a
    ¥Q•hW&  ã                   @   s(  d Z ddlZddlmZ ddlmZ d ZZdZi Z	e 
d¡jZe 
d¡jZd	Zi Zze d
¡ZW n  ey‚   eeƒjd ZY n0 ee ¡ ƒD ]BZejdkr�ejdd… Zeee< e d¡d Zeevr�eee< q�dd„ eD ƒZdd„ ZG dd„ dƒZG dd„ de ƒZ!G dd„ dƒZ"G dd„ dƒZ#dS )zY

Pyphen
======

Pure Python module to hyphenate text, inspired by Ruby's Text::Hyphen.

é    N)Ú	resources)ÚPathz0.17.2)Ú	LANGUAGESÚPyphenÚlanguage_fallbackz\^{2}([0-9a-f]{2})z
(\d?)(\D?))ú%ú#ZLEFTHYPHENMINZRIGHTHYPHENMINZCOMPOUNDLEFTHYPHENMINZCOMPOUNDRIGHTHYPHENMINzpyphen.dictionariesÚdictionariesz.dicé   éüÿÿÿÚ_c                 C   s   i | ]}|  ¡ |“qS © )Úlower)Ú.0Únamer   r   úH/var/www/sistema_ama/venv/lib/python3.9/site-packages/pyphen/__init__.pyÚ
<dictcomp>,   ó    r   c                 C   sB   |   dd¡ ¡  d¡}|r>d |¡} | tv r4t|  S | ¡  qdS )a	  Get a fallback language available in our dictionaries.

    http://www.unicode.org/reports/tr35/#Locale_Inheritance

    We use the normal truncation inheritance. This function needs aliases
    including scripts for languages with multiple regions available.

    ú-r   N)Úreplacer   ÚsplitÚjoinÚLANGUAGES_LOWERCASEÚpop)ÚlanguageÚpartsr   r   r   r   /   s    	
r   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚAlternativeParserz¶Parser of nonstandard hyphen pattern alternative.

    The instance returns a special int with data about the current position in
    the pattern when called with an odd value.

    c                 C   sL   |  d¡}|d | _t|d ƒ| _t|d ƒ| _| d¡rH|  jd7  _d S )Nú,r   é   é   Ú.)r   ÚchangeÚintÚindexÚcutÚ
startswith)ÚselfÚpatternÚalternativer   r   r   Ú__init__G   s    


zAlternativeParser.__init__c                 C   s<   |  j d8  _ t|ƒ}|d@ r4t|| j| j | jfƒS |S d S )Nr   )r#   r"   ÚDataIntr!   r$   )r&   Úvaluer   r   r   Ú__call__O   s
    zAlternativeParser.__call__N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r)   r,   r   r   r   r   r   @   s   r   c                   @   s   e Zd ZdZddd„ZdS )r*   zE``int`` with some other data can be stuck to in a ``data`` attribute.Nc                 C   s.   t  | |¡}|r$t|tƒr$|j|_n||_|S )z…Create a new ``DataInt``.

        Call with ``reference=dataint_object`` to use the data from another
        ``DataInt``.

        )r"   Ú__new__Ú
isinstancer*   Údata)Úclsr+   r3   Ú	referenceÚobjr   r   r   r1   Z   s
    
zDataInt.__new__)NN)r-   r.   r/   r0   r1   r   r   r   r   r*   X   s   r*   c                   @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚHyphDictzHyphenation patterns.c           
         sd  i | _ | d¡�}| ¡  ¡ }W d  ƒ n1 s20    Y  | ¡ dkrLd}| |¡ d¡dd… D ]Þ}| ¡ }|rd| t	¡r€qdt
dd„ |ƒ}d	|v rºd
|v rº| d	d¡\}}t||ƒ‰ nt‰ t‡ fdd„t|ƒD ƒŽ \}}t|ƒdkrêqddt|ƒ }}	|| �s|d7 }qø||	d  �s&|	d8 }	�q||||	… f| j d |¡< qdi | _tdd„ | j D ƒƒ| _dS )zhRead a ``hyph_*.dic`` and parse its patterns.

        :param path: Path of hyph_*.dic to read

        ÚrbNzmicrosoft-cp1251Úcp1251Ú
r   c                 S   s   t t|  d¡dƒƒS )Nr   é   )Úchrr"   Úgroup)Úmatchr   r   r   Ú<lambda>�   r   z#HyphDict.__init__.<locals>.<lambda>ú/ú=c                    s    g | ]\}}|ˆ |pd ƒf‘qS )Ú0r   )r   ÚiÚstring©Úfactoryr   r   Ú
<listcomp>Š   s   z%HyphDict.__init__.<locals>.<listcomp>r   Ú c                 s   s   | ]}t |ƒV  qd S )N)Úlen)r   Úkeyr   r   r   Ú	<genexpr>›   r   z$HyphDict.__init__.<locals>.<genexpr>)ÚpatternsÚopenÚreadlineÚdecoder   Ú	read_textr   Ústripr%   ÚignoredÚ	parse_hexr   r"   ÚzipÚparseÚmaxrI   r   ÚcacheÚmaxlen)
r&   ÚpathÚfdÚencodingr'   r(   ÚtagsÚvaluesÚstartÚendr   rE   r   r)   l   s:    *ÿÿ

