%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/cupshelpers/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/cupshelpers/__pycache__/xmldriverprefs.cpython-312.pyc

�

�QDb�N���ddlZddlZddlZddlmZd�ZGd�d�ZGd�d�ZGd	�d
�Z	Gd�d�Z
Gd
�d�Zdd�Zy)�N�)�
parseDeviceIDc��tjjjt	|�j��}t
|�S�N)�xml�etree�ElementTree�XML�open�read�list)�filename�preferreddriverss  �</usr/lib/python3/dist-packages/cupshelpers/xmldriverprefs.py�PreferredDriversrs6���y�y�,�,�0�0�$��/�2F�2F�2I�J��� �!�!�c�"�eZdZdZd�Zd�Zd�Zy)�
DeviceIDMatchzK
    A set of fields and regular expressions for matching a Device ID.
    c�"�t�|_yr)�dict�_re��selfs r�__init__zDeviceIDMatch.__init__$s���6��rc��tj|tj�|j|j	�<yr)�re�compile�Ir�upper)r�field�patterns   r�	add_fieldzDeviceIDMatch.add_field's%��#%�:�:�w����#=�������� rc���|jj�D]K\}}||vry|dk(r%d}||D]}|j|�s�d}n|sy|j||�r�Kyy)z�
        Match against a parsed Device ID dictionary.

        The CMD field is treated specially.  If any of the
        comma-separated words in this field value match, the Device ID
        pattern is considered to match.
        F�CMDT)r�items�match)r�deviceidr r&�this_field_matches�cmds      rr&zDeviceIDMatch.match*s���!�H�H�N�N�-�	�L�E�5��H�$����~�%*�"�#�E�?��C��{�{�C�(�-1�*���
*� ��;�;����0��	�"rN)�__name__�
__module__�__qualname__�__doc__rr"r&�rrrr s����>�rrc�`�eZdZdZdZdZdZdZdZd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zy)�
DriverTypez
    A type of driver.
    z	exact-cmd�exact�close�generic�nonec�v�||_d|_g|_g|_Gd�d�}|�|_d|_y)Nc��eZdZdd�Zy)�'DriverType.__init__.<locals>.AlwaysTrueNc��y�NTr.)r�k�ds   r�getz+DriverType.__init__.<locals>.AlwaysTrue.getXs��rr)r*r+r,r<r.rr�
AlwaysTruer7Ws��
rr=)�name�ppd_name�
attributesr'�_fit�_packagehint)rr>r=s   rrzDriverType.__init__Qs;����	���
������
�	�	��M��	� ��rc�`�tj|tj�|_|j�y|jdd�}t
|�dkDrX|d}|dk(rC|d}|jd�r,|dd}|jd�}|d	k7r|d|}d
|z|_yyyd|z|_yy)z:
        An optional PPD name regular expression.
        N�:rr�drvz///��/���z/usr/share/cups/drv/%sz/usr/lib/cups/driver/%s)	rrrr?rB�split�len�
startswith�rfind)rr!�parts�scheme�restrE�fs       r�add_ppd_namezDriverType.add_ppd_name^s����
�
�G�R�T�T�2��
����(���
�
�s�A�&����;��?��1�X�F�����Q�x���?�?�E�*��q�r�(�C��	�	�3��A��B�w�!�"�1�g��,D�s�,J��)��+�%>��$F��!�rc��|jj|tj|tj�f�y)zl
        An optional IPP attribute name and regular expression to match
        against its values.
        N)r@�appendrrr)rr>r!s   r�
add_attributezDriverType.add_attributews*��
	
������r�z�z�7�B�D�D�'A� B�Crc�:�|jj|�y)z8
        An optional IEEE 1284 Device ID match.
        N�r'rS�r�deviceid_matchs  r�add_deviceid_matchzDriverType.add_deviceid_match~���	
�
�
���n�-rc��i|_|j�D]:}d|j|<||jk(s�"d|j|j<�<yr9)rArI�	FIT_EXACT�
FIT_EXACT_CMD)r�text�fittypes   r�add_fitzDriverType.add_fit�sN����	��z�z�|�	5�G�!%�D�I�I�g���$�.�.�(�04��	�	�$�,�,�-�	5rc��||_yr)�_packagekit)r�hints  r�set_packagehintzDriverType.set_packagehint�s
����rc��|jS)z7
        Return the name for this driver type.
        )r>rs r�get_namezDriverType.get_name�s���y�y�rc�6�d|jt|�fzS)Nz <DriverType %s instance at 0x%x>)r>�idrs r�__repr__zDriverType.__repr__�s��1�T�Y�Y��D�	�4J�J�Jrc�8�|jj|d�}|r)|jr|jj|�sd}|rX|jD]I\}}||vrd}n>||}t|t�s|g}d}|D]}	|j|	�s�d}n|r�Gd}n|rv|jrd|vrd}|S|jrV|d}
t|
t�s|
g}
d}|
D]3}t|�}
|jD]}|j|
�s�d}�3�5|sd}|S)z�
        Return True if there is a match for all specified criteria.

        ppdname: string

        attributes: dict

        fit: string
        FTz
ppd-device-id)	rAr<r?r&r@�
isinstancer
r'r)rr?r@�fit�matchesr>r&�values�any_value_matches�value�deviceidlist�any_id_matches�deviceidstrr's              rr&zDriverType.match�sL���)�)�-�-��e�,���t�}�}�T�]�]�-@�-@�(�-K��G��#���
���e��z�)�#�G��#�D�)��!�6�4�0�$�X�F�$)�!�#��E��{�{�E�*�,0�)���
)�#�G��%
�(��}�}��
�!B���(��'��� *�/�:��!�<��6�$0�>�L�!&��#/�"�K�,�k�:�H�!%���"�� �;�;��1�-1�N�!�"�"�&�#�G��rc��yrr.rs r�get_packagehintzDriverType.get_packagehint�s��rN)r*r+r,r-r]r\�	FIT_CLOSE�FIT_GENERIC�FIT_NONErrQrTrYr`rdrfrir&rur.rrr0r0FsX���$�M��I��I�!�K��H�!�G�2D�.�5� ��K�:�xrr0c�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�DriverTypesz!
    A list of driver types.
    c��g|_yr)�drivertypesrs rrzDriverTypes.__init__�s
