o
    0 iQ)                     @   s:  U d Z ddlZddlZddlmZ ddlmZm	Z	m
Z
mZ ddlZzddlZW n ey6   ddlmZ Y nw dededefd	d
Zdede
e fddZed dZeed< ed dZeed< ed Ze
e ed< dedefddZG dd dejjZG dd deZG dd dejjZG dd dejjZG dd dejjZG d d! d!ejjZ G d"d# d#ejj!Z"G d$d% d%ejjZ#eej$%ed&Z&eed'< e#ej$%ed(Z'e#ed)< eej$%ed*Z(eed+< eej$%ed,Z)eed-< eej$%ed.Z*eed/< e ej$%ed0Z+e ed1< eej$%ed2Z,eed3< dS )4	pycountry    N)metadata)DictListOptionalType)	resourcespackage_or_requirementresource_namereturnc                 C   s   t t| | S )N)strimportlib_resourcesfiles)r	   r
    r   ^/home/app/PaddleOCR-VL-test/.venv_paddleocr/lib/python3.10/site-packages/pycountry/__init__.pyresource_filename   s   r   distribution_namec                 C   s$   zt | W S  t jy   Y dS w )Nzn/a)_importlib_metadataversionZPackageNotFoundError)r   r   r   r   get_version   s
   r   ZlocalesLOCALES_DIRZ	databasesDATABASE_DIR__version__	input_strc                 C   s0   | }|   std| }ddd |D }|S )NZNFKD c                 S   s   g | ]	}t |s|qS r   )unicodedata	combining).0cr   r   r   
<listcomp>.   s    z"remove_accents.<locals>.<listcomp>)isasciir   	normalizejoin)r   Z
output_strZ	nfkd_formr   r   r   remove_accents(   s   r#   c                   @   s6   e Zd ZdZejjZdZde	de
ed   fddZdS )ExistingCountriesz4Provides access to an ISO 3166 database (Countries).z3166-1queryr   c                    sx  t |  }i  dddtdd f fdd}z
||d W n	 ty*   Y nw tjjt	|d}|D ]}||j
d	 q5D ]6}|jd
|jd|jdfD ]"}|d urut | }||v ru||tddd||  g  nqSq@tjjt	|d}|D ]!}|jd
}t | }||v r||j
tdd|| g q st|fddt  dd dD }|S )Ncountryzpycountry.db.Countrypointsr   c                    $     | jd  | j  |7  < d S Nr   )
setdefaultalpha_2)r&   r'   resultsr   r   
add_result@   s   z2ExistingCountries.search_fuzzy.<locals>.add_result2   )selfr%   1   nameZofficial_namecomment            c                       g | ]
} j |d  dqS )r   r+   getr   xr0   r   r   r   r       z2ExistingCountries.search_fuzzy.<locals>.<listcomp>c                 S      | d  | d fS Nr7   r   r   r=   r   r   r   <lambda>w       z0ExistingCountries.search_fuzzy.<locals>.<lambda>key)r#   striplowerintlookupLookupErrorr   Subdivisionsmatchsubdivisionsr&   _fieldsr;   maxfindpartial_matchsorteditems)r0   r%   r.   Zmatch_subdivions	candidatevpartial_match_subdivisionssorted_resultsr   r-   r0   r   search_fuzzy9   sR   



