
    QDb                     n   d dl Z ddlmZ ddlmZ d dlZd dlZd dlZd dlZd dl	Z
d dlZd dlZddlmZmZ d dlmZ ddgZd	 ej"                  d
      fd ej"                  d      fd ej"                  d      fd ej"                  d      fd ej"                  d      fd ej"                  d      fd ej"                  d      fd ej"                  d      fd ej"                  d      fd ej"                  d      fd ej"                  d      fd ej"                  d       fgZi ZeD ]  \  ZZeeej-                         <    d!d"d#d$d%d&d'Z ej"                  d(      Z ej"                  d)      Z ej"                  d*      Z ej"                  d+ej6                        Zd, Zd- Zd. Z G d/ 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Epsonzstylus|aculaserApplez.stylewriter|imagewriter|deskwriter|laserwriterCanonz%pixus|pixma|selphy|imagerunner|bj|lbpBrotherz
hl|dcp|mfcXeroxz/docuprint|docupage|phaser|workcentre|homecentreLexmarkzoptra|(:color )?jetprinterKONICA MINOLTAzmagicolor|pageworks|pageproKyocerazfs-|km-|taskalfaRicohaficioOce
varioprintOkizokipage|microlineDeskJetLaserJet	OfficeJetzColor LaserJet
PhotoSmart )djljojzcolor ljzps zhp 
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                         }t        D ]  \  }}|j                  |      s|}| } n |t        j                  |      r| j                  d      }|dk7  r$| j                  d      }||k7  r	| |dz   | } n| d| } 	 | j                  dd      \  }}t        j                  d	d
|      }t        j                  dd
|      }t        j                  d	d
|      }t        j                  dd
|      }t        j                  dd|      }t        j                  dd|      }d}n|j                  d      rd}| dd }n||j                  d      rd}| dd }nc|j                  d      rd}| dd }nJ|j                  d      rd}| dd }n1|j                  d      rd}| dd }nd}	 | j                  d
d      \  }}|j                         }	|rg|	j                  d      r|	j                  d       rd!}d"}	n@|	j                  d#      r|	j                  d$      rd}d%}	nt        j                  |	      }|r|}|j                         }
|
j                  d&      }|dk7  r1t        j                  |
      }|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-        |      d z   }|j                         }
 n |j                         }||fS #  | }d}Y xY w#  | }d}Y xY w)(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   _r   r   z(?<=[a-z])(?=[0-9]) z(?<=[a-z])(?=[A-Z])z JetJetzPhoto Smartr   Tzkonica minolta r      zlexmark international r      zkyocera mita r      zkyocera    zfuji xerox z
Fuji Xerox   hewlettpackardr   hpkonicaminoltazkonica 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	   w   s    DL  #A$ V<<D&E	 |--q1##]37#))=9BBw%7Br%B"%7%;"	,223:KD% vv-sD9vv-sD9.U;.U;.e< 
(	)"23'	
/	0"23'	
	'"23'	
z	""12&	
}	%"23' 	,223:KD% JJMEi(NNI&DE)nni(#D$E &))51C [[^FTABw %++V4\\_FGV_F'6NE%%v.Fllo%l{# #''U!'<JUA}/558 	ND(  $' 5d#55		 KKNE%=C	%DE>	%DEs   M* >M6 *M36M?c                 T   | j                         j                         }d}d}d}d}|}d}t        t        |            D ]f  }||   j	                         r||k7  r|r|dz  }|}n$||   j                         r||k7  r|r|dz  }|}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.
    r   r   r      Fr&   T)r3   r4   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AY!5 Zc!
HH!9&)#JJ      c                 0    t        | t              r| d   S | 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     1dtHrn   c            
          e Zd ZdZdZdZdZdZej                  j                  Z
ej                  j                  Zej                  j                  Zej                  j                  Zej                  j                  Ze
eeeeeeeeeiZddZd Zd	 Zd
 Zd Zd Z	 	 	 	 ddZ	 	 	 ddZ	 	 	 	 ddZd ZddZd Zd Zy)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.
    r   r   r_      Nc                    |j                         | _        d| _        d| _        t	        j
                         | _        t	        j                         | _        |Qt        j                  j                  d      }|0ddlm} t        j                  j                  |j                   d      }	 t        j                  j                  |d      }t	        j"                  |      \  }}| j                  j%                  |       | j                  j%                  |       |
