%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__/ppds.cpython-312.pyc

�

�QDb����n�ddlZddlmZddlmZddlZddlZddlZddlZddl	Z
ddlZddlZddlm
Z
mZddlmZddgZd	ej"d
�fdej"d�fd
ej"d�fdej"d�fdej"d�fdej"d�fdej"d�fdej"d�fdej"d�fdej"d�fdej"d�fdej"d �fgZiZeD]\ZZeeej-�<�d!d"d#d$d%d&d'�Zej"d(�Zej"d)�Zej"d*�Zej"d+ej6�Zd,�Zd-�Zd.�ZGd/�d�Z d0�Z!y)1�N�)�
parseDeviceID)�xmldriverprefs)�_debugprint�set_debugprint_fn)�reduce�ppdMakeModelSplit�PPDs�HPzhdeskjet|dj[ 0-9]?|laserjet|lj|color laserjet|color lj|designjet|officejet|oj|photosmart|ps |psc|edgeline�Epsonzstylus|aculaser�Applez.stylewriter|imagewriter|deskwriter|laserwriter�Canonz%pixus|pixma|selphy|imagerunner|bj|lbp�Brotherz
hl|dcp|mfc�Xeroxz/docuprint|docupage|phaser|workcentre|homecentre�Lexmarkzoptra|(:color )?jetprinter�KONICA MINOLTAzmagicolor|pageworks|pagepro�Kyocerazfs-|km-|taskalfa�Ricoh�aficio�Oce�
varioprint�Okizokipage|microline�DeskJet�LaserJet�	OfficeJetzColor LaserJet�
PhotoSmart�)�dj�lj�ojzcolor ljzps zhp �
turboprintz! v(?:er\.)?\d(?:\d*\.\d+)?(?: |$)zn,| hpijs| foomatic/| - | w/| \(| postscript| ps| pdf| pxl| zjs| zxs| pcl3| printer|_bt| pcl| ufr ii| br-scriptz series| all-in-onec��|j�d}d}|j�}tD]\}}|j|�s�|}|}n|��tj|�r�|j
d�}|dk7r$|jd�}||k7r	||dz|}n|d|}	|jdd�\}}tjd	d
|�}tjdd
|�}tjd	d
|�}tjdd
|�}tjdd
|�}tjdd|�}d}n�|jd�rd}|dd}n||jd�rd}|dd}nc|jd�rd}|dd}nJ|jd�rd}|dd}n1|jd�rd}|dd}nd}	|jd
d�\}}|j�}	|rg|	jd�r|	jd �rd!}d"}	n@|	jd#�r|	jd$�rd}d%}	ntj|	�}|r|}|j�}
|
j
d&�}|dk7r1tj|
�}|r|j!�}
|
d|
}
|d|
}t"j|
�}|r|j!�}|
d|}
|d|}t$j'd|d�'�\}}|r|j�}
|	d"k(rPt(j+�D]9\}}|
j|�s�||t-|�dz}|j�}
n|j�}||fS#|}d}Y���xYw#|}d}Y���xYw)(z�
    Split a ppd-make-and-model string into a canonical make and model pair.

    @type ppd_make_and_model: string
    @param ppd_make_and_model: IPP ppd-make-and-model attribute
    @return: a string pair representing the make and the model
    NFz TurboPrint�����_rrz(?<=[a-z])(?=[0-9])� z(?<=[a-z])(?=[A-Z])z Jet�JetzPhoto SmartrTzkonica minolta r�zlexmark international r�z
