)Ej+UddlmZddlmZ hdZded<hdZded<dZd ed <Gd d eZ dddZ gddfddZ gddfddZ e dkrddlZejdSdS)) annotations)Iterable>/*     "()+/:<>?[\]|zset[str]illegalCharacters>clock$auxconnulprncom1com2com3com4com5com6com7com8com9lpt1lpt2lpt3lpt4lpt5lpt6lpt7lpt8lpt9reservedFileNamesintmaxFileNameLengthceZdZdS)NameTranslationErrorN)__name__ __module__ __qualname__LC:\PYTHON\MyICR_Suite\python\Lib\site-packages\fontTools/ufoLib/filenames.pyrQrQosDrVrQrUuserNamestrexisting Iterable[str]prefixsuffixreturnct|tstdt|}t|}|s|ddkr d|ddz}g}|D]@}|tvrd}n||kr|dz }||Ad|}t|z |z }|d|}g} | dD]7} | tvrd| z} | | 8d| }||z|z} | |vrt||||} | S)aConverts from a user name to a file name. Takes care to avoid illegal characters, reserved file names, ambiguity between upper- and lower-case characters, and clashes with existing files. Args: userName (str): The input file name. existing: A case-insensitive list of all existing file names. prefix: Prefix to be prepended to the file name. suffix: Suffix to be appended to the file name. Returns: A suitable filename. Raises: NameTranslationError: If no suitable name could be generated. Examples:: >>> 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.r._NrX) isinstancerZ ValueErrorlenr4lowerappendjoinrOsplitrL handleClash1) rYr[r]r^ prefixLength suffixLengthfilteredUserName character sliceLengthpartspartfullNames rWuserNameToFileNamertssH h $ $ECDDDv;;Lv;;L &hqkS((!""%++ ) ) )II )//++ + +  I ****ww'((H#l2\AK  %H Es## ::<<, , ,:D TxxH 6)H~~8##(FFCC OrVct|}t|}|t|z|zdztkr,|t|z|zdz}t|z }|d|}d}d} |T|t| dz} || z|z} | |vr| }n| dz } | dkrn|T|t |||}|S)aCA helper function that resolves collisions with existing names when choosing a filename. This function attempts to append an unused integer counter to the filename. Args: userName (str): The input file name. existing: A case-insensitive list of all existing file names. prefix: Prefix to be prepended to the file name. suffix: Suffix to be appended to the file name. Returns: A suitable filename. >>> 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 NrclI5)rfrOrZzfillrg handleClash2) rYr[r]r^rlrmlrp finalNamecounternamerss rWrkrksTv;;Lv;;Lc(mm#l2R7:KKK 3x== (< 7" <'!+ L[L)IG  #g,,,,R000D=6) >>  8 + + I  qLG o % %    66:: rVctt|z t|z }td|z}d}d}|<|t|z|z}||vr|}n|dz }||krn|<|t d|S)akA helper function that resolves collisions with existing names when choosing a filename. This function is a fallback to :func:`handleClash1`. It attempts to append an unused integer counter to the filename. Args: userName (str): The input file name. existing: A case-insensitive list of all existing file names. prefix: Prefix to be prepended to the file name. suffix: Suffix to be appended to the file name. Returns: A suitable filename. Raises: NameTranslationError: If no suitable name could be generated. Examples:: >>> 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 9NrczNo unique name could be found.)rOrfrNrZrgrQ)r[r]r^ maxLengthmaxValuerzr{rss rWrxrx!sV"CKK/#f++=I3?##HIG  CLL(61 >>  8 + + I  qLG h     "#CDDD rV__main__N)rUrXrX) rYrZr[r\r]rZr^rZr_rZ)r[r\r]rZr^rZr_rZ) __future__rcollections.abcrr4__annotations__rLrO ExceptionrQrtrkrxrRdoctesttestmodrUrVrWrsb"""""""$$$$$$:0000000b2     9   RTgggggV.0rQSAAAAAJ!"=====@ zNNNGOrV