zHyphDict.__init__c                 C   sì   |  ¡ }| j |¡}|du rèd|› d�}dgt|ƒd  }tt|ƒd ƒD ]€}t|| j t|ƒƒd }t|d |ƒD ]T}| j |||… ¡}|s’qt|\}	}
t||	 ||	 t|
ƒ ƒ}t	t
|
|| ƒ||< qtqJdd„ t|ƒD ƒ | j|< }|S )aþ  Get a list of positions where the word can be hyphenated.

        :param word: unicode string of the word to hyphenate

        E.g. for the dutch word 'lettergrepen' this method returns ``[3, 6,
        9]``.

        Each position is a ``DataInt`` with a data attribute.

        If the data attribute is not ``None``, it contains a tuple with
        information about nonstandard hyphenation at that point: ``(change,
        index, cut)``.

        change
          a string like ``'ff=f'``, that describes how hyphenation should
          take place.

        index
          where to substitute the change, counting from the current point

        cut
          how many characters to remove while substituting the nonstandard
          hyphenation

        Nr    r   r   c                 S   s(   g | ] \}}|d  rt |d |d�‘qS )r   r   )r5   )r*   )r   rC   r5   r   r   r   rG   Ç   s   ÿz&HyphDict.positions.<locals>.<listcomp>)r   rW   ÚgetrI   ÚrangeÚminrX   rL   ÚsliceÚmaprV   Ú	enumerate)r&   ÚwordZpointsZpointed_wordÚ
referencesrC   ÚstopÚjr'   Úoffsetr]   Úslice_r   r   r   Ú	positions�   s$    þzHyphDict.positionsN)r-   r.   r/   r0   r)   rl   r   r   r   r   r7   i   s   1r7   c                   @   sB   e Zd ZdZddd„Zdd„ Zd	d
„ Zddd„Zddd„ZeZ	dS )r   zEHyphenation class, with methods to hyphenate strings in various ways.Nr   Tc                 C   sL   || | _ | _|rt|ƒn
tt|ƒ }|r2|tvr>t|ƒt|< t| | _dS )a°  Create an hyphenation instance for given lang or filename.

        :param filename: filename or Path of hyph_*.dic to read
        :param lang: lang of the included dict to use if no filename is given
        :param left: minimum number of characters of the first syllabe
        :param right: minimum number of characters of the last syllabe
        :param cache: if ``True``, use cached copy of the hyphenation patterns

        N)ÚleftÚrightr   r   r   Úhdcacher7   Úhd)r&   ÚfilenameÚlangrm   rn   rW   rY   r   r   r   r)   Ð   s
    
zPyphen.__init__c                    s*   t |ƒˆj ‰ ‡ ‡fdd„ˆj |¡D ƒS )zñGet a list of positions where the word can be hyphenated.

        :param word: unicode string of the word to hyphenate

        See also ``HyphDict.positions``. The points that are too far to the
        left or right are removed.

        c                    s*   g | ]"}ˆj |  krˆ krn q|‘qS r   )rm   )r   rC   ©rn   r&   r   r   rG   ê   r   z$Pyphen.positions.<locals>.<listcomp>)rI   rn   rp   rl   )r&   rf   r   rs   r   rl   à   s    	zPyphen.positionsc                 c   s’   t |  |¡ƒD ]~}|jrr|j\}}}||7 }| ¡ r<| ¡ }| d¡\}}|d|… | |||| d…  fV  q|d|… ||d… fV  qdS )z†Iterate over all hyphenation possibilities, the longest first.

        :param word: unicode string of the word to hyphenate

        rA   N)Úreversedrl   r3   ÚisupperÚupperr   )r&   rf   Úpositionr!   r#   r$   Úc1Úc2r   r   r   Úiterateì   s    (zPyphen.iterater   c                 C   s@   |t |ƒ8 }|  |¡D ]$\}}t |ƒ|kr|| |f  S qdS )a´  Get the longest possible first part and the last part of a word.

        :param word: unicode string of the word to hyphenate
        :param width: maximum length of the first part
        :param hyphen: unicode string used as hyphen character

        The first part has the hyphen already attached.

        Returns ``None`` if there is no hyphenation point before ``width``, or
        if the word could not be hyphenated.

        N)rI   rz   )r&   rf   ÚwidthÚhyphenZw1Zw2r   r   r   Úwrapþ   s    zPyphen.wrapc                 C   sv   t |ƒ}t|  |¡ƒD ]T}|jr^|j\}}}||7 }| ¡ rD| ¡ }| d|¡|||| …< q| ||¡ qd |¡S )a£  Get the word as a string with all the possible hyphens inserted.

        :param word: unicode string of the word to hyphenate
        :param hyphen: unicode string used as hyphen character

        E.g. for the dutch word ``'lettergrepen'``, this method returns the
        unicode string ``'let-ter-gre-pen'``. The hyphen string to use can be
        given as the second parameter, that defaults to ``'-'``.

        rA   rH   )	Úlistrt   rl   r3   ru   rv   r   Úinsertr   )r&   rf   r|   Úlettersrw   r!   r#   r$   r   r   r   Úinserted  s    zPyphen.inserted)NNr   r   T)r   )r   )
r-   r.   r/   r0   r)   rl   rz   r}   r�   r,   r   r   r   r   r   Í   s   


r   )$r0   ÚreÚ	importlibr   Úpathlibr   ÚVERSIONÚ__version__Ú__all__ro   ÚcompileÚsubrS   ÚfindallrU   rR   r   Úfilesr	   Ú	TypeErrorÚ__file__ÚparentÚsortedÚiterdirrY   Úsuffixr   r   Z
short_namer   r   r   r"   r*   r7   r   r   r   r   r   Ú<module>   s6   	

d