
    Ng                         d Z h dZh dZdZ G d de          Zddefd	Zg ddfd
Zg ddfdZ	e
dk    rddlZ ej                     dS dS )zH
User name to file name conversion.
This was taken from the UFO 3 spec.
>/   * 	
"()+/:<>?[\]|>   clock$auxconnulprncom1com2com3com4com5com6com7com8com9lpt1lpt2lpt3lpt4lpt5lpt6lpt7lpt8lpt9   c                       e Zd ZdS )NameTranslationErrorN)__name__
__module____qualname__     V/var/www/html/ai-engine/env/lib/python3.11/site-packages/fontTools/ufoLib/filenames.pyrJ   rJ   [   s        DrO   rJ   rN    userNamec                    t          | t                    st          d          t          |          }t          |          }|s| d         dk    rd| dd         z   } g }| D ]@}|t          v rd}n||                                k    r|dz  }|                    |           Ad                    |          } t          |z
  |z
  }| d|         } g }	| 	                    d          D ]7}
|
                                t          v rd|
z   }
|	                    |
           8d                    |	          } || z   |z   }|                                |v rt          | |||          }|S )a  
    `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.    ._   NrQ   )
isinstancestr
ValueErrorlenillegalCharacterslowerappendjoinmaxFileNameLengthsplitreservedFileNameshandleClash1)rR   existingprefixsuffixprefixLengthsuffixLengthfilteredUserName	charactersliceLengthpartspartfullNames               rP   userNameToFileNamero   _   s   d h$$ ECDDDv;;Lv;;L  &hqkS((!""% + +	)))II)//++++I	****ww'((H#l2\AK%HEs##  ::<<,,,:DTxxH 6)H~~8##(FFCCOrO   c                    t          |          }t          |          }|t          |           z   |z   dz   t          k    r,|t          |           z   |z   dz   }t          |z
  }| d|         } d}d}	|T| t          |	                              d          z   }
||
z   |z   }|                                |vr|}n|	dz  }	|	dk    rn|T|t          |||          }|S )aO  
    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
       NrW   l   I5 )r[   r`   rY   zfillr]   handleClash2)rR   rd   re   rf   rg   rh   lrk   	finalNamecounternamern   s               rP   rc   rc      s   > v;;Lv;;Lc(mm#l2R7:KKK3x==(<7"<'!+L[L)IG

#g,,,,R000D=6)>>8++ IqLGo%% 
  66::	rO   c                    t           t          |          z
  t          |          z
  }t          d|z            }d}d}|<|t          |          z   |z   }|                                | vr|}n|dz  }||k    rn|<|t          d          |S )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
    9NrW   zNo unique name could be found.)r`   r[   intrY   r]   rJ   )rd   re   rf   	maxLengthmaxValueru   rv   rn   s           rP   rs   rs      s    6 "CKK/#f++=I3?##HIG

CLL(61>>8++ IqLGh 
 "#CDDDrO   __main__rT   N)rN   rQ   rQ   )__doc__r\   rb   r`   	ExceptionrJ   rY   ro   rc   rs   rK   doctesttestmodrN   rO   rP   <module>r      s    0 0 0 b   2  	 	 	 	 	9 	 	 	U U U U U Up %'r" 6 6 6 6r R - - - -` zNNNGO rO   