|d	k(  s|d
k(  rd}|j+                  d      }	|	dk7  r|d|	 }
n|}
g }| j                  j-                         D ]7  \  }}	 t/        |d         }|dk(  r||k(  r!||
k(  r'|j3                  |       9 |D ]  }| j                  |=  d| j                  v rCt/        | j                  d   d         }|j5                  d      sd|z   | j                  d   d<   yyy# t&        $ r*}t)        dd|       d| _        d| _        Y d}~d}~ww xY w# t0        $ r Y w xY w)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cupshelperszpreferreddrivers.xmlzError loading : CPOSIXen_USr%   r#   zppd-natural-languageenrawppd-make-and-modelzGeneric )copyppdsmakesidsr   DriverTypesdrivertypesPreferenceOrder	preforderosenvironrA   r   rx   pathjoin
sysconfdirPreferredDriversload	Exceptionprintr9   rH   rs   KeyErrorappendr>   )selfr   languagexml_dirrx   xmlfiler   preferenceordereushort_language	to_removeppdnameppddictnatural_language	makemodels                   r]   __init__zPPDs.__init__P  s8    IIL	
)558'77:?jjnn&:;G$'',,(9(9=I		"ggllG-CDG//9 +[/!!;/NN1 OHMM37%bq\N%N	 $		 2 	'GW#-w7M/N#O   4' 8+>1g&#	'& ! 	#G		'"	# DII"DIIe$45I$JKI''49Ci9O		% !56 5 U  	"GQ78#D!DNN	"(  s+   *A.H  'H6 	H3	H..H36	IIc                    | j                          t        | j                  j                               }|j	                  t
        j                         	 |j                  d       |j                  dd       |S # t        $ r Y |S w xY w)zb
	@returns: a list of strings representing makes, sorted according
        to the current locale
	keyGenericr   )
_init_makesrq   r   keyssortlocalestrxfrmremoveinsert
ValueError)r   
makes_lists     r]   getMakeszPPDs.getMakes  s|    
 	$**//,-
V^^,	y)q),   		s   #A: :	BBc                     | j                          	 t        | j                  |   j                               }d }|j                  t        j                  |             |S # t        $ r g cY S w xY w)zS
	@returns: a list of strings representing models, sorted using
	cups.modelSort()
	c                 Z    t        |       }t        |      }t        j                  ||      S N)rm   cups	modelSort)abfirstseconds       r]   compare_modelsz&PPDs.getModels.<locals>.compare_models  s%    qME]F>>%00rn   r   )r   rq   r   r   r   r   	functools
cmp_to_key)r   rK   models_listr   s       r]   	getModelszPPDs.getModels  sp    
 		tzz$/4478K	1 	Y11.AB  	I	s   &A" "A0/A0c                 j    | j                          	 | j                  |   |   S # t        $ r i cY S w xY w)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   rK   rP   s      r]   getInfoFromModelzPPDs.getInfoFromModel  s=     		::d#E** 	I	s   $ 22c                      | j                   |   S )zM
	@returns: a dict representing a PPD, as given by
	cups.Connection.getPPDs
	)r   )r   r   s     r]   getInfoFromPPDNamezPPDs.getInfoFromPPDName  s    
 yy!!rn   c                 j    | j                   j                  |t        j                  j                        S r   )_fit_to_statusrA   r   
