
    h                         S r 1 Skr1 SkrSr " S S\5      rSS\4S jjr/ SS4S	 jr/ SS4S
 jr	\
S:X  a  SSKr\R                  " 5         gg)zH
User name to file name conversion.
This was taken from the UFO 3 spec.
>/    	
"()*+/:<>?[\]|>   auxconnulprncom1com2com3com4com5com6com7com8com9lpt1lpt2lpt3lpt4lpt5lpt6lpt7lpt8lpt9clock$   c                       \ rS rSrSrg)NameTranslationError[    N)__name__
__module____qualname____firstlineno____static_attributes__rL       L/var/www/html/env/lib/python3.13/site-packages/fontTools/ufoLib/filenames.pyrJ   rJ   [   s    rR   rJ    userNamec                 h   [        U [        5      (       d  [        S5      e[        U5      n[        U5      nU(       d  U S   S:X  a  SU SS -   n / nU  H9  nU[        ;   a  SnOXwR                  5       :w  a  US-  nUR                  U5        M;     SR                  U5      n [        U-
  U-
  nU SU n / n	U R                  S5       H1  n
U
R                  5       [        ;   a  SU
-   n
U	R                  U
5        M3     SR                  U	5      n X -   U-   nUR                  5       U;   a  [        XX#5      nU$ )aG  
`existing` should be a set-like object.

>>> userNameToFileName("a") == "a"
True
>>> userNameToFileName("A") == "A_"
True
>>> userNameToFileName("AE") == "A_E_"
True
>>> userNameToFileName("Ae") == "A_e"
True
>>> userNameToFileName("ae") == "ae"
True
>>> userNameToFileName("aE") == "aE_"
True
>>> userNameToFileName("a.alt") == "a.alt"
True
>>> userNameToFileName("A.alt") == "A_.alt"
True
>>> userNameToFileName("A.Alt") == "A_.A_lt"
True
>>> userNameToFileName("A.aLt") == "A_.aL_t"
True
>>> userNameToFileName(u"A.alT") == "A_.alT_"
True
>>> userNameToFileName("T_H") == "T__H_"
True
>>> userNameToFileName("T_h") == "T__h"
True
>>> userNameToFileName("t_h") == "t_h"
True
>>> userNameToFileName("F_F_I") == "F__F__I_"
True
>>> userNameToFileName("f_f_i") == "f_f_i"
True
>>> userNameToFileName("Aacute_V.swash") == "A_acute_V_.swash"
True
>>> userNameToFileName(".notdef") == "_notdef"
True
>>> userNameToFileName("con") == "_con"
True
>>> userNameToFileName("CON") == "C_O_N_"
True
>>> userNameToFileName("con.alt") == "_con.alt"
True
>>> userNameToFileName("alt.con") == "alt._con"
True
z(The value for userName must be a string.    ._   NrT   )
isinstancestr
ValueErrorlenillegalCharacterslowerappendjoinmaxFileNameLengthsplitreservedFileNameshandleClash1)rU   existingprefixsuffixprefixLengthsuffixLengthfilteredUserName	charactersliceLengthpartspartfullNames               rS   userNameToFileNamerr   _   s7   d h$$CDDv;Lv;L hqkS(!"%	))I//++I	*  ww'(H#l2\AK%HEs#::<,,:DT $ xxH 6)H~~8#FCOrR   c                 r   [        U5      n[        U5      nU[        U 5      -   U-   S-   [        :  a"  U[        U 5      -   U-   S-   n[        U-
  nU SU n SnSn	UcL  U [        U	5      R                  S5      -   n
X*-   U-   nUR	                  5       U;  a  UnOU	S-  n	U	S:  a  OUc  ML  Uc  [        XU5      nU$ )a  
existing should be a case-insensitive list
of all existing file names.

>>> prefix = ("0" * 5) + "."
>>> suffix = "." + ("0" * 10)
>>> existing = ["a" * 5]

>>> e = list(existing)
>>> handleClash1(userName="A" * 5, existing=e,
...         prefix=prefix, suffix=suffix) == (
...         '00000.AAAAA000000000000001.0000000000')
True

>>> e = list(existing)
>>> e.append(prefix + "aaaaa" + "1".zfill(15) + suffix)
>>> handleClash1(userName="A" * 5, existing=e,
...         prefix=prefix, suffix=suffix) == (
...         '00000.AAAAA000000000000002.0000000000')
True

>>> e = list(existing)
>>> e.append(prefix + "AAAAA" + "2".zfill(15) + suffix)
>>> handleClash1(userName="A" * 5, existing=e,
...         prefix=prefix, suffix=suffix) == (
...         '00000.AAAAA000000000000001.0000000000')
True
   NrZ   l   I5 )r^   rc   r\   zfillr`   handleClash2)rU   rg   rh   ri   rj   rk   lrn   	finalNamecounternamerq   s               rS   rf   rf      s    > v;Lv;Lc(m#l2R7:KK3x=(<7"<'!+L[)IG

#g,,,R00=6)>>8+ IqLGo% 
  6:	rR   c                     [         [        U5      -
  [        U5      -
  n[        SU-  5      nSnSnUc8  U[        U5      -   U-   nUR	                  5       U ;  a  UnOUS-  nXd:  a  OUc  M8  Uc  [        S5      eU$ )a  
existing should be a case-insensitive list
of all existing file names.

>>> prefix = ("0" * 5) + "."
>>> suffix = "." + ("0" * 10)
>>> existing = [prefix + str(i) + suffix for i in range(100)]

>>> e = list(existing)
>>> handleClash2(existing=e, prefix=prefix, suffix=suffix) == (
...         '00000.100.0000000000')
True

>>> e = list(existing)
>>> e.remove(prefix + "1" + suffix)
>>> handleClash2(existing=e, prefix=prefix, suffix=suffix) == (
...         '00000.1.0000000000')
True

>>> e = list(existing)
>>> e.remove(prefix + "2" + suffix)
>>> handleClash2(existing=e, prefix=prefix, suffix=suffix) == (
...         '00000.2.0000000000')
True
9NrZ   zNo unique name could be found.)rc   r^   intr\   r`   rJ   )rg   rh   ri   	maxLengthmaxValuerx   ry   rq   s           rS   rv   rv      s    6 "CK/#f+=I3?#HIG

CL(61>>8+ IqLG 
 "#CDDrR   __main__rW   N)rL   rT   rT   )__doc__r_   re   rc   	ExceptionrJ   r\   rr   rf   rv   rM   doctesttestmodrL   rR   rS   <module>r      sx   0 b 2  	9 	U Up %'r" 6r R -` zOO rR   