����rc���g}t|�D�]J}t|jd�}t|�D�]}|jdk(r|j	|jd��2|jdk(r-|j|jd|jd��n|jdk(rht
�}t|�D]>}|jdk(s�|j|jd|jd��@|j|���|jdk(s��|j|j���|j|���M||_y)	zA
        Load the list of driver types from an XML file.
        r>�ppdnamer&�	attributer'r rlN)
r
r0�attrib�tagrQrTrr"rYr`r^rSr|)rr|�types�
drivertype�t�childrXr s        r�loadzDriverTypes.load�s5��
���{�+�	�J��J�-�-�f�5�6�A��j�)�
+���9�9�	�)��N�N�E�L�L��$9�:��Y�Y�+�-��O�O�U�\�\�&�%9�%*�\�\�'�%:�<��Y�Y�*�,�%2�%5�N�!%�e��M�� �9�9��/�*�4�4�e�l�l�6�6J�6;�l�l�7�6K�M�M�
�(�(�.�9��Y�Y�%�'��I�I�u�z�z�*�
+�"
�L�L�!��)	�,!��rc�T�|jD]}|j|||�s�|cSy)z�
        Return the first matching drivertype for a PPD, given its name,
        attributes, and fitness, or None if there is no match.
        N)r|r&)rr~�ppddictrlr�s     rr&zDriverTypes.match�s6���*�*�	"�J�����'�3�7�!�!�	"�rc��tj|jD�cgc]}|j���c}|�Scc}w)z[
        Return the subset of driver type names that match a glob
        pattern.
        )�fnmatch�filterr|rf)rr!�xs   rr�zDriverTypes.filter
s4���~�~�t�7G�7G�H�!��
�
�
�H�&�(�	(��Hs�=c	��g}i}tj}|j�D]e\}}|j|||j	||��}	|	r|	j�}
nd}
|j	|
g�}|j
|�|||
<�g|D]1}|j	|g�D]}||vr�|j
||f���3|S)a
        Given a list of driver type names, a dict of PPD attributes by
        PPD name, and a dict of driver fitness status codes by PPD
        name, return a list of tuples in the form (driver-type-name,
        PPD-name), representing PPDs that match the list of driver
        types.

        The returned tuples will have driver types in the same order
        as the driver types given, with the exception that any
        blacklisted driver types will be omitted from the returned
        result.
        r4)r0rvr%r&r<rfrS)
rr|�ppdsdictrl�ppdnames�ppdtypes�fit_defaultr?�ppd_dictr�r>�m�drivertypenames
             r�get_ordered_ppdnamesz DriverTypes.get_ordered_ppdnamess������� �*�*��"*�.�.�"3�
	��H�h����X�x����(�BM�:O�P�J��!�*�*�-�������d�B�'�A�
�H�H�h���H�T�N�
	�*�	=�N�$�L�L�.�"�=�
=���x�'�����.�(�!;�<�	
=�	=��rN)	r*r+r,r-rr�r&r�r�r.rrrzrz�s ����!�<
�(�'rrzc�L�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
y)
�PrinterTypez�
    A make-and-model pattern and/or set of IEEE 1284 Device ID
    patterns for matching a set of printers, together with an ordered
    list of driver type names.
    c�j�d|_g|_g|_t�|_t�|_yr)�make_and_modelr'�drivertype_patterns�set�avoid�	blacklistrs rrzPrinterType.__init__Cs+��"�����
�#%�� ��U��
����rc�V�tj|tj�|_y)zR
        Set a make-and-model regular expression.  Only one is permitted.
        N)rrrr�)rr!s  r�add_make_and_modelzPrinterType.add_make_and_modelJs��!�j�j�'�2�4�4�8��rc�:�|jj|�y)z(
        Add a Device ID match.
        NrVrWs  rrYzPrinterType.add_deviceid_matchPrZrc�V�|jj|j��y)z/
        Append a driver type pattern.
        N)r�rS�strip�rr>s  r�add_drivertype_patternz"PrinterType.add_drivertype_patternVs��	
� � �'�'�����7rc��|jS)z:
        Return the list of driver type patterns.
        )r�rs r�get_drivertype_patternsz#PrinterType.get_drivertype_patterns\s���'�'�'rc�:�|jj|�y)z3
        Add an avoid driver type pattern.
        N)r��addr�s  r�add_avoidtype_patternz!PrinterType.add_avoidtype_patternbs��	
�
�
����rc��|jS)zB
        Return the set of driver type patterns to avoid.
        )r�rs r�get_avoidtype_patternsz"PrinterType.get_avoidtype_patternshs���z�z�rc�:�|jj|�y)z8
        Add a blacklisted driver type pattern.
        N)r�r�r�s  r�add_blacklistedzPrinterType.add_blacklistedns��	
�����D�!rc��|jS)zE
        Return the set of blacklisted driver type patterns.
        )r�rs r�
get_blacklistzPrinterType.get_blacklistts���~�~�rc���|jduxr|jgk(}|jr|jj|�rd}|s'|jD]}|j|�s�d}|S|S)a}
        Return True if there are no constraints to match against; if
        the make-and-model pattern matches; or if all of the IEEE 1284
        Device ID patterns match.

        The deviceid parameter must be a dict indexed by Device ID
        field key, of strings; except for the CMD field which must be
        a list of strings.

        Return False otherwise.
        NT)r�r'r&)rr�r'rmr&s     rr&zPrinterType.matchzsz���&�&�$�.�F�4�=�=�B�3F������"�"�(�(�.�9�������
���;�;��)�"�G����
�
�rN)r*r+r,r-rr�rYr�r�r�r�r�r�r&r.rrr�r�<s9����9�.�8�(���"��rr�c�"�eZdZdZd�Zd�Zd�Zy)�PreferenceOrderzA
    A policy for choosing the preference order for drivers.
    c��g|_yr)�ptypesrs rrzPreferenceOrder.__init__�s	����rc�F�t|�D�]�}t�}t|�D�][}|jdk(r|j|jd��2|jdk(rht�}t|�D]>}|jdk(s�|j
|jd|jd��@|j|���|jdk(r,t|�D]}|j|j����|jdk(r-t|�D]}|j|j���� |jdk(s��1t|�D]}|j|j����^|jj|����y	)
z3
        Load the policy from an XML file.
        zmake-and-modelr&r'r r>�driversr�r�N)r
r�r�r�r�rr"rYr�r^r�r�r�rS)rr�printer�ptyper�rXr r�s        rr�zPreferenceOrder.load�su��
�,�-�	'�G��N�E��g��
@���9�9� 0�0��,�,�e�l�l�7�.C�D��Y�Y�*�,�%2�%5�N�!%�e��M�� �9�9��/�*�4�4�e�l�l�6�6J�6;�l�l�7�6K�M�M��,�,�n�=��Y�Y�)�+�&*�5�k�G�
��4�4�j�o�o�F�G��Y�Y�'�)�&*�5�k�F�
��3�3�Z�_�_�E�F��Y�Y�+�-�&*�5�k�@�
��-�-�z���?�@�)
@�.
�K�K����&�3	'rc���|�i}|�d}g}t�}t�}|jD]�}|j||�s�|j�D].}|j	|�D]}	|	|vs�|j|	���0|j
�D])}|j	|�D]}	|j|	���+|j�D])}|j	|�D]}	|j|	���+��|r@g}
|D](}	|j|�}||=|
j|��*|j|
�|r!g}
|D]}||vs�|
j|��|
}|S#t$rY�lwxYw)a
        Return an accumulated list of driver types from all printer
        types that match a given printer's device-make-and-model and
        IEEE 1284 Device ID.

        The deviceid parameter must be None or a dict indexed by
        short-form upper-case field keys.
        �)r�r�r&r�r�rSr�r�r��index�
IndexError�extend)rr|r�r'�orderedtypesr��
avoidtypesr�r!r��avoidedr��i�	remainings              r�get_ordered_typesz!PreferenceOrder.get_ordered_types�s������H��!��N����E�	��U�
��[�[�	3�E��{�{�N�H�5�$�<�<�?�=�G�&1�&8�&8�'�&B�=�
�%�\�9�(�/�/��<�=�=� %�;�;�>�4�G�&1�&8�&8�'�&B�4�
�"���
�3�4�4� %�2�2�5�3�G�&1�&8�&8�'�&B�3�
�!�
�
�z�2�3�3�	3�*��G��
���$�*�*�A�.�A�$�Q���N�N�A�&�	
�
����)���I�!�
)���I�%��$�$�a�(�
)�%�L����"����s�%E#�#	E/�.E/N)r*r+r,r-rr�r�r.rrr�r��s����'�@=rr�c
��ddl}ddl}ddlm}ddlm}ddlm}ddl}	|rd�}
|j|
�|j|jd�|�S|	jj|	jj|	jjt�d�d	�}||	jd
<|	jj|d�}|�}t|�\}}
t!�}|j#|�t%�}|j#|
�|�|z
}|rt'd||fz�|j)�}	|j+�}|j1|�}|s|�rl|r"|j3d
�|j5�}nt7|�}d||d�d|d��d�i}|j9�D�]\}}|j;d�dk(r�|j=dd�}t?|t@�r|d}|s�F|jCd�st'|�t7|�}|jE|d|d|d|d|�}|j=dd�}|jG|||�}i}|jI�D]}|jK|�||<�|jM|||�}d}|D]\}} t'd|| ||| fz�|dz
}�!��y|jO�D]�}!|jQ|!�D]�}"|jS|!|"�}#|!dz|"z}|jG||d�}i}|#jI�D]}tTjV||<�|jM||#|�}t'|dz�d}|D]\}} t'd|| |fz�|dz
}�t'�����y#t,$r|j/�}Y��nwxYw)Nrr)�ppds)�pprint)�timec��t|�yr)�print)r�s r�
debugprintztest.<locals>.debugprints	���1�Irr�z..r�CUPSHELPERS_XMLDIRzpreferreddrivers.xmlzTime to load %s: %.3fs�rootz	xxx://yyy�MFG� �MDL)�	device-id�device-make-and-modelrDrHr�zxxx:�DESr$r�z%d  %s
    (%s, %s)z%d  %s
    (%s)),�cups�localer�r�r�r��os.path�set_debugprint_fn�	setlocale�LC_ALL�path�join�dirname�__file__�environrrzr�r�r��
Connection�getPPDs2�AttributeError�getPPDs�PPDs�setUser�
getDevicesrr%�findr<rkr
rK�getPPDNamesFromDeviceIDr��keys�getInfoFromPPDNamer��getMakes�	getModels�getInfoFromModelr0rv)$�xml_path�attachedr'�debugr�r�r�r�r��osr��	loadstart�xmldrivertypes�xmlpreferenceorderr|�	preforder�loadtime�c�cupsppds�	ppdfinder�devices�devid�uri�device�id_dictrl�mmr�r~�orderedppdsr�r��ppd�make�modelr�s$                                    r�testr�s����������	�	
���
�+�
���f�m�m�R�(����7�7�<�<������r�w�w����/I�/3�"5�!&�(��(0�B�J�J�#�$��w�w�|�|�X�'=�>�H���I�+;�X�+F�(�^�'��.�K����n�%��"�I�
�N�N�&�'��w��"�H��
�&�(�H�)=�=�>�����A� ��:�:�=��
�	�	�8�$�I��8���L�L�&�!��l�l�o�G�!�8�,�E�#�+3�BG��,�BG��,�8P� ��G�#�=�=�+�#	�K�C���x�x��~��#���J�J��R�0�E��5�$�'��a������>�>�6�*��s��#�U�+�G��3�3�W�U�^�5<�U�^�5<�U�^�5<�U�^�58�	:�C����4�b�9�B�$�6�6��8:�G�E�L��D��8�8�;�
G�� )� <� <�g� F��W�
�
G�&�:�:�L�<@�<?�A�K��A�%�
���3��,��3��3�s�8�/D�D�E��Q���
�C#	�J�&�&�)�	�D�"�,�,�d�3�
��$�5�5�t�U�C���C�Z�%�'��(�:�:�K�<>�� F����'�}�}�/�8�G�#-�#7�#7�C��L�8�*�>�>��@H�#�O���b�3�h����)��F�A�s��,��3��{�:�;���F�A����%
�	��q� ��9�9�<�� �s�	N+�+O�O)NFNF)
r�r�xml.etree.ElementTreer�cupshelpersrrrr0rzr�r�rr.rr�<module>rs]��.�	��&�"�$�$�LP�P�db�b�HV�V�pe�e�Por

Zerion Mini Shell 1.0