DriverTypeFIT_NONE)r   fits     r]   getStatusFromFitzPPDs.getStatusFromFit  s'    ""&&^-F-F-O-OPPrn   c                    |g }|g }|i }| j                   r| j                  ri }|D ]  }| j                  |   ||<    | j                  j                  | j                   ||      }t	        dt        |      z         | j                   j                  |||      }	t	        dt        |	      z         |	D 
cg c]  }
|
d   	 }}
t	        dt        |      z         t               }|D ](  }|j                  d      \  }}}|j                  |       * |rUg }|D ]-  }|j                  d      \  }}}||v s|j                  |       / |r|D ]  }||vs|j                  |        |}|S c c}
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: %sr   z(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]   orderPPDNamesByPreferencezPPDs.orderPPDNamesByPreference  s   * K" O;CD& 3 $		' 2W3  >>;;T=M=M=K=BDL SVZ[gVhhi**??AEsLKORVWbRccd7BC88A;CKCBT+EVVW 5- 	)N#1#<#<c#B T5%  %(	) !#& 8*1*<*<c*B'uh//&--w78 "* <G&88*117;< 15 Ds   6E+c           	         t        d|d|       |}|}| j                          |g }i }	|j                         }
|j                         }d}	 | j                  |
   |   D ]  }| j                  |	|<    d}|
dk(  rd	 | j                  d   |   D ]  }| j                  |	|<    t        d| j                  d   |   z         t        d	|d
|d       t        d       d}t        d       d}| j                          d}|
dk(  r$t        |      \  }}t        |      }
t        |      }t        d|
z         t        d|z         dddd}|
| j                  v r| j                  |
   }n8|
|v r4||
   }|| j                  v r!|}|}
t        d|
z         | j                  |
   }t        d|z         |G| j                  |   }| j                  t        |         }|
ddfD ]A  }|j                  |dz         s|t        |      dz   d }t        |      }t        d|z         C || j                  |
   v r@||   }||   j                         D ]$  }| j                  |	|<   t        |	|   d|       & nt        |dz   |z         \  }}t        |      }t        d|z         || j                  |
   v rH||   }t        ||   j                               D ]$  }| j                  |	|<   t        |	|   d|       & |	sE|rC| j!                  ||      \  }}|| j"                  k7  r|D ]  }||	|<   t        |	|   d|        |rjt%        |      t        k7  r|j'                  d      }t        d       | j)                  |      }|r)|D ]$  }| j*                  |	|<   t        |	|   d|       & |r7|j                  d      s|j                  d      s|j                  d      rd|vrrt-               }|	j                         D ]%  }|j                  d       s|j/                  |       ' t        |      d!kD  rt        d"|z         |D ]  }|	|=  t-               }|rt        |      d!kD  rt-               }t-               }|	j                         D ]  }d}| j0                  |   } t3        | j5                  d#            }!|!rt7        |!      }"|"d$   }|s6|j9                  d%      d&k(  r"t3        | j5                  d'            }#|#d(k(  rd)g}|s{d}$|D ]
  }%|%|v sd}$ n |$r|j/                  |       |j/                  |        |D ]?  }|	|   | j                  k(  s| j:                  |	|<   t        | j:                  d*|z  z          A t        |      t        |	j=                         D &'cg c]  \  }&}'|'d+k7  r|& c}'}&      k  rt        d,|z         |D ]  }|	|=  nt        d-|z  d.z          |	sd/d0g}(d})|(D ]{  }*t        d1|*z         |*d2z   }+| j0                  j                         D ]7  },|,j?                  |*      s|,j?                  |+      s&| j"                  |	|,<   d}) n |)r nt        d3|*z         } |)s>t        d4       | j"                  |	t        | j0                  j                               d!   <   |setA        jB                  d5d6tE        |      7      }-	 tG        d8 |      }.d9|d
|d}/|.r|/d:|.z  z  }/|r|/d;|z  z  }/t        d<|-z         t        |/       |	S # t
        $ r Y w xY w# t
        $ r Y Ww xY wc c}'}&w # tH        $ r d}.Y kw xY w)=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 componentzTrying make/model namesr   zmfgl: %szmdll: %slexmarkzkyocera mita)r   zlexmark internationalkyocerazremapped mfgl: %szmake: %sr   zunprefixed mdll: %srz   zre-split mdll: %s,zChecking CMD fieldzipp:zipps:dnssdz._ippzdriverless:r   z$Removed %s due to non-IPP connectionppd-device-idCMD:r#   zppd-type