kyocera mita r�
zkyocera �zfuji xerox z
Fuji Xerox��hewlett�packardr�hp�konica�minoltazkonica minoltaz v)�count)�strip�lower�
_MFR_BY_RANGE�match�_RE_turboprint�search�find�rfind�split�re�sub�
startswith�endswith�_MFR_NAMES_BY_LOWER�get�_RE_version_numbers�start�_RE_ignore_suffix�_RE_ignore_series�subn�_HP_MODEL_BY_NAME�items�len)�ppd_make_and_model�make�cleanup_make�l�mfr�regexp�model�t�t2�makel�modell�v�vmatch�vstart�suffix�suffixstart�n�name�fullnames                   �2/usr/lib/python3/dist-packages/cupshelpers/ppds.pyr	r	ws��������D��L�� � �#�A�$����V��<�<����D�&�E��	��|��-�-�q�1��#�#�]�3����7�#�)�)�=�9�B��B�w�%7��B��r�%B�"�%7���%;�"�	�,�2�2�3��:�K�D�%��v�v�-�s�D�9���v�v�-�s�D�9�����.��U�;�����.��U�;��������.�������e�<����
���(�	)���"�2�3�'��	
���/�	0���"�2�3�'��	
����	'���"�2�3�'��	
���z�	"���"�1�2�&��	
���}�	%���"�2�3�'����	�,�2�2�3��:�K�D�%�
�J�J�M�E�����i�(��N�N�I�&��D��E�����)��n�n�i�(�#�D�$�E�&�)�)�5�1�C�����[�[�^�F����T��A��B�w�%�+�+�V�4����\�\�_�F��G�V�_�F��'�6�N�E�
�
%�
%�v�
.�F�
��l�l�o�����%���l�{�#��#�'�'��U�!�'�<�J�U�A���������}�/�5�5�8�	�N�D�(�� � �$�'� �5��d���#5�5��������		�
�K�K�N�E��%�=���C	�%�D��E��>	�%�D��E�s�M*�>M6�*M3�6M?c�T�|j�j�}d}d}d}d}|}d}tt|��D]f}||j	�r||k7r|r|dz
}|}n$||j�r||k7r|r|dz
}|}n|}||j
�s�]|||z
}d}�h|S)a
    This function normalizes manufacturer and model names for comparing.
    The string is turned to lower case and leading and trailing white
    space is removed. After that each sequence of non-alphanumeric
    characters (including white space) is replaced by a single space and
    also at each change between letters and numbers a single space is added.
    This makes the comparison only done by alphanumeric characters and the
    words formed from them. So mostly two strings which sound the same when
    you pronounce them are considered equal. Printer manufacturers do not
    market two models whose names sound the same but differ only by
    upper/lower case, spaces, dashes, ..., but in printer drivers names can
    be easily supplied with these details of the name written in the wrong
    way, especially if the IEEE-1284 device ID of the printer is not known.
    This way we get a very reliable matching of printer model names.
    Examples:
    - Epson PM-A820 -> epson pm a 820
    - Epson PM A820 -> epson pm a 820
    - HP PhotoSmart C 8100 -> hp photosmart c 8100
    - hp Photosmart C8100  -> hp photosmart c 8100

    @type strin: string that can be the make or the model
    @return: a normalized lowercase string in which punctuations have been replaced with spaces.
    rrr�Fr&T)r3r4�rangerI�isalpha�isdigit�isalnum)	�strin�lstrin�
normalized�BLANK�ALPHA�DIGIT�lastchar�
alnumfound�is	         r]�	normalizerm�s���0�[�[�^�
!�
!�
$�F��J�
�E�
�E�
�E��H��J�
�C��L�
!����!�9�����5� �Z��c�!�
��H�
�A�Y�
�
�
!��5� �Z��c�!�
��H��H��!�9�����&��)�#�J��J�� ��c�0�t|t�r|dS|S)z{If we don't know whether getPPDs() or getPPDs2() was used, this
    function can unwrap an item from a list in either case.r)�
isinstance�list)�xs r]�
_singletonrs.s���1�d����t���Hrnc
��eZdZdZdZdZdZdZejjZ
ejjZejjZejjZ
ejjZe
eeeeee
eeeiZdd�Zd�Zd	�Zd
�Zd�Zd�Z				dd
�Z			dd�Z				dd�Zd�Zdd�Zd�Zd�Zy)r
a\
    This class is for handling the list of PPDs returned by CUPS.  It
    indexes by PPD name and device ID, filters by natural language so
    that foreign-language PPDs are not included, and sorts by driver
    type.  If an exactly-matching PPD is not available, it can
    substitute with a PPD for a similar model or for a generic driver.
    rrr_�Nc��|j�|_d|_d|_t	j
�|_t	j�|_|�Qtjjd�}|�0ddlm
}tjj|j d�}	tjj|d�}t	j"|�\}}|jj%|�|jj%|�|�
|d	k(s|d
k(rd}|j+d�}	|	d
k7r|d|	}
n|}
g}|jj-�D]7\}}
	t/|
