o
    nÄŽiž)  ã                   @  sª   U d dl mZ d dlmZ 	 h d£Zded< h d£Zded< dZd	ed
< G dd„ deƒZ		dddd„Z
g ddfddd„Zg ddfd dd„ZedkrSd dlZe ¡  dS dS )!é    )Úannotations)ÚIterable>/   Ú
Ú*ú úúúúúúúúú	úúúúúúúúúúúúúúúúúúúúúú"ú(ú)ú+ú/ú:ú<ú>ú?ú[ú\ú]ú|úzset[str]ÚillegalCharacters>   úclock$ÚauxÚconÚnulÚprnÚcom1Úcom2Úcom3Úcom4Úcom5Úcom6Úcom7Úcom8Úcom9Úlpt1Úlpt2Úlpt3Úlpt4Úlpt5Úlpt6Úlpt7Úlpt8Úlpt9ÚreservedFileNameséÿ   ÚintÚmaxFileNameLengthc                   @  s   e Zd ZdS )ÚNameTranslationErrorN)Ú__name__Ú
__module__Ú__qualname__© rS   rS   úV/home/jeff/fluffinator/venv/lib/python3.10/site-packages/fontTools/ufoLib/filenames.pyrO   o   s    rO   rS   Ú ÚuserNameÚstrÚexistingúIterable[str]ÚprefixÚsuffixÚreturnc                 C  s  t | tƒs	tdƒ‚t|ƒ}t|ƒ}|s!| d dkr!d| dd…  } g }| D ]}|tv r.d}n
|| ¡ kr8|d7 }| |¡ q%d |¡} t| | }| d|… } g }	|  	d¡D ]}
|
 ¡ t
v rbd|
 }
|	 |
¡ qVd |	¡} ||  | }| ¡ |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   Ú.Ú_é   NrU   )Ú
isinstancerW   Ú
ValueErrorÚlenr3   ÚlowerÚappendÚjoinrN   ÚsplitrK   ÚhandleClash1)rV   rX   rZ   r[   ÚprefixLengthÚsuffixLengthÚfilteredUserNameÚ	characterÚsliceLengthÚpartsÚpartÚfullNamerS   rS   rT   ÚuserNameToFileNames   s4   
D

rp   c                 C  sÂ   t |ƒ}t |ƒ}|t | ƒ | d tkr(|t | ƒ | d }t| }| d|… } d}d}	|du rU| t|	ƒ d¡ }
||
 | }| ¡ |vrH|}n|	d7 }	|	dkrQn|du s0|du r_t|||ƒ}|S )aC  A 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
    é   Nr_   l   ÿŒIú5 )rb   rN   rW   Úzfillrc   ÚhandleClash2)rV   rX   rZ   r[   rh   ri   Úlrl   Ú	finalNameÚcounterÚnamero   rS   rS   rT   rg   Ý   s*   *÷rg   c                 C  s€   t t|ƒ t|ƒ }td| ƒ}d}d}|du r6|t|ƒ | }| ¡ | vr)|}n|d7 }||kr2n|du s|du r>tdƒ‚|S )ak  A 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
    Ú9Nr_   zNo unique name could be found.)rN   rb   rM   rW   rc   rO   )rX   rZ   r[   Ú	maxLengthÚmaxValueru   rv   ro   rS   rS   rT   rs   !  s    +ø
rs   Ú__main__N)rS   rU   rU   )
rV   rW   rX   rY   rZ   rW   r[   rW   r\   rW   )rX   rY   rZ   rW   r[   rW   r\   rW   )Ú
__future__r   Úcollections.abcr   r3   Ú__annotations__rK   rN   Ú	ExceptionrO   rp   rg   rs   rP   ÚdoctestÚtestmodrS   rS   rS   rT   Ú<module>   s"    1ÿkÿEÿ@ý