postscript
POSTSCRIPTz: %sgenericzRemoved %s due to CMD mis-matchzNot removing %s z3due to CMD mis-match as it would leave nothing goodztextonly.ppdzpostscript.ppdz'%s' fallbackz.gzzFallback '%s' not availablez#No fallback available; choosing anyz
//[^@]*@/?z//)patternreplstringc                     | dz   |z   S )Nr    rr   ys     r]   <lambda>z.PPDs.getPPDNamesFromDeviceID.<locals>.<lambda>  s    1s7A: rn   zMFG:zCMD:%s;zDES:%s;zNo ID match for device %s:)%r   	_init_idsr4   r   	FIT_EXACTr   r   r	   rm   lmakesr   lmodelsr>   rI   r   rq   _findBestMatchPPDsr   typer;   _getPPDNameFromCommandSetFIT_GENERICr   r   r   rs   rA   r   r9   FIT_EXACT_CMDrH   r?   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]   getPPDNamesFromDeviceIDzPPDs.getPPDNamesFromDeviceID  s   ( 	#s+,K 
 yy|yy|
	t, + NND	+J
 $$	 HHTN40 /D $CI/E!XXd^D12 33LMST!

 	./2:*C0JS#c?Dc?DZ$&'Z$&'&*,5,. 4;;;;t$DW_4=Dt{{"0478{{4(Z$&'::d#DLL41E  !2D9 ???FSL1c6lQ./0C$c?D!6!=>	? t||D))d K,,/ ?D $CISY!=>?  1#)c/Bt!4(0589DLL..!%LE $T%[%5%5%8 9 C$(NND	#TD%ABC t//s;IQDMM!  ?D !CISY!=>? [!T))//5-.44kBG% CF"&"2"2CKS[&!ABC '(..)S.UF88; )&&}5JJ() FaCfLM" "DD	"UF0 #{+a/UFI88; ") $ii( *CGG_,E F )6)F&$6u$=M%
 LL#&",  *377J+?@H</)5$ ( Ck)!%
 MM7+JJ(E")L " Et9. $ 2 2CI!3!3ftm!CDE
 F|cCIIL $7&1a'(I~ %& $7 8 8>GH" "DD	" /&822 3 ')9:IE% G_x78%-
#yy~~0 G(((3((*5'+}}G $ :XEFG BC26--D*+A./FFLt+.96M5{C &.x8Bi#o%i+--5EF
A  		  F$7J  s=   (\ =A#\+ %\;] 	\('\(+	\87\8]]c                 4   |g }|g }| j                  ||||||      }||||d}	| j                  t        |j                               |||	|      }
t	        dt        |
      z         | j                  ||
d            }t	        d|
d   |fz         ||
d   fS )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   zFound PPDs: %sr   zUsing %s (status: %d))r'  r   rq   r   r   r   r   )r   r   r   r  r  r  r   r   r   r   r   statuss               r]   getPPDNameFromDeviceIDzPPDs.getPPDNameFromDeviceID(  s    L K" O**Ck,7,:< S$$' 44d388;6G6E6D6;SB 	%[(99:&&KN(;<,A/GGHA''rn   c                    t        d       |j                         }|j                  d      r
|dd }|dd }d}d}t        |j	                               }|D cg c]  }||j                         f }}|j                  ||f       |j                  t        j                  d              |j                  ||f      }	||	dz
     g}
|	dz   t        |      k  r;|
j                  ||	dz             t        |
d   d   d	z   |z   d	z   |
d   d   z          nt        |
d   d   d	z   |z          |
D ]l  \  }}t        j                  j                  ||g      }t        |      |kD  s6t        ||   j	                               }t        |      }t        d
||fz         n |rA|t        |      dz  kD  r0|}|t        |      k(  r| j                  }||fS | j                  }||fS | j                   }d}|j                  t        j                  t"        j$                               |D cg c]  }|j                         ||   f }}d}|j'                  d      D ]>  }||}d}t)        t        |            D ]  }	||	   j+                         sd} n |s<|} n d}d}d}t)        t        |            D ]+  }	||	   j+                         r|dk(  r|	}|	}|dz  }%|dk7  s+ n |dz  }d}|dkD  rt-        |||       }|d| dz   ||d z   }t        d|||fz         d}d}d}||k  rt/        d|      }|||z  |z  z  }t        d|||fz         |D ]O  \  }}|j'                  d      D ]  }|j                         |k(  sd} n |s6t        |j	                               } n |rn|dz  }|dk  rn||k  r|r|}| j                  }||fS c c}w c c}w )z|
        Find the best-matching PPDs based on the MDL Device ID.
        This function could be made a lot smarter.
        zTrying best matchz seriesNir   c                 :    t        j                  | d   |d         S )Nr   )r   r   r   s     r]   r   z)PPDs._findBestMatchPPDs.<locals>.<lambda>|  s    dnnQqTSTUVSW>X rn   r   r   z <= z%s: match length %dr_   r&   FTr#   z%dz'Searching for model ID '%s', '%s' %% %d
   z#Ignoring %d of %d digits, trying %s)r   r4   r?   rq   r   r   r   r   r   indexrI   r   r   commonprefixr   	FIT_CLOSEr   r   r   r;   r`   rb   intpow)r   r
  r   r  best_mdlbest_matchlenmdlnamesrr   	mdlnameslrl   
