L i dZdjdZeeddDcgc] }e| c}z Zeedgz Zdj jdZedj jdz ZdZGd d eZ gd d fd Z gd d fd Z gd d fdZ e dk(r4ddlZddlZej ej"j$yycc}w)a This module implements the algorithm for converting between a "user name" - something that a user can choose arbitrarily inside a font editor - and a file name suitable for use in a wide range of operating systems and filesystems. The `UFO 3 specification `_ provides an example of an algorithm for such conversion, which avoids illegal characters, reserved file names, ambiguity between upper- and lower-case characters, and clashes with existing files. This code was originally copied from `ufoLib `_ by Tal Leming and is copyright (c) 2005-2016, The RoboFab Developers: - Erik van Blokland - Tal Leming - Just van Rossum z\" * + / : < > ? [ \ ] | \0  z!CON PRN AUX CLOCK$ NUL A:-Z: COM1zLPT1 LPT2 LPT3 COM2 COM3 COM4c eZdZy)NameTranslationErrorN)__name__ __module__ __qualname__^/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/fontTools/misc/filenames.pyrrsr rcDt|ts tdt|}t|}|s|ddk(rd|ddz}g}|D]6}|tvrd}n||j k7r|dz }|j |8dj|}t|z |z }|d|}g} |jdD].} | j tvrd| z} | j | 0dj| }||z|z} | j |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.._rNr) isinstancestr ValueErrorlenillegalCharacterslowerappendjoinmaxFileNameLengthsplitreservedFileNames handleClash1) userNameexistingprefixsuffix prefixLength suffixLengthfilteredUserName character sliceLengthpartspartfullNames ruserNameToFileNamer, sFD h $CDDv;Lv;L hqkS(!"%+ ) )I )//+ +  I *+ww'(H#l2\AK %H Es# ::<, ,:D TxxH 6)H~~8#(FFC Or cft|}t|}|t|z|zdztkDr"|t|z|zdz}t|z }|d|}d}d} |H|t| jdz} || z|z} | j |vr| }n| dz } | dk\rn|H| 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 NrlI5)rrrzfillr handleClash2) r r!r"r#r$r%lr( finalNamecounternamer+s rrrs>v;Lv;Lc(m#l2R7:KK 3x= (< 7" <'!+ L[)IG  #g,,,R00D=6) >> 8 + I  qLG o %    66: r ctt|z t|z }td|z}d}d}|4|t|z|z}|j |vr|}n|dz }||k\rn|4| 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 9NrzNo unique name could be found.)rrintrrr)r!r"r# maxLengthmaxValuer2r3r+s rr0r0s6"CK/#f+=I3?#HIG  CL(61 >> 8 + I  qLG h    "#CDD r __main__rN)__doc__rrrangechrrrr Exceptionrr,rr0r doctestsysexittestmodfailed)is0rrEs&388=eArl3c!f33c$i[ 7==?EEcJ4::<BB3GG 9 +-ReP%'r"6rR-` z CHH_W__  % %& y4sC