d�}|dk(r�||k(r�!||
k(r�'|j3|��9|D]}|j|=�d|jvrCt/|jdd�}|j5d�sd|z|jdd<yyy#t&$r*}t)d�d|���d|_d|_Yd}~��d}~wwxYw#t0$rY��wxYw)a%
        @type ppds: dict
        @param ppds: dict of PPDs as returned by cups.Connection.getPPDs()
        or cups.Connection.getPPDs2()

        @type language: string
	@param language: language name, as given by the first element
        of the pair returned by locale.getlocale()
        N�CUPSHELPERS_XMLDIRr)�config�cupshelperszpreferreddrivers.xmlzError loading �: �C�POSIX�en_USr%r#zppd-natural-language�en�raw�ppd-make-and-modelzGeneric )�copy�ppds�makes�idsr�DriverTypes�drivertypes�PreferenceOrder�	preforder�os�environrArrx�path�join�
sysconfdir�PreferredDrivers�load�	Exception�printr9rHrs�KeyError�appendr>)�selfr��language�xml_dirrx�xmlfiler��preferenceorder�e�u�short_language�	to_remove�ppdname�ppddict�natural_language�	makemodels                r]�__init__z
PPDs.__init__Ps8���I�I�L��	���
����)�5�5�8���'�7�7�:����?��j�j�n�n�&:�;�G���$��'�'�,�,��(9�(9�=�I��		"��g�g�l�l�G�-C�D�G��/�/��9�
+�[�/����!�!�;�/��N�N����1�
����O�����H��M�M�3�����7�%�b�q�\�N�%�N��	� $�	�	��� 2�	'��G�W�
�#-�w�7M�/N�#O� � �4�'���8�+���>�1�����g�&�#	'�&!�	#�G��	�	�'�"�	#��D�I�I��"�D�I�I�e�$4�5I�$J�K�I��'�'��4�9C�i�9O��	�	�%� �!5�6�5���U�	"��G�Q�7�8�#�D��!�D�N�N��	"��(�
��
�s+�*A.H�'H6�	H3�	H.�.H3�6	I�Ic��|j�t|jj��}|j	t
j��	|jd�|jdd�|S#t$rY|SwxYw)zb
	@returns: a list of strings representing makes, sorted according
        to the current locale
	��key�Genericr)
�_init_makesrqr��keys�sort�locale�strxfrm�remove�insert�
ValueError)r��
makes_lists  r]�getMakesz
PPDs.getMakes�s|��
	
�����$�*�*�/�/�,�-�
����V�^�^��,�	����y�)����q�)�,�����	����	�s�#A:�:	B�Bc���|j�	t|j|j��}d�}|jt
j|���|S#t$rgcYSwxYw)zS
	@returns: a list of strings representing models, sorted using
	cups.modelSort()
	c�Z�t|�}t|�}tj||�S�N)rm�cups�	modelSort)�a�b�first�seconds    r]�compare_modelsz&PPDs.getModels.<locals>.compare_models�s%���q�M�E���]�F��>�>�%��0�0rnr�)r�rqr�r�r�r��	functools�
cmp_to_key)r�rK�models_listr�s    r]�	getModelszPPDs.getModels�sp��
	
����	��t�z�z�$�/�4�4�7�8�K�	1�	���Y�1�1�.�A��B�����	��I�	�s�&A"�"A0�/A0c�j�|j�	|j||S#t$ricYSwxYw)z�
	Obtain a list of PPDs that are suitable for use with a
        particular printer model, given its make and model name.

	@returns: a dict, indexed by ppd-name, of dicts representing
        PPDs (as given by cups.Connection.getPPDs)
	)r�r�r�)r�rKrPs   r]�getInfoFromModelzPPDs.getInfoFromModel�s=��	
����	��:�:�d�#�E�*�*���	��I�	�s�$�2�2c� �|j|S)zM
	@returns: a dict representing a PPD, as given by
	cups.Connection.getPPDs
	)r�)r�r�s  r]�getInfoFromPPDNamezPPDs.getInfoFromPPDName�s��
�y�y��!�!rnc�j�|jj|tjj�Sr�)�_fit_to_statusrAr�
DriverType�FIT_NONE)r��fits  r]�getStatusFromFitzPPDs.getStatusFromFit�s'���"�"�&�&��^�-F�-F�-O�-O�P�Prnc���|�g}|�g}|�i}|jr�|jr�i}|D]}|j|||<�|jj|j||�}t	dt|�z�|jj
|||�}	t	dt|	�z�|	D�
cgc]}
|
d��	}}
t	dt|�z�t�}|D](}|jd�\}
}}|j|��*|rUg}|D]-}|jd�\}
}}||vs�|j|��/|r|D]}||vs�|j|��|}|Scc}
w)a`

	Sort a list of PPD names by preferred driver type.

	@param ppdnamelist: PPD names
	@type ppdnamelist: string list
        @param downloadedfiles: Filenames from packages downloaded
        @type downloadedfiles: string list
        @param make_and_model: device-make-and-model name
        @type make_and_model: string
        @param devid: Device ID dict
        @type devid: dict indexed by Device ID field name, of strings;
        except for CMD field which must be a string list
        @param fit: Driver fit string for each PPD name
        @type fit: dict of PPD name:fit
	@returns: string list
	z9Valid driver types for this printer in priority order: %sz5PPDs with assigned driver types in priority order: %srz(Resulting PPD list in priority order: %s�/)r�r�r��get_ordered_typesr�repr�get_ordered_ppdnames�set�
rpartition�addr�)r��ppdnamelist�downloadedfiles�make_and_model�devidr�r�r��orderedtypes�orderedppds�typ_name�downloadedfnames�downloadedfiler��slash�fname�downloadedppdnames�ppdfnames                  r]�orderPPDNamesByPreferencezPPDs.orderPPDNamesByPreference�s���*���K��"� �O��;��C��������D�&�
3�� $�	�	�'� 2��W�
�
3� �>�>�;�;�T�=M�=M�=K�=B�D�L�
�S�VZ�[g�Vh�h�i��*�*�?�?��AE�s�L�K��O�RV�Wb�Rc�c�d�7B�C�8�8�A�;�C�K�C��B�T�+�EV�V�W��5��-�	)�N�#1�#<�#<�c�#B� �T�5�%�� � �%�(�	)��!#��&�
8��*1�*<�*<�c�*B�'��u�h��/�/�&�-�-�w�7�
8�"�*�<�G��&8�8�*�1�1�7�;�<�1�����5Ds�6E+c	��td|�d|���|}|}|j�|�g}i}	|j�}
|j�}d}	|j|
|D]}
|j|	|
<�d}|
dk(rd	|jd|D]}
|j|	|
<�td|jd|z�td	|�d
|�d��td�d}td
�d}|j
�d}|
dk(r$t|�\}}t|�}
t|�}td|
z�td|z�dddd�}|
|jvr|j|
}n8|
|vr4||
}||jvr!|}|}
td|
z�|j|
}td|z�|��G|j|}|jt|�}|
ddfD]A}|j|dz�s�|t|�dzd}t|�}td|z��C||j|
vr@||}||j�D]$}
|j|	|
<t|	|
�d|
����&n�t|dz|z�\}}t|�}td|z�||j|
vrH||}t||j��D]$}
|j|	|
<t|	|
�d|
����&|	sE|rC|j!||�\}}||j"k7r|D]}
||	|
<t|	|
�d|
����|rjt%|�tk7r|j'd�}td�|j)|�}|r)|D]$}|j*|	|<t|	|�d|����&|r7|jd�s�|jd�s�|jd�rd|vrrt-�}|	j�D]%}|jd �s�|j/|��'t|�d!kDrtd"|z�|D]}
|	|
=�t-�}|�r�t|�d!kD�r�t-�}t-�}|	j�D]�}d}|j0|} t3| j5d#��}!|!rt7|!�}"|"d$}|s6|j9d%�d&k(r"t3| j5d'��}#|#d(k(rd)g}|s�{d}$|D]
}%|%|vs�d}$n|$r|j/|���|j/|���|D]?}
|	|
|jk(s�|j:|	|
<t|j:d*|
zz��At|�t|	j=�D�&�'cgc]\}&}'|'d+k7r|&��c}'}&�krtd,|z�|D]}
|	|
=�ntd-|zd.z�|	s�d/d0g}(d})|(D]{}*td1|*z�|*d2z}+|j0j�D]7},|,j?|*�s|,j?|+�s�&|j"|	|,<d})n|)rntd3|*z��}|)s>td4�|j"|	t|j0j��d!<|setAjBd5d6tE|��7�}-	tGd8�|�}.d9|�d
|�d�}/|.r|/d:|.zz
}/|r|/d;|zz
}/td<|-z�t|/�|	S#t
$rY���wxYw#t
$rY��WwxYwcc}'}&w#tH$rd}.Y�kwxYw)=a9
	Obtain a best-effort PPD match for an IEEE 1284 Device ID.

	@param mfg: MFG or MANUFACTURER field
	@type mfg: string
	@param mdl: MDL or MODEL field
	@type mdl: string
	@param description: DES or DESCRIPTION field, optional
	@type description: string
	@param commandsets: CMD or COMMANDSET field, optional
	@type commandsets: string
	@param uri: device URI, optional (only needed for debugging)
	@type uri: string
        @param make_and_model: device-make-and-model string
        @type make_and_model: string
	@returns: a dict of fit (string) indexed by PPD name
	�
r&NFT�hewlett-packardr/z&**** Incorrect IEEE 1284 Device ID: %sz**** Actual ID is MFG:z;MDL:�;z4**** Please report a bug against the HPLIP componentzTrying make/model namesrzmfgl: %szmdll: %s�lexmarkzkyocera mita)r�zlexmark international�kyocerazremapped mfgl: %szmake: %srzunprefixed mdll: %srzzre-split mdll: %s�,zChecking CMD fieldzipp:zipps:�dnssdz._ippzdriverless:rz$Removed %s due to non-IPP connection�
ppd-device-id�CMD�:r#zppd-type�
postscript�
POSTSCRIPTz: %s�genericzRemoved %s due to CMD mis-matchzNot removing %s z3due to CMD mis-match as it would leave nothing goodztextonly.ppdzpostscript.ppdz
'%s' fallbackz.gzzFallback '%s' not availablez#No fallback available; choosing anyz
//[^@]*@/?z//)�pattern�repl�stringc��|dz|zS)Nr���rr�ys  r]�<lambda>z.PPDs.getPPDNamesFromDeviceID.<locals>.<lambda>s��1�s�7�A�:�rnzMFG:zCMD:%s;zDES:%s;zNo ID match for device %s:)%r�	_init_idsr4r��	FIT_EXACTr�r�r	rm�lmakesr��lmodelsr>rIr�rq�_findBestMatchPPDsr��typer;�_getPPDNameFromCommandSet�FIT_GENERICr�r�r�rsrArr9�
FIT_EXACT_CMDrHr?r<r=�strr�	TypeError)0r��mfg�mdl�description�commandsets�urir��orig_mfg�orig_mdlr��mfgl�mdll�
id_matched�each�mdlsrK�mfgrepl�rmfg�mdlsl�prefixrP�mfg2�mdl2�mdl2l�sr�r��driver�failedr��	exact_cmd�
ppd_cmd_field�ppd�
ppd_device_id�ppd_device_id_dict�ppd_type�usable�pdl�d�m�	fallbacks�found�fallback�
fallbackgz�ppdpath�
sanitised_uri�cmd�ids0                                                r]�getPPDNamesFromDeviceIDzPPDs.getPPDNamesFromDeviceIDs���(	�#�s�+�,������������K���
�y�y�|���y�y�|���
�	������t�,�
+�� �N�N��D�	�
+��J�
�$�$�	
� �H�H�T�N�4�0�/�D� $���C��I�/��E�!�X�X�d�^�D�1�2�3��3��L�M��S�T�!�
�
	�.�/����������2�:�*�C�0�J�S�#��c�?�D��c�?�D��Z�$�&�'��Z�$�&�'�&*�,5�,�.���4�;�;���;�;�t�$�D�
�W�_��4�=�D��t�{�{�"������0�4�7�8��{�{�4�(���Z�$�&�'����:�:�d�#�D��L�L��4��1�E� �!2�D�9�
?���?�?�F�S�L�1��c�6�l�Q�.�/�0�C�$�c�?�D��!6��!=�>�	
?��t�|�|�D�)�)��d��� ��K�,�,�/�?�D� $���C��I��S��Y��!=�>�?� 1�#��)�c�/�B���t�!�4�(���0�5�8�9��D�L�L��.�.�!�%�L�E� $�T�%�[�%5�%5�%8� 9�C��$(�N�N��D�	�#��T��D�%A�B�C��t��/�/��s�;�I�Q���D�M�M�!� �?�D� !�C��I��S��Y��!=�>�?���[�!�T�)�)�/�/��5���-�.��4�4�k�B�G��%�C�F�"&�"2�"2�C��K��S��[�&�!A�B�C������'�����(��.�.��)��S�.��U�F��8�8�;�
)���&�&�}�5��J�J��(�
)��F��a���C�f�L�M�"�"�D��D�	�"��U�F�0�#�{�+�a�/��U�F���I��8�8�;�"
)�� $�
��i�i��(�� *�C�G�G�_�,E� F�
� �)6�
�)F�&�$6�u�$=�M�%�
�L�L�#�&�"�,� *�3�7�7�J�+?�@�H��<�/�)5��
�$����(��C��k�)�!%����
��M�M�7�+��J�J��(�E"
)�L"�
E���t�9����.� $� 2� 2�C��I���!3�!3�f�t�m�!C�D�
E�
�F�|�c�C�I�I�L�$7�&�1�a�'(�I�~�%&�$7�8�8��>��G�H�"�"�D��D�	�"��/�&�8�2�2�3��'�)9�:�I��E�%�

G���_�x�7�8�%��-�
�#�y�y�~�~�0��G��(�(�(�3��(�(�*�5�'+�}�}��G�� $�������:�X�E�F�

G���B�C�26�-�-��D������*�+�A�.�/���F�F�L�t�+.��9�6�M�
��5�{�C���&.�x�8�B���i�#�o�%����i�+�-�-���5�
�E�F�����
��A�	��	���
��
��F$7��J�
���
�s=�(\�=A#\+�%\;�
]�	\(�'\(�+	\8�7\8�]�]c�4�|�g}|�g}|j||||||�}||||d�}	|jt|j��|||	|�}
t	dt|
�z�|j
||
d�}t	d|
d|fz�||
dfS)a�
	Obtain a best-effort PPD match for an IEEE 1284 Device ID.
	The status is one of:

	  - L{STATUS_SUCCESS}: the match was successful, and an exact
            match was found

	  - L{STATUS_MODEL_MISMATCH}: a similar match was found, but
            the model name does not exactly match

	  - L{STATUS_GENERIC_DRIVER}: no match was found, but a
            generic driver is available that can drive this device
            according to its command set list

	  - L{STATUS_NO_DRIVER}: no match was found at all, and the
            returned PPD name is a last resort

	@param mfg: MFG or MANUFACTURER field
	@type mfg: string
	@param mdl: MDL or MODEL field
	@type mdl: string
	@param description: DES or DESCRIPTION field, optional
	@type description: string
	@param commandsets: CMD or COMMANDSET field, optional
	@type commandsets: string
	@param uri: device URI, optional (only needed for debugging)
	@type uri: string
        @param downloadedfiles: filenames from downloaded packages
        @type downloadedfiles: string list
        @param make_and_model: device-make-and-model string
        @type make_and_model: string
	@returns: an integer,string pair of (status,ppd-name)
	)�MFG�MDL�DESr�zFound PPDs: %srzUsing %s (status: %d))r'r�rqr�rr�r�)r�r�rrrrr�r�r�r�r��statuss            r]�getPPDNameFromDeviceIDzPPDs.getPPDNameFromDeviceID(s���L���K��"� �O��*�*�C��k�,7��,:�<���S�$�$�'���4�4�d�3�8�8�;�6G�6E�6D�6;�S�B��	�%��[�(9�9�:��&�&��K��N�(;�<���,��A���/G�G�H���A��'�'rnc��td�|j�}|jd�r
|dd}|dd}d}d}t|j	��}|D�cgc]}||j�f��}}|j||f�|j
tjd����|j||f�}	||	dz
g}
|	dzt|�kr;|
j||	dz�t|
ddd	z|zd	z|
ddz�nt|
ddd	z|z�|
D]l\}}tjj||g�}
t|
�|kDs�6t||j	��}t|
�}td
||fz��n|rA|t|�dzkDr0|}|t|�k(r|j}||fS|j}||fS|j }d}|j
tjt"j$���|D�cgc]}|j�||f��}}d}|j'd�D]>}|�|}d
}t)t|��D]}	||	j+�s�d}n|s�<|}nd}d}d}t)t|��D]+}	||	j+�r|dk(r|	}|	}|dz
}�%|dk7s�+n|dz
}d}|dkDr�t-|||�}|d|dz||dz}td|||fz�d}d}d
}||kr�t/d|�}|||z|zz}td|||fz�|D]O\}}|j'd�D]}|j�|k(s�d}n|s�6t|j	��}n|rn|dz
}|dkrn||kr��|r|}|j}||fScc}wcc}w)z|
        Find the best-matching PPDs based on the MDL Device ID.
        This function could be made a lot smarter.
        zTrying best matchz seriesNi����rc�:�tj|d|d�S)Nr)r�r�r�s  r]r�z)PPDs._findBestMatchPPDs.<locals>.<lambda>|s��d�n�n�Q�q�T�ST�UV�SW�>X�rnr�rz <= z%s: match length %dr_r&FTr#z%dz'Searching for model ID '%s', '%s' %% %d�
z#Ignoring %d of %d digits, trying %s)rr4r?rqr�r�r�r�r��indexrIr�r��commonprefixr��	FIT_CLOSEr�r�r�r;r`rb�int�pow)r�r
rr�best_mdl�
best_matchlen�mdlnamesrr�	mdlnameslrl�
candidates�	candidate�
candidatelrr�r��mdlitems�modelid�word�have_digits�digits�digits_start�
digits_end�modelnumber�modelpattern�
ignore_digitsr �divr[r�s                              r]r�zPPDs._findBestMatchPPDsisz��	�(�)��y�y�|���=�=�)�$����9�D��c�r�(�C����
���	�	��%��.6�6��a�����^�6�	�6����3��+�&����I�0�0�1X�Y��Z��O�O�c�4�[�)����A��&�'�
��q�5�3�	�?�"����y��Q��/�0���A��q�)�F�2�S�8�6�A�"�1�
�a�(�)�
*�
��A��q�)�F�2�S�8�9�(2�	Q�#�Y�
��W�W�)�)�J��+=�>�F��F�|�m�+���Y�� 4� 4� 7�8�� #�V��
��2�i��5O�O�P�	Q��
��d��a��8�"�K���T�
�*��n�n��Z�[�!�!�W�n�n��V�[�!�!�S�-�-�C��K�
�M�M�y�3�3�D�N�N�C�M�D�7?�@�!�����T�!�W�-�@�H�@��G��
�
�C�(�
���?�"�G�#����T�
�+��A��A�w���)�&*����
�"�G��
��F��L��J��C��M�*�
���1�:�%�%�(�#�r�)�'(��!"�J��a�K�F�!�R�'��
�
�!�O�J��K���z�!�7�<�
�#C�D�� '�
�� 6�� =� '�
�� 4�!5���F�%�|�[�A�B�C� !�
�����#�f�,��r�=�1�C�*�{�S�/@�C�.G�H�G��!F�"/���!A�"B�C�)1�"���t�$(�J�J��$4�&�D�#�z�z�}��7�(,�� %�&�
!�'+�D�I�I�L�'9�H�!�"���!�Q�&�M���z��+$�f�,�.�"*�K��.�.�C��[�!�!��M7��JAs�O�$Oc����|�g}	�j��jd���fd�}|D�cgc]}|j���}}d|vsd|vsd|vr|d�Sd|vsd	|vsd
|vsd|vr	|dd
�Sd|vr	|dd
�Sd|vr	|dd
�Sd|vsd|vr	|dd
�Sd|vr	|dd
�Sd|vsd|vsd|vr|d�Sy#t$rYywxYwcc}w)zfReturn ppd-name list or None, given a list of strings representing
        the command sets supported.Nr�c�d��|D]*}�j�|�\}}|�jk(s�(|cSyr�)r�r�)r:rPrr��modelsr�s    ��r]rAz+PPDs._getPPDNameFromCommandSet.<locals>.get�s>���#�
 �� �3�3�V�U�C�	��D�����&��K�
 �rnr��postscript2zpostscript level 2 emulation�
PostScript�pclxlzpcl-xl�pcl6zpcl 6 emulationzPCL 6/PCL XLz	PCL Laser�pcl5ezPCL 5e�pcl5czPCL 5c�pcl5zpcl 5 emulationzPCL 5�pclzPCL 3�escpl2zesc/p2�escp2ezESC/P Dot Matrix)r�r�r�r4)r�rrArr�cmdsetsrJs`    @r]r�zPPDs._getPPDNameFromCommandSet�s7������K�	������Z�Z�	�*�F�	�(3�3�!�1�7�7�:�3��3�
�W�
$�-�7�*B�
+�w�
6���%�%��'�!�x�7�':��� �&7�7�&B����4�4�
��
���+�.�.�
��
���+�.�.����%6�'�%A����-�-�
�g�
����-�-��7�"��G�(;��7�"��*�+�+���9�	��	��4s�C�C�	C�Cc	��|jrytj�}i}i}i}i}|jj�D�]%\}}t	|d�}t|�}	t
|	g�}
|jdg�}t|t�s|g}t
|D�cgc]}|jd�s�|��c}�}|r�t|�dk(r
t
�}t	|jdd��j�}
|
r|
dz
}
t|
�}|D]s}|jd�r"|jd�r|dt|�dz
}|s�9t|�}|j|�s|
|z}|
jt|���u|
D]_\}
}t|
�}t|�}||vr|
||<i||<i||
<n||}
|||vr||||<i||
|<n|||}|||
||<�a|	|
vr|
j!|	�|
s���|	\}
}|
|vr||
j|t
��}ni||
<t
�}|j#|
D�cgc]}|d��	c}�}|||
|<��(|j�D]�\}
}t|
�}||}|j�D]j\}}||jt|��}|s�&|||}|D]8}||jt|��}|||}|j%|��:�l��||_||_||_t+d	tj�|z
z�ycc}wcc}w)
Nr�zppd-product�(rzppd-makerr&�)zinit_makes: %.3fs)r��timer�rHrsr	r�rArprqr>rI�rstriprmr?r�r��union�updater�r�r)r��tstartr�r�r��aliasesr�r�rJ�ppd_mm_split�ppd_makes_and_models�ppd_productsrrrK�lmake�ppd_product�lprodrP�lmodelrJ�	main_make�
modelnames�
main_model�	main_ppds�	eachmodel�
this_modelr�s                           r]r�zPPDs._init_makes
s����:�:��������������� $�	�	��� 2�L	.��G�W�!+�W�5I�-J�!K��,�.@�A�L�#&��~�#6� �#�;�;�
�r�:�L��|�T�2� ,�~���L� O�q�A�L�L�#�<N�� O�P�L����%��*�#&�5�L�!�7�;�;�
�B�#?�@�G�G�J����C�K�D�!�4�(��#/�O�K�#�.�.��4�#�,�,�c�2�&1�!�C��4E��4I�&J��&� �&�{�3�E� �+�+�U�3�&*�[�&8��(�,�,�.?��.M�N�O�" 4�
6���e�!�4�(��"�E�*����&�$(�F�5�M�%'�G�E�N�"$�E�$�K�!�%�=�D�����/�-2�G�E�N�6�*�)+�E�$�K��&�#�E�N�6�2�E�.5��d��E�"�7�+�!
6�&�3�3�$�+�+�\�:�#� ,�
��u��7�?�$�T�]�.�.��s�u�=�F�$&�G�D�M� �U�F����6J�'K���!��'K�L��'-���
�e�$�YL	.�`$�M�M�,�
	,�L�D�&��t�$�E��u�
�I�%+�\�\�_�

,�!��z�$�U�^�/�/��E�1B�C�
�!��!�)�,�Z�8�	�!+�,�I�!(���!3�!3�Y�	�5J�!K�J� ��+�J�7�D��K�K��+�,�

,�
	,���
��������(�D�I�I�L�6�,A�B�C��c!P��t(Ls�M
�5M
�M
c��|jryi}|jj�D]�\}}t|j	d��}|s�#t|�}|dj
�}|dj
�}d}t|�dk(rd}t|�dk(rd}|r�y||vri||<|||vrg|||<|||j|���||_y)Nr�r)r*FrT)	r�r�rHrsrArr4rIr�)	r�r�r�r�r&�id_dict�lmfg�lmdl�bads	         r]r�zPPDs._init_idsws����8�8���� $�	�	��� 2�	-��G�W��W�[�[�/�:�;�B���#�R�(�G��5�>�'�'�*�D��5�>�'�'�*�D��C��D�z�Q�����D�z�Q�������3����D�	��3�t�9�$�"$��D�	�$����I�d�O�"�"�G�,�/	-�2��rn)NN)NNNNN)rNNN)rNNNNr�)�__name__�
__module__�__qualname__�__doc__�STATUS_SUCCESS�STATUS_MODEL_MISMATCH�STATUS_GENERIC_DRIVER�STATUS_NO_DRIVERrr�r�r�r3r�r�r�r�r�r�r�r�r�r�r'r-r�r�r�r�r�rnr]r
r
5s����N�������"�-�-�;�;�M��)�)�3�3�I��)�)�3�3�I� �+�+�7�7�K��(�(�1�1�H�$�n� �.� �"7�"�$9��!1�	4�N�IP�V� �$�"�Q�6:�37�26�37�D�L>@�7;�04�K�Z=?�6:�04�/3�?(�Bw"�r&�PkD�Zrnc��td�y)NzBusage: ppds.py [--deviceid] [--list-models] [--list-ids] [--debug])r�r�rnr]�
_show_helprz�s��	�O�Prn)"r�ryrrr�	itertoolsr�rYr��os.pathr�r�r<rrr�__all__�compiler5r@rNrOr4rGr7rBrD�IrEr	rmrsr
rzr�rnr]�<module>r�s!��.�&���
��
���	�,������

�:�2�:�:�"�#�$�
�j�b�j�j�*�+�,��j�b�j�j�(�)�*�
�j�b�j�j� �!�"��
��
�
�<�(�)��j�b�j�j�'�(�)�
�
��
�
�7�8�9��z�r�z�z�#-�.�/��
��
�
�'�(�)�
�j�b�j�j��"�#�
�J�B�J�J�|�$�%�
�J�B�J�J�*�+�,�S*�
�X�� �,�K�C��(+���	�	��%�,��
�
� ��
�
������\�*�� �b�j�j�"F�G���B�J�J�!.�"��&�B�J�J� 5�r�t�t�<��B�H1�f
�`
�`
�DQrn

Zerion Mini Shell 1.0