candidates	candidate
candidatelr  r   r   mdlitemsmodelidwordhave_digitsdigitsdigits_start
digits_endmodelnumbermodelpatternignore_digitsr   divr[   r   s                                 r]   r   zPPDs._findBestMatchPPDsi  sz    	()yy|==)$9Dcr(C		% .66a^6	63+&I001XYZOOc4[)A&'
q53	?"yQ/0Aq)F2S86A"1a() * Aq)F2S89 (2 	Q#Y
WW))J+=>FF|m+Y 4 4 78 #V2i5OOP	Q da8"KT
*nnZ [!!W nnV [!!S --CK MMy33DNNCMD7?@!T!W-@H@G

C( ?"G#T
+ AAw)&*
 "G FLJCM* 1:%%(#r)'(!"JaKF!R' !OJKz!7<
#CD ' 6 = '
 4!5F%|[AB C !#f,r=1C*{S/@C.GHG!F"/!A"B C )1 "t$(JJ$4 &D#zz}7(, %&
 !'+DIIL'9H!" !Q&Mz+ $f,. "*K..C[!!M 7J As   O$Oc                     |g }	  j                           j                  d    fd}|D cg c]  }|j                          }}d|v sd|v sd|v r |d      S d|v sd	|v sd
|v sd|v r	 |dd      S d|v r	 |dd      S d|v r	 |dd      S d|v sd|v r	 |dd      S d|v r	 |dd      S d|v sd|v sd|v r |d      S y# t        $ r Y yw xY wc c}w )zfReturn ppd-name list or None, given a list of strings representing
        the command sets supported.Nr   c                  d    | D ]*  }j                  |      \  }}|j                  k(  s(|c S  y r   )r   r   )r:  rP   r  r   modelsr   s       r]   rA   z+PPDs._getPPDNameFromCommandSet.<locals>.get  s>    #   33VUC	D&K  rn   r   postscript2zpostscript level 2 emulation
