§
    ¢”j   ã                   óÔ  — d Z d                     d¦  «        Zed„  edd¦  «        D ¦   «         z  Ze ed¦  «        gz  Zd                     ¦   «                              d¦  «        Zed                     ¦   «                              d¦  «        z  Zd	Z G d
„ de¦  «        Z	g ddfd„Z
g ddfd„Zg ddfd„Zedk    r,ddlZddlZ ej         ej        ¦   «         j        ¦  «         dS dS )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 <http://unifiedfontobject.org/versions/ufo3/conventions/>`_
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 <https://github.com/unified-font-object/ufoLib/blob/8747da7/Lib/ufoLib/filenames.py>`_
by Tal Leming and is copyright (c) 2005-2016, The RoboFab Developers:

-	Erik van Blokland
-	Tal Leming
-	Just van Rossum
z\" * + / : < > ? [ \ ] | \0ú c                 ó,   — g | ]}t          |¦  «        ‘ŒS © )Úchr)Ú.0Úis     úg/var/www/finuniver-perm.ru/html/portfolio/venv/lib/python3.11/site-packages/fontTools/misc/filenames.pyú
<listcomp>r	      s   € Ð3Ð3Ð3 •c˜!‘f”fÐ3Ð3Ð3ó    é   é    é   z!CON PRN AUX CLOCK$ NUL A:-Z: COM1zLPT1 LPT2 LPT3 COM2 COM3 COM4éÿ   c                   ó   — e Zd ZdS )ÚNameTranslationErrorN)Ú__name__Ú
__module__Ú__qualname__r   r
   r   r   r      s   € € € € € Ø€Dr
   r   Ú c                 óÊ  — 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Œ  Converts 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   Nr   )Ú
isinstanceÚstrÚ
ValueErrorÚlenÚillegalCharactersÚlowerÚappendÚjoinÚmaxFileNameLengthÚsplitÚreservedFileNamesÚhandleClash1)ÚuserNameÚexistingÚprefixÚsuffixÚprefixLengthÚsuffixLengthÚfilteredUserNameÚ	characterÚsliceLengthÚpartsÚpartÚfullNames               r   ÚuserNameToFileNamer1       s‘  € õD �h¥Ñ$Ô$ð EÝÐCÑDÔDÐDå�v‘;”;€LÝ�v‘;”;€Lð ð &�h˜q”k SÒ(Ð(Ø˜ ! " "œÑ%ˆàÐØð +ð +ˆ	àÕ)Ð)Ð)ØˆIˆIà˜)Ÿ/š/Ñ+Ô+Ò+Ð+Ø˜ÑˆIØ×Ò 	Ñ*Ô*Ð*Ð*Ø�wŠwÐ'Ñ(Ô(€Hå# lÑ2°\ÑA€KØ˜˜˜Ô%€Hà€EØ—’˜sÑ#Ô#ð ð ˆØ�:Š:‰<Œ<Õ,Ð,Ð,Ø˜‘:ˆDØ�Š�TÑÔÐÐØ�xŠx˜‰Œ€Hà˜Ñ  6Ñ)€HØ‡~‚~ÑÔ˜8Ð#Ð#Ý ¨(°F¸FÑCÔCˆà€Or
   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
    é   Nr   l   ÿŒIú5 )r   r!   r   Úzfillr   ÚhandleClash2)r%   r&   r'   r(   r)   r*   Úlr-   Ú	finalNameÚcounterÚnamer0   s               r   r$   r$   ˆ   s  € õ> �v‘;”;€LÝ�v‘;”;€LØ•c˜(‘m”mÑ# lÑ2°RÑ7Õ:KÒKÐKØ�3˜x™=œ=Ñ(¨<Ñ7¸"Ñ<ˆÝ'¨!Ñ+ˆØ˜L˜[˜LÔ)ˆØ€Ià€GØ
Ð
Ø�#˜g™,œ,×,Ò,¨RÑ0Ô0Ñ0ˆØ˜D‘= 6Ñ)ˆØ�>Š>ÑÔ 8Ð+Ð+Ø ˆIØà�q‰LˆGØ�oÒ%Ð%Øð Ð
ð ÐÝ  ¨6°6Ñ:Ô:ˆ	àÐr
   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
    Ú9Nr   zNo unique name could be found.)r!   r   Úintr   r   r   )r&   r'   r(   Ú	maxLengthÚmaxValuer7   r8   r0   s           r   r5   r5   Á   s®   € õ6 "¥C¨¡K¤KÑ/µ#°f±+´+Ñ=€IÝ�3˜‘?Ñ#Ô#€Hà€IØ€GØ
Ð
Ø�C ™LœLÑ(¨6Ñ1ˆØ�>Š>ÑÔ 8Ð+Ð+Ø ˆIØà�q‰LˆGØ�hÒÐØð Ð
ð ÐÝ"Ð#CÑDÔDÐDàÐr
   Ú__main__r   N)Ú__doc__r"   r   Úranger   r   r#   r!   Ú	Exceptionr   r1   r$   r5   r   ÚdoctestÚsysÚexitÚtestmodÚfailedr   r
   r   ú<module>rH      s~  ððð ð& 3×8Ò8¸Ñ=Ô=Ð Ø Ð3Ð3 e e¨A¨r¡l¤lÐ3Ñ3Ô3Ñ 3Ð Ø �c�c˜$‘i”i�[Ñ  Ð Ø7×=Ò=Ñ?Ô?×EÒEÀcÑJÔJÐ Ø Ð4×:Ò:Ñ<Ô<×BÒBÀ3ÑGÔGÑ GÐ ØÐ ð	ð 	ð 	ð 	ð 	˜9ñ 	ô 	ð 	ð +-°RÀð eð eð eð eðP %'¨r¸"ð 6ð 6ð 6ð 6ðr  R°ð -ð -ð -ð -ð` ˆzÒÐØ€N€N€NØ€J€J€Jà€C„Hˆ_ˆWŒ_ÑÔÔ%Ñ&Ô&Ð&Ð&Ð&ð	 Ðr
   