
    +gW&                     p   d Z ddlZddlmZ ddlmZ dxZZdZi Z	 ej                  d      j                  Z ej                  d      j                  Zd	Zi Z	  ej"                  d
      Z eej/                               D ]D  Zej2                  dk(  sej4                  dd Zeee<   ej7                  d      d   Zeevs@eee<   F eD  ci c]  } | j;                         |  c} Zd Z G d d      Z  G d de!      Z" G d d      Z# G d d      Z$y# e$ r  ee      j*                  dz  ZY w xY wc c} w )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?))%#LEFTHYPHENMINRIGHTHYPHENMINCOMPOUNDLEFTHYPHENMINCOMPOUNDRIGHTHYPHENMINzpyphen.dictionariesdictionariesz.dic   _c                     | j                  dd      j                         j                  d      }|r6dj                  |      } | t        v r	t        |    S |j                          |r5yy)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)replacelowersplitjoinLANGUAGES_LOWERCASEpop)languagepartss     g/home/viktor/gitlab-persoonlijk/factuur-applicatie/venv/lib/python3.12/site-packages/pyphen/__init__.pyr   r   /   s\     S#&,,.44S9E
88E?**&x00			     c                       e Zd ZdZd Zd Zy)AlternativeParserzParser 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                     |j                  d      }|d   | _        t        |d         | _        t        |d         | _        |j                  d      r| xj                  dz  c_        y y )N,r         .)r   changeintindexcut
startswith)selfpatternalternatives      r   __init__zAlternativeParser.__init__G   s]    !'',!!nQ(
{1~&c"JJ!OJ #r   c                     | xj                   dz  c_         t        |      }|dz  r-t        || j                  | j                   | j                  f      S |S )Nr"   )r'   r&   DataIntr%   r(   )r*   values     r   __call__zAlternativeParser.__call__O   sD    

a
E
1954;;

DHH"EFFLr   N)__name__
__module____qualname____doc__r-   r1    r   r   r   r   @   s    r   r   c                       e Zd ZdZddZy)r/   zE``int`` with some other data can be stuck to in a ``data`` attribute.Nc                     t         j                  | |      }|r#t        |t              r|j                  |_        |S ||_        |S )zCreate a new ``DataInt``.

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

        )r&   __new__
isinstancer/   data)clsr0   r;   	referenceobjs        r   r9   zDataInt.__new__Z   s@     kk#u%Iw7 ~~CH 
 CH
r   )NN)r2   r3   r4   r5   r9   r6   r   r   r/   r/   X   s
    Or   r/   c                       e Zd ZdZd Zd Zy)HyphDictzHyphenation patterns.c                 p   i | _         |j                  d      5 }|j                         j                         }ddd       j	                         dk(  rd}|j                  |      j                  d      dd D ]   }|j                         }|r|j                  t              r,t        d |      }d|v r&d	|v r"|j                  dd      \  }}t        ||      }nt        }t        t        |      D cg c]  \  }}| ||xs d
      f c}} \  }	}
t        |
      dk(  rdt!        |
      }}|
|   s|dz  }|
|   s|
|dz
     s|dz  }|
|dz
     s||
|| f| j                   dj#                  |	      <    i | _        t        d | j                   D              | _        y# 1 sw Y   oxY wc c}}w )zhRead a ``hyph_*.dic`` and parse its patterns.

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

        rbNzmicrosoft-cp1251cp1251
r"   c                 J    t        t        | j                  d      d            S )Nr"      )chrr&   group)matchs    r   <lambda>z#HyphDict.__init__.<locals>.<lambda>   s    c#ekk!nb"9: r   /=0r    c              3   2   K   | ]  }t        |        y w)N)len).0keys     r   	<genexpr>z$HyphDict.__init__.<locals>.<genexpr>   s     <s#c(<s   )patternsopenreadlinedecoder   	read_textr   stripr)   ignored	parse_hexr   r&   zipparsemaxrP   r   cachemaxlen)r*   pathfdencodingr+   r,   factoryistringtagsvaluesstartends                r   r-   zHyphDict.__init__l   s     YYt_ 	.{{}++-H	.>>11H~~h/55d;AB? 	DGmmoGg009  :GEG g~#.'.}}S!'<$+G[A=B7^!M096c*+!M NLD& 6{a CK3EUm
 UmS1Woq S1Wo ,1&s2C+CDMM"''$-(=	D@ 