PostScriptpclxlzpcl-xlpcl6zpcl 6 emulationzPCL 6/PCL XLz	PCL Laserpcl5ezPCL 5epcl5czPCL 5cpcl5zpcl 5 emulationzPCL 5pclzPCL 3escpl2zesc/p2escp2ezESC/P Dot Matrix)r   r   r   r4   )r   r  rA   rr   cmdsetsrJ  s   `    @r]   r   zPPDs._getPPDNameFromCommandSet  s7    K	ZZ	*F	 (33!177:33W$-7*B+w6%%'!x7': &77&B44+..+..%6'%A--g--7"G(;7"*++9  		 4s   C C	CCc           	         | j                   ry t        j                         }i }i }i }i }| j                  j                         D ]%  \  }}t	        |d         }t        |      }	t        |	g      }
|j                  dg       }t        |t              s|g}t        |D cg c]  }|j                  d      s| c}      }|rt        |      dk(  r
t               }t	        |j                  dd            j                         }|r|dz  }t        |      }|D ]s  }|j                  d      r"|j                  d      r|dt        |      dz
   }|s9t        |      }|j                  |      s||z   }|
j                  t        |             u |
D ]_  \  }}t        |      }t        |      }||vr|||<   i ||<   i ||<   n||   }|||   vr|||   |<   i ||   |<   n||   |   }|||   |   |<   a |	|
v r|
j!                  |	       |
s|	\  }}||v r||   j                  |t                     }ni ||<   t               }|j#                  |
D cg c]  }|d   	 c}      }|||   |<   ( |j                         D ]  \  }}t        |      }||   }|j                         D ]j  \  }}||   j                  t        |            }|s&||   |   }|D ]8  }||   j                  t        |            }||   |   }|j%                  |       : l  || _         || _        || _        t+        d	t        j                         |z
  z         y c c}w c c}w )
Nr   zppd-product(r   zppd-maker   r&   )zinit_makes: %.3fs)r   timer   rH   rs   r	   r   rA   rp   rq   r>   rI   rstriprm   r?   r   r   unionupdater   r   r   )r   tstartr   r   r   aliasesr   r   rJ   ppd_mm_splitppd_makes_and_modelsppd_productsrr   rK   lmakeppd_productlprodrP   lmodelrJ  	main_make
modelnames
main_model	main_ppds	eachmodel
this_modelr   s                              r]   r   zPPDs._init_makes
  s   :: $		 2 L	.GW!+W5I-J!K,.@AL#&~#6  #;;r:L|T2 ,~L OqALL#<N OPL %*#&5L!7;;
B#?@GGJCKD!4(#/ OK#..4#,,c2&1!C4E4I&J&  &{3E ++U3&*[&8(,,.?.MNO"  4 6e!4("E*&$(F5M%'GEN"$E$K!%=D/-2GEN6*)+E$K&#EN62E.5dE"7+!6& 33$++\:# ,u7?$T]..su=F$&GDM UF6J'K!'KL'-e$YL	.` $MM, 	,LD&t$EuI%+\\_ 
,!z$U^//E1BC
!!),Z8	!+ ,I!(!3!3Y	5J!KJ +J7DKK+,
,	, 
(DIIL6,ABCc !Pt (Ls   M
5M
M
c                    | j                   ry i }| j                  j                         D ]  \  }}t        |j	                  d            }|s#t        |      }|d   j                         }|d   j                         }d}t        |      dk(  rd}t        |      dk(  rd}|ry||vri ||<   |||   vrg ||   |<   ||   |   j                  |        || _         y )Nr   r)  r*  Fr   T)	r   r   rH   rs   rA   r   r4   rI   r   )	r   r   r   r   r&  id_dictlmfglmdlbads	            r]   r   zPPDs._init_idsw  s    88 $		 2 	-GWW[[/:;B#R(G5>''*D5>''*DCDzQDzQ3D	3t9$"$D	$IdO""G,/	-2 rn   )NN)NNNNN)r   NNN)r   NNNNr   )__name__
__module____qualname____doc__STATUS_SUCCESSSTATUS_MODEL_MISMATCHSTATUS_GENERIC_DRIVERSTATUS_NO_DRIVERr   r   r   r   r3  r   r   r   r   r   r   r   r   r   r   r'  r-  r   r   r   r   r   rn   r]   r
   r
   5  s    N"--;;M))33I))33I ++77K((11H$n . "7"$9!1	4NIPV $"Q 6:372637DL >@7;04KZ =?6:04/3?(Bw"r&PkDZrn   c                      t        d       y )NzBusage: ppds.py [--deviceid] [--list-models] [--list-ids] [--debug])r   r   rn   r]   
_show_helprz    s    	OPrn   )"r   ry   r   r   r   	itertoolsr   rY  r   os.pathr   r   r<   r   r   r   __all__compiler5   r@   rN   rO   r4   rG   r7   rB   rD   IrE   r	   rm   rs   r
   rz  r   rn   r]   <module>r     s!  .  &        	 , 
 
:2:: " # $ jbjj*+,jbjj ( ) * jbjj   ! " 


<()jbjj ' ( )
 


789zrzz #- . / 


 ' ( ) jbjj"#
JBJJ|$%
JBJJ*+,S*X    ,KC(+		%, 

   \* bjj"FG BJJ !. " & BJJ 5rtt< BH1f` `DQrn   