� ��g ����dZd�d��Zed�edd��D��z Zeed��gz Zd����d��Zed����d��z Zd ZGd �d e��Z gd d fd �Z gd d fd�Z gd d fd�Z e dkr,ddlZddlZejej��j��dSdS)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 �h/home/asafur/pinokio/api/open-webui.git/app/env/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: COM1zLPT1 LPT2 LPT3 COM2 COM3 COM4��c��eZdZdS)�NameTranslationErrorN)�__name__� __module__� __qualname__rr rrrs�������Dr r�c���t|t��std���t|��}t|��}|s|ddkr d|dd�z}g}|D]@}|tvrd}n||���kr|dz }|�|���Ad�|��}t|z |z }|d|�}g} |� d��D]7} | ���tvrd| z} | �| ���8d�| ��}||z|z} | ���|vrt||||��} | 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|zdztkr,|t|��z|zdz}t|z }|d|�}d}d} |�T|t| ���d��z} || z|z} | ���|vr| }n| dz } | dkrn|�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)rr!r�zfillr� handleClash2) r%r&r'r(r)r*�lr-� finalName�counter�namer0s rr$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��tt|��z t|��z }td|z��}d}d}|�<|t|��z|z}|���|vr|}n|dz }||krn|�<|�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 zNo unique name could be found.)r!r�intrrr)r&r'r(� maxLength�maxValuer7r8r0s rr5r5�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__rN)�__doc__r"r�rangerrr#r!� Exceptionrr1r$r5r�doctest�sys�exit�testmod�failedrr r�<module>rHs~����&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
Memory