<dmm<<M	. 	.*!Ms   F%4F2%F/c           	      ~   |j                         }| j                  j                  |      }|d| d}dgt        |      dz   z  }t	        t        |      dz
        D ]  }t        || j                  z   t        |            dz   }t	        |dz   |      D ]]  }| j                  j                  |||       }|s$|\  }	}
t        ||	z   ||	z   t        |
      z         }t        t        |
||         ||<   _  t        |      D cg c]  \  }}|dz  rt        |dz
  |       c}}x| j                  |<   }|S c c}}w )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

        r$   r   r"   r#   )r=   )r   r_   getrP   rangeminr`   rT   slicemapr^   	enumerater/   )r*   wordpointspointed_word
referencesre   stopjr+   offsetrh   slice_r=   s                r   	positionszHyphDict.positions   sV   4 zz|%>tfA;LL 1A 56J3|,q01 N1t{{?C,=>Bq1ud+ NA"mm//Qq0ABG" %,NFF"1v:q6zCK/GHF),S&*V:L)MJv&NN %.j$9)L AyY] A3)L LDJJtv )Ls   D9N)r2   r3   r4   r5   r-   rz   r6   r   r   r@   r@   i   s    /=b-r   r@   c                   8    e Zd ZdZddZd Zd Zd	dZd	dZeZ	y)
r   zEHyphenation class, with methods to hyphenate strings in various ways.Nc                     ||c| _         | _        |rt        |      nt        t	        |         }|r|t
        vrt        |      t
        |<   t
        |   | _        y)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   hdcacher@   hd)r*   filenamelangr}   r~   r_   ra   s          r   r-   zPyphen.__init__   sN     !%e	4:!)tH~y9J49P/QG+$TNGDM$-r   c                     t        |      | j                  z
  }| j                  j                  |      D cg c]  }| j                  |cxk  r|k  sn n| c}S c c}w )zGet 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.

        )rP   r~   r   rz   r}   )r*   rr   r~   re   s       r   rz   zPyphen.positions   sI     D	DJJ&77,,T2Nadii16M6MNNNs   AAc              #   8  K   t        | j                  |            D ]y  }|j                  r_|j                  \  }}}||z  }|j                         r|j	                         }|j                  d      \  }}|d| |z   ||||z   d z   f n|d| ||d f { yw)zIterate over all hyphenation possibilities, the longest first.

        :param word: unicode string of the word to hyphenate

        rL   N)reversedrz   r;   isupperupperr   )r*   rr   positionr%   r'   r(   c1c2s           r   iteratezPyphen.iterate   s      !!56 
	7H}}%-]]"s!<<>#\\^Fc*B6ElR'd53;<.@)@@@9HotHI66
	7s   BBc                     |t        |      z  }| j                  |      D ]  \  }}t        |      |k  s||z   |fc S  y)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)rP   r   )r*   rr   widthhyphenw1w2s         r   wrapzPyphen.wrap   sH     	Vll4( 	'FB2w%F{B&	'r   c                 P   t        |      }t        | j                  |            D ]n  }|j                  rN|j                  \  }}}||z  }|j	                         r|j                         }|j                  d|      ||||z    ]|j                  ||       p dj                  |      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 ``'-'``.

        rL   rN   )	listr   rz   r;   r   r   r   insertr   )r*   rr   r   lettersr   r%   r'   r(   s           r   insertedzPyphen.inserted  s     t* !56 		1H}}%-]]"s!<<>#\\^F-3^^C-Heck*x0		1 wwwr   )NNr#   r#   T)r   )
r2   r3   r4   r5   r-   rz   r   r   r   r1   r6   r   r   r   r      s&    O  
O7$'$ 2 Hr   r   )%r5   re	importlibr   pathlibr   VERSION__version____all__r   compilesubr[   findallr]   rZ   r   filesr   	TypeError__file__parentsortediterdirra   suffixnamer   
short_namer   r   r   r   r&   r/   r@   r   )r   s   0r   <module>r      sc   
     +
6  BJJ,-11	

=!))7
 	:"9??#89L <'')* )D{{fyy2	$ZZ_Q'
Y&$(Ij!) 7@@dtzz|T)@ " 0c "a aH\ \Y  :>((>9L: As   D D3D0/D0