zExistingCountries.search_fuzzyN)__name__
__module____qualname____doc__r   dbCountry
data_classroot_keyr   r   r   rZ   r   r   r   r   r$   3   s
    r$   c                   @   s   e Zd ZdZejjZdZdS )HistoricCountrieszcProvides access to an ISO 3166-3 database
    (Countries that have been removed from the standard).z3166-3N)	r[   r\   r]   r^   r   r_   r`   ra   rb   r   r   r   r   rc   |   s    rc   c                   @      e Zd ZdZdZdZdS )Scriptsz3Provides access to an ISO 15924 database (Scripts).ZScriptZ15924Nr[   r\   r]   r^   ra   rb   r   r   r   r   re          re   c                   @   rd   )
Currenciesz5Provides access to an ISO 4217 database (Currencies).ZCurrencyZ4217Nrf   r   r   r   r   rh      rg   rh   c                   @   s    e Zd ZdZg dZdZdZdS )	Languagesz:Provides access to an ISO 639-1/2T/3 database (Languages).)statusscopetypeZinverted_nameZcommon_nameZLanguagez639-3N)r[   r\   r]   r^   no_indexra   rb   r   r   r   r   ri      s
    ri   c                   @   rd   )LanguageFamilieszLProvides access to an ISO 639-5 database
    (Language Families and Groups).ZLanguageFamilyz639-5Nrf   r   r   r   r   rn      s    rn   c                       s4   e Zd Z fddZedd Zedd Z  ZS )SubdivisionHierarchyc                    s   d|v r|d |d< nd |d< t  jdi | | jdd | _| jd ur?| jd}|d | jkrA| j d| j | _d S d S d S )Nparentparent_code-r   r   )super__init__codesplitcountry_coderq   )r0   kwparts	__class__r   r   rt      s   
zSubdivisionHierarchy.__init__c                 C   s   t j| jdS )Nr9   )	countriesr;   rw   r>   r   r   r   r&      s   zSubdivisionHierarchy.countryc                 C   s   | j sd S tj| j dS )Nru   )rq   rN   r;   r>   r   r   r   rp      s   zSubdivisionHierarchy.parent)r[   r\   r]   rt   propertyr&   rp   __classcell__r   r   rz   r   ro      s    
ro   c                       sb   e Zd ZeZg dZdZ fddZ fddZdd Z	d	d
 Z
dedeed   fddZ  ZS )rL   )r2   rq   rp   rl   z3166-2c                    sN   t  j|i | i | jd< | D ]}| jd |j t }|| qd S )Nrw   )rs   _loadindicesr*   rw   rH   setadd)r0   argsrx   subdivisionZdivsrz   r   r   r      s   

zSubdivisions._loadc                    sJ   | dd }t jdi |}||u r#d|v r#tj|d dd ur#g S |S )Ndefaultrw   r9   r   )r*   rs   r;   r|   )r0   rx   r   rN   rz   r   r   r;      s   zSubdivisions.getc                 C   sl   t |  }g }tD ]'}|j D ]}|d ur2t | }|dD ]}||kr1||  nq$qq|S )N;)r#   rG   rH   rN   rO   valuesrv   append)r0   r%   matching_candidatesrU   rV   wr   r   r   rM      s   

zSubdivisions.matchc                 C   sL   t |  }g }tD ]}|jd}t | }||v r#|| q|S )Nr2   )r#   rG   rH   rN   rO   r;   r   )r0   r%   r   rU   rV   r   r   r   rR      s   
zSubdivisions.partial_matchr%   r   c              	      s   t |  }i  dddtdd f fdd}|}|D ]}||d q|}|D ] }|jd}t | }||v rM||td	d
|	| g q- sTt
|fddt  dd dD }|S )Nr   zpycountry.db.Subdivisionr'   r   c                    r(   r)   )r*   ru   )r   r'   r,   r   r   r.      s   z-Subdivisions.search_fuzzy.<locals>.add_resultr/   r2   r7   r4   c                    r8   )r   r}   r:   r<   r>   r   r   r     r?   z-Subdivisions.search_fuzzy.<locals>.<listcomp>c                 S   r@   rA   r   rB   r   r   r   rC     rD   z+Subdivisions.search_fuzzy.<locals>.<lambda>rE   )r#   rG   rH   rI   rM   rR   rO   r;   rP   rQ   rK   rS   rT   )r0   r%   r.   Zmatch_subdivisionsrU   rW   rV   rX   r   rY   r   rZ      s2   


zSubdivisions.search_fuzzy)r[   r\   r]   ro   ra   rm   rb   r   r;   rM   rR   r   r   r   rZ   r   r   r   rz   r   rL      s    "rL   ziso3166-1.jsonr|   ziso3166-2.jsonrN   ziso3166-3.jsonhistoric_countriesziso4217.json
currenciesziso639-3.json	languagesziso639-5.jsonlanguage_familiesziso15924.jsonscripts)-r^   Zos.pathosr   	importlibr   r   typingr   r   r   r   Zpycountry.dbr   r   ModuleNotFoundErrorr   r   r   r   r   __annotations__r   r   r#   r_   ZDatabaser$   rc   re   rh   ri   rn   ZDataro   rL   pathr"   r|   rN   r   r   r   r   r   r   r   r   r   <module>   sP    I	b