+
    QDb  c                   s~   ^ RI t ^RIHt ^RIHt ^ RIt^ RIt^ RIt^ RIt^ RI	t
^ RIt^ RIt^RIHtHt ^ RIHt RR.tR]P"                  ! R	4      3R
]P"                  ! R4      3R]P"                  ! R4      3R]P"                  ! R4      3R]P"                  ! R4      3R]P"                  ! R4      3R]P"                  ! R4      3R]P"                  ! R4      3R]P"                  ! R4      3R]P"                  ! R4      3R]P"                  ! R4      3R]P"                  ! R4      3.t/ t] F  w  tt]]]P-                  4       &   K  	  R R!R"R#R$R%R&R'R(R)R*R+/t]P"                  ! R,4      t]P"                  ! R-4      t]P"                  ! R.4      t]P"                  ! R/]P6                  4      tR0 tR1 tR2 t ! R3 R4      t R4 t!R# )5i    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|edgelineZEpsonzstylus|aculaserZApplez.stylewriter|imagewriter|deskwriter|laserwriterZCanonz%pixus|pixma|selphy|imagerunner|bj|lbpZBrotherz
hl|dcp|mfcZXeroxz/docuprint|docupage|phaser|workcentre|homecentreLexmarkzoptra|(:color )?jetprinterKONICA MINOLTAzmagicolor|pageworks|pageproKyocerazfs-|km-|taskalfaZRicohZaficioZOceZ
varioprintZOkizokipage|microlineZdjZDeskJetZljZLaserJetZojZ	OfficeJetzcolor ljzColor LaserJetzps 
PhotoSmartzhp  Z
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                s&   V P                  4        RpRpV P                  4       p\         F"  w  rEVP                  V4      '       g   K  TpT p M	  VEf   \        P                  V4      '       d   V P                  R4      pVR%8w  d)   V P                  R4      pWx8w  d   W^,           V p MV RV p  V P                  R^4      w  r\        P                  ! RRT4      p\        P                  ! RRT4      p\        P                  ! RRT4      p\        P                  ! RRT4      p\        P                  ! R	R
T4      p\        P                  ! RRT4      pRpMVP                  R4      '       d   RpV R,          pMVP                  R4      '       d   RpV R,          pMVP                  R4      '       d   RpV R,          pM]VP                  R4      '       d   RpV R,          pM:VP                  R4      '       d   RpV R,          pMRp V P                  R^4      w  rVP                  4       p	V'       d   V	P                  R4      '       d   V	P                  R4      '       d   RpRp	MRV	P                  R 4      '       d   V	P                  R!4      '       d   RpR"p	M\        P                  V	4      pV'       d   TpVP                  4       p
V
P                  R#4      pVR%8w  d8   \        P                  V
4      pV'       d   VP!                  4       pV
RV p
VRV p\"        P                  V
4      pV'       d   VP!                  4       pV
RV p
VRV p\$        P'                  RV^R$7      w  ppV'       d   VP                  4       p
V	R8X  d]   \(        P+                  4        FD  w  ppV
P                  V4      '       g   K  VV\-        V4      R ,           pVP                  4       p
 M	  VP                  4       pW3#    T pRp EL>; i   T pRp EL; i)&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   z(?<=[a-z])(?=[0-9]) z(?<=[a-z])(?=[A-Z])z JetZJetzPhoto Smartr   Tzkonica minolta r	   :i   NNzlexmark international r   :i   NNzkyocera mita r
   :i   NNzkyocera :i   NNzfuji xerox z
Fuji Xerox:i   NNZhewlettZpackardr   hpZkonicaZminoltazkonica minoltaz v)Zcount)striplower_MFR_BY_RANGEZmatch_RE_turboprintZsearchfindZrfindsplitresub
startswithendswith_MFR_NAMES_BY_LOWERget_RE_version_numbersZstart_RE_ignore_suffix_RE_ignore_seriesZsubn_HP_MODEL_BY_NAMEitemslen)ppd_make_and_modelmakeZcleanup_makeZlmfrregexpmodelZtZt2ZmakelZmodellZvZvmatchZvstartZsuffixZsuffixstartZnnameZfullnames   &                  5/usr/lib/python3.14/site-packages/cupshelpers/ppds.pyr   r   w   s    DL  #A$<<D&E	 % |--q11##]37#))=9Bw%7Br%B"%7%;"	,223:KD vv-sD9vv-sD9.U;.U;.e< 
(	)	)"3'	
/	0	0"3'	
	'	'"3'	
z	"	""2&	
}	%	%"3' 	,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8ND(  $'' 5d#55	 9 KKNE=C	%DE>	%DEs   2O; P ;PPc                s   V P                  4       P                  4       pRp^ p^p^pTpRp\        \        V4      4       F  pW,          P	                  4       '       d   Wd8w  d   V'       d
   VR,          pTpM8W,          P                  4       '       d   We8w  d   V'       d
   VR,          pTpMTpW,          P                  4       '       g   K  W!V,          ,          pRpK  	  V# )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   Fr   T)r   r   ranger"   ZisalphaisdigitZisalnum)	ZstrinZlstrinZ
normalizedZBLANKZALPHAZDIGITZlastcharZ
alnumfoundi	   &        r)   	normalizer.      s    0 [[^!!$FJ
E
E
EHJCL!9 Zc!
HY!! Zc!
HH9)#JJ "      c                sD    \        V \        4      '       d
   V ^ ,          # V # )zwIf we don't know whether getPPDs() or getPPDs2() was used, this
function can unwrap an item from a list in either case.)
isinstancelist)xs   &r)   
_singletonr3   .  s     1dtHr/   c            
       s  a  ] tR tRt o Rt^ t^t^t^t]	P                  P                  t]	P                  P                  t]	P                  P                  t]	P                  P                  t]	P                  P                  t]]]]]]]]]]/tRR ltR tR tR tR tR	 tRR
 ltRR ltRR ltR tRR ltR tR tRtV tR# )r   i5  aD  
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.
Nc                s
   VP                  4       V n        RV n        RV n        \        P
                  ! 4       V n        \        P                  ! 4       V n        VfT   \        P                  P                  R4      pVf1   ^RIHp \        P                  P                  VP                   R4      p \        P                  P                  VR4      p\        P"                  ! V4      w  rgV P                  P%                  V4       V P                  P%                  V4       Ve   VR8X  g   VR	8X  d   R
pVP+                  R4      p	V	R8w  d   VRV	 p
MTp
. pV P                  P-                  4        FB  w  r \/        VR,          4      pTR8X  d   K!  Y8X  d   K)  Y8X  d   K1  TP3                  T4       KD  	  V F  pV P                  V K  	  RV P                  9   d\   \/        V P                  R,          R,          4      pVP5                  R4      '       g    RV,           V P                  R,          R&   R# R# R#   \&         d-   p\)        RX: RT: 24       RT n        RT n         Rp?ELLRp?ii ; i  \0         d     EK  i ; i)z
@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()
NZCUPSHELPERS_XMLDIR)configcupshelperszpreferreddrivers.xmlzError loading : ZCZPOSIXZen_USr   zppd-natural-languageZenZrawppd-make-and-modelzGeneric r   )Zcopyppdsmakesidsr   ZDriverTypesdrivertypesZPreferenceOrder	preforderosZenvironr   r   r4   pathZjoinZ
sysconfdirZPreferredDriversZloadZ	Exceptionprintr   r!   r3   KeyErrorappendr   )selfr8   ZlanguageZxml_dirr4   Zxmlfiler;   ZpreferenceorderZeZuZshort_languageZ	to_removeppdnameppddictZnatural_languageZ	makemodels   &&&&            r)   __init__ZPPDs.__init__P  s)    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G#-w7M/N#O   4' +1g&# !3& !G		'" ! DII"DIIe$45I$JKI''449Ci9O		% !56 5 U  	"GQ78#D!DNN	"(  s+   0A.H8 4I28I/!I**I/2JJc                s   V P                  4        \        V P                  P                  4       4      pVP	                  \
        P                  R7        VP                  R4       VP                  ^ R4       V#   \         d     T# i ; i)zX
@returns: a list of strings representing makes, sorted according
to the current locale
ZkeyGeneric)
_init_makesr1   r9   keyssortlocaleZstrxfrmremoveZinsertZ
ValueError)rB   Z
makes_lists   & r)   getMakesZPPDs.getMakes  s|    
 	$**//,-
V^^,	y)q),   		s   #A: :B	B	c                s    V P                  4         \        V P                  V,          P                  4       4      pR pTP                  \        P                  ! T4      R7       T#   \         d    . u # i ; i)zP
@returns: a list of strings representing models, sorted using
cups.modelSort()
c                 sZ    \        V 4      p\        V4      p\        P                  ! W#4      # N)r.   cups	modelSort)ZaZbZfirstZsecond   &&  r)   compare_modelsZ&PPDs.getModels.<locals>.compare_models  s#    qME]F>>%00r/   rF   )rH   r1   r9   rI   r@   rJ   	functools
cmp_to_key)rB   r$   Zmodels_listrR   rQ   r)   	getModelsZPPDs.getModels  sp    
 		tzz$/4478K	1 	Y11.AB  	I	s   *A' 'A76A7c                s~    V P                  4         V P                  V,          V,          #   \         d    / u # i ; i)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)
)rH   r9   r@   )rB   r$   r'   s   &&&r)   getInfoFromModelZPPDs.getInfoFromModel  s=     		::d#E** 	I	s   , <<c                s(    V P                   V,          # )zJ
@returns: a dict representing a PPD, as given by
cups.Connection.getPPDs
)r8   )rB   rC      &&r)   getInfoFromPPDNameZPPDs.getInfoFromPPDName  s    
 yy!!r/   c                sj    V P                   P                  V\        P                  P                  4      # rN   )_fit_to_statusr   r   
DriverTypeFIT_NONE)rB   fitrW   r)   getStatusFromFitZPPDs.getStatusFromFit  s'    ""&&^-F-F-O-OPPr/   c                s^   Vf   . pVf   . pVf   / pV P                   '       d   V P                  '       d   / pV F  pV P                  V,          Wg&   K  	  V P                  P                  V P                   VV4      p\	        R\        V4      ,          4       V P                   P                  VWe4      p	\	        R\        V	4      ,          4       V	 U
u. uF  q^,          NK  	  pp
\	        R\        V4      ,          4       \        4       pV F(  pVP                  R4      w  rpVP                  V4       K*  	  V'       dg   . pV F1  pVP                  R4      w  rpVV9   g   K   VP                  V4       K3  	  V'       d&   V F  pVV9  g   K  VP                  V4       K  	  TpV# u up
i )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: %sz(Resulting PPD list in priority order: %sZ/)r;   r<   r8   Zget_ordered_typesr   ZreprZget_ordered_ppdnamessetZ
rpartitionaddrA   )rB   ppdnamelistdownloadedfilesmake_and_modeldevidr\   r8   rC   ZorderedtypesZorderedppdsZtyp_nameZdownloadedfnamesZdownloadedfiler>   ZslashZfnameZdownloadedppdnamesZppdfnames   &&&&&&            r)   orderPPDNamesByPreferenceZPPDs.orderPPDNamesByPreference  s   * K" O;CD& $		' 2 '  >>;;T=M=M=K=BDL SVZ[gVhhi**??AELKORVWbRccd7BC{8A;;{KCBT+EVVW 5-N#1#<#<c#B T%  %( . !#&*1*<*<c*B'h//&--w7 ' "*G&88*117;  + 15 Ds   F*c           	     s   \        RV: RV: 24       TpTpV P                  4        Vf   . p/ p	VP                  4       p
VP                  4       pRp V P                  V
,          V,           F  pV P                  W&   K  	  RpV
R8X  d|    V P                  R,          V,           F  pV P                  W&   K  	  \        RV P                  R,          V,          ,          4       \        R	V: R
V: R24       \        R4       Rp\        R4       RpV P                  4        RpV
R8X  d$   \        V4      w  r\        V4      p
\        V4      p\        RV
,          4       \        RV,          4       RRRRRR/pWP                  9   d   V P                  V
,          pMJV
V9   dD   VV
,          pVV P                  9   d*   TpTp
\        RV
,          4       V P                  V
,          p\        RV,          4       VEe   V P                  V,          pV P                  \        V4      ,          pV
RR3 FU  pVP                  VR,           4      '       g   K#  V\        V4      ^,           R p\        V4      p\        RV,          4       KW  	  WP                  V
,          9   dO   VV,          pVV,          P                  4        F)  pV P                  W&   \        W,          : RV: 24       K+  	  M\        VR,           V,           4      w  pp\        V4      p\        RV,          4       VV P                  V
,          9   dW   VV,          p\        VV,          P                  4       4       F)  pV P                  W&   \        W,          : RV: 24       K+  	  V	'       gS   V'       dK   V P!                  W4      w  ppVV P"                  8w  d&   V F  pVW&   \        W,          : RV: 24       K!  	  V'       d{   \%        V4      \        8w  d   VP'                  R4      p\        R4       V P)                  V4      pV'       d2   V F+  pV P*                  V	V&   \        V	V,          : RV: 24       K-  	  V'       dM   VP                  R4      '       g   VP                  R4      '       g   VP                  R4      '       d   RV9   g   \-        4       pV	P                  4        F-  pVP                  R 4      '       g   K  VP/                  V4       K/  	  \        V4      ^ 8  d   \        R!V,          4       V F  pW K  	  \-        4       pV'       Ed   \        V4      ^ 8  Ed   \-        4       p\-        4       pV	P                  4        F  pRpV P0                  V,          p \3        V P5                  R"4      4      p!V!'       d   \7        V!4      p"V"R#,          pV'       g;   VP9                  R$4      R;8X  d%   \3        V P5                  R%4      4      p#V#R&8X  d   R'.pV'       g   K  Rp$V F  p%V%V9   g   K  Rp$ M	  V$'       d   VP/                  V4       K  VP/                  V4       K  	  V FM  pW,          V P                  8X  g   K  V P:                  W&   \        V P:                  R(V,          ,           4       KO  	  \        V4      \        V	P=                  4        U&U'u. uF  w  p&p'V'R)8w  g   K  V&NK  	  up'p&4      8  d   \        R*V,          4       V F  pW K  	  M\        R+V,          R,,           4       V	'       g   R-R..p(Rp)V( F  p*\        R/V*,          4       V*R0,           p+V P0                  P                  4        FD  p,V,P?                  V*4      '       g   V,P?                  V+4      '       g   K3  V P"                  V	V,&   Rp) M	  V)'       d    M\        R1V*,          4       K  	  V)'       gC   \        R24       V P"                  V	\        V P0                  P                  4       4      ^ ,          &   V'       g   \@        PB                  ! R3R4\E        V4      R57      p- \G        R6 V4      p.R7V: R
V: R2p/V.'       d   V/R8V.,          ,          p/V'       d   V/R9V,          ,          p/\        R:V-,          4       \        V/4       V	#   \
         d     ELNi ; i  \
         d     ELi ; iu up'p&i   \H         d    Rp. Li ; i)<a  
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
Z
r   NFTzhewlett-packardr   z&**** Incorrect IEEE 1284 Device ID: %sz**** Actual ID is MFG:z;MDL:Z;z4**** Please report a bug against the HPLIP componentzTrying make/model namesr   zmfgl: %szmdll: %szlexmark internationalZlexmarkZkyocerazkyocera mitazremapped mfgl: %szmake: %szunprefixed mdll: %sr6   zre-split mdll: %s,zChecking CMD fieldzipp:zipps:Zdnssdz._ippzdriverless:z$Removed %s due to non-IPP connectionppd-device-idCMDZ:zppd-type
postscriptZ
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//)ZpatternZreplstringc                 s"    V R ,           V,           # )re    r2   ZyrW   r)   <lambda>Z.PPDs.getPPDNamesFromDeviceID.<locals>.<lambda>  s    1s7A:r/   zMFG:zCMD:%s;zDES:%s;zNo ID match for device %s:r   )%r   	_init_idsr   r:   	FIT_EXACTr@   rH   r   r.   lmakesr9   lmodelsr   r"   rI   r1   _findBestMatchPPDsr[   Ztyper   _getPPDNameFromCommandSetFIT_GENERICr^   r_   r8   r3   r   r    r   FIT_EXACT_CMDr!   r   r   r   strr   Z	TypeError)0rB   mfgmdldescriptioncommandsetsurirb   Zorig_mfgZorig_mdlr\   ZmfglmdllZ
id_matchedZeachmdlsr$   ZmfgreplZrmfgZmdlslprefixr'   Zmfg2Zmdl2Zmdl2lsr8   ri   ZdriverZfailedrC   Z	exact_cmdZppd_cmd_fieldZppdZppd_device_idZppd_device_id_dictZppd_typeZusableZpdlZdZmZ	fallbacksfoundZfallbackZ
fallbackgzZppdpathZsanitised_uriZcmdids0   &&&&&&&                                         r)   getPPDNamesFromDeviceIDZPPDs.getPPDNamesFromDeviceID  s   ( 	#s+,K 
 yy|yy|
	t,, NN	 -J
 $$	 HHTN400D $CI 1E!XXd^D12 33LMST!

 	./2:*C0JSc?Dc?DZ$&'Z$&'$d*In. ;;;;t$DW_4=Dt{{"0478{{4(Z$&'::d#DLL41E  !2D9??FSL11c6lQ./0C$c?D!6!=>	 : ||D))d K,,/D $CISYY!=> 0  1#)c/Bt!4(0589DLL..!%LE $T%[%5%5%8 9$(NN	#D%AB !: t//;IQDMM! D !CISYY!=> ! [!T))//5-.44kBG%F"&"2"2CKS[[&!AB & ''((..))S.UF88;&&}55JJ( ' FaCfLM"D	 #UF0 :#{+a/UFI88; $ii( *CGG_,E F )6)F&$6u$=M%
 LL#&",  *377J+?@H</)5$ (Ck)!% )
 MM7+JJ(E 'L "9. $ 2 2CI!3!3ftm!CD "
 F|cCIIL $7L&1a'(I~ %&AL $7 8 8>GH"D	 # /&822 3 ')9:IE%_x78%-
#yy~~0G(((33((*55'+}}G $  1 :XEF & BC26--D*+A./FFLt+.96M5{C &.x8Bi#o%i+--5EF
A  		  F$7J  sC   1c A:c c(/c(c. ccc%$c%.c>=c>c                sh   Vf   . pVf   . pV P                  WVWEV4      pRVRVRVRV/p	V P                  \        VP                  4       4      VVW4      p
\	        R\        V
4      ,          4       V P                  W^ ,          ,          4      p\	        RV
^ ,          V3,          4       W^ ,          3# )aJ  
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MDLZDESrg   zFound PPDs: %szUsing %s (status: %d))r   rd   r1   rI   r   rv   r]   )rB   rw   rx   ry   rz   r{   ra   rb   r\   rc   r`   Zstatuss   &&&&&&&&    r)   getPPDNameFromDeviceIDZPPDs.getPPDNameFromDeviceID(  s    L K" O**Ck,7,:< eS' 44d388;6G6E6D6;B 	%[(99:&&N(;<,A/GGHA''r/   c                s<	   \        R4       VP                  4       pVP                  R4      '       d   VRR pVRR pRp^ p\        VP	                  4       4      pV Uu. uF  qwVP                  4       3NK  	  ppVP                  W#34       VP                  \        P                  ! R 4      R7       VP                  W#34      p	W^,
          ,          .p
V	^,           \        V4      8  dc   V
P                  W^,           ,          4       \        V
^ ,          ^ ,          R,           V,           R,           V
^,          ^ ,          ,           4       M'\        V
^ ,          ^ ,          R,           V,           4       V
 Ft  w  r\        P                  P                  W.4      p\        V4      V8  g   K7  \        W,          P	                  4       4      p\        V4      p\        RW3,          4       Kv  	  V'       dI   V\        V4      ^,          8  d2   TpV\        V4      8X  d   V P                  pW3# V P                  p W3# V P                   pRpVP                  \        P                  ! \"        P$                  4      R7       V Uu. uF  qwP                  4       W,          3NK  	  ppRpVP'                  R4       FS  pVf   TpR	p\)        \        V4      4       F$  p	VV	,          P+                  4       '       g   K"  R
p M	  V'       g   KQ  Tp M	  ^ pRpRp\)        \        V4      4       F?  p	VV	,          P+                  4       '       d   VR8X  d   T	pT	pV^,          pK6  VR8w  g   K?   M	  V^,          p^ pV^ 8  Ed   \-        VVV 4      pVRV R,           VVR ,           p\        RVVV3,          4       ^ pRpR	pVV8  d   \/        ^
V4      pVVV,          V,          ,          p\        RVVV3,          4       V FZ  w  ppVP'                  R4       F  pVP                  4       V8X  g   K  R
p M	  V'       g   KA  \        VP	                  4       4      p M	  V'       d   MV^,          pV^8  g   K   V'       d   TpV P                  pW3# u upi u upi )zd
Find the best-matching PPDs based on the MDL Device ID.
This function could be made a lot smarter.
zTrying best matchz seriesNc                 sL    \         P                  ! V ^,          V^,          4      # )i   )rO   rP   rl   rW   r)   rm   Z)PPDs._findBestMatchPPDs.<locals>.<lambda>|  s    dnnQqTSTUVSW>Xr/   rF   z <= z%s: match length %dr   FTz%dz'Searching for model ID '%s', '%s' %% %dz#Ignoring %d of %d digits, trying %sir   )r   r   r   r1   rI   rA   rJ   rS   rT   Zindexr"   r=   r>   Zcommonprefixro   	FIT_CLOSEr[   rO   rP   r   r*   r+   ZintZpow)rB   r}   rx   r|   Zbest_mdlZbest_matchlenZmdlnamesr2   Z	mdlnameslr,   
candidatesZ	candidateZ
candidatelr~   r`   r\   ZmdlitemsZmodelidZwordZhave_digitsZdigitsZdigits_startZ
digits_endZmodelnumberZmodelpatternZignore_digitsr   Zdivr(   r8   s   &&&                           r)   rr   ZPPDs._findBestMatchPPDsi  sA    	()yy|==)$$9Dcr(C		% .66X^X	63+&I001XYZOOc[)A&'
q53	?"yQ/0Aq)F2S86A"1a() * Aq)F2S89 (2#YWW))J+=>FF|m+ 4 4 78 #V2i5OOP (2 da8"KT
*nnZ !!W nnV !!S --CK MMy33DNNCMD7?@x!TW-xH@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$4D#zz}7(, % %5
 !5'+DIIL'9H! )1 !Q&Mz"*K..C!!M 7J As   R Rc                s"  a a Vf   . p S P                  4        S P                  R,          oTT 3R lpT Uu. uF  q3P                  4       NK  	  ppRT9   g   RT9   g   RT9   d	   T! R4      # RT9   g   R	T9   g   R
T9   g   RT9   d
   T! RR4      # RT9   d
   T! RR4      # RT9   d
   T! RR4      # RT9   g   RT9   d
   T! RR4      # RT9   d
   T! RR4      # RT9   g   RT9   g   RT9   d	   T! R4      # R#   \         d     R# i ; iu upi )z^Return ppd-name list or None, given a list of strings representing
the command sets supported.NrG   c                  sl   < V  F,  pSP                  SV4      w  r#VSP                  8X  g   K*  Vu # 	  R # rN   )rr   ro   )r   r'   r   r8   modelsrB   s   *   r)   r   Z+PPDs._getPPDNameFromCommandSet.<locals>.get  s7    # 33VUC	&K $ r/   rh   Zpostscript2zpostscript level 2 emulationZ
PostScriptZpclxlzpcl-xlZpcl6zpcl 6 emulationzPCL 6/PCL XLz	PCL LaserZpcl5ezPCL 5eZpcl5czPCL 5cZpcl5zpcl 5 emulationzPCL 5ZpclzPCL 3Zescpl2zesc/p2Zescp2ezESC/P Dot Matrix)rH   r9   r@   r   )rB   rz   r   r2   Zcmdsetsr   s   f&   @r)   rs   ZPPDs._getPPDNameFromCommandSet  s6    K	ZZ	*F	 (33{!77:{3W$-7*B+w6%%'!x7': &77&B44+..+..%6'%A--g--7"G(;7"*++9  		 4s   #C: D:D	D	c           	     s   V P                   '       d   R # \        P                  ! 4       p/ p/ p/ p/ pV P                  P                  4        EF  w  rg\	        VR,          4      p\        V4      p	\        V	.4      p
VP                  R. 4      p\        V\        4      '       g   V.p\        V Uu. uF  qP                  R4      '       g   K  VNK  	  up4      pV'       d   \        V4      ^8X  d   \        4       p\	        VP                  RR4      4      P                  4       pV'       d
   VR,          p\        V4      pV F  pVP                  R4      '       d-   VP                  R4      '       d   V^\        V4      ^,
           pV'       g   KP  \        V4      pVP                  V4      '       g	   W,           pV
P                  \        V4      4       K  	  V
 F|  w  pp\        V4      p\        V4      pW9  d   WV&   / WN&   / W-&   MW>,          pVWN,          9  d   VWN,          V&   / W-,          V&   MWN,          V,          pWrV,          V,          V&   K~  	  W9   d   V
P!                  V	4       V
'       g   EK2  V	w  ppW9   d"   W],          P                  V\        4       4      pM/ W]&   \        4       pTP#                  V
 Uu. uF  q^,          NK  	  up4      pVW],          V&   EK  	  VP                  4        F  w  pp\        V4      pW>,          pVP                  4        F  w  ppWN,          P                  \        V4      4      pV'       g   K0  VV,          V,          pV FD  pWN,          P                  \        V4      4      pVV,          V,          pVP%                  V4       KF  	  K  	  K  	  W n         W0n        W@n        \+        R\        P                  ! 4       V,
          ,          4       R # u upi u upi )	Nr7   zppd-productZ(zppd-maker   r   Z)zinit_makes: %.3fs)r9   timer8   r!   r3   r   r^   r   r0   r1   r   r"   Zrstripr.   r   r_   rL   ZunionZupdaterp   rq   r   )rB   Ztstartr9   rp   rq   ZaliasesrC   rD   r#   Zppd_mm_splitZppd_makes_and_modelsZppd_productsr2   r$   ZlmakeZppd_productZlprodr'   Zlmodelr   Z	main_makeZ
modelnamesZ
main_modelZ	main_ppdsZ	eachmodelZ
this_modelr8   s   &                          r)   rH   ZPPDs._init_makes
  sh   ::: $		 2G!+W5I-J!K,.@AL#&~#6  #;;r:L|T22 ,~L OLqLL#<NL OPL %*#&5L!7;;
B#?@GGJCKD!4(#/K#..44#,,c22&1!C4E4I&J&  &{3E ++U33&*&8(,,.?.MN $0"  4e!4("E*&$(5M%'GN"$EK!=D/-2GN6*)+EK&#N62E.5dE"7+!  4& 3$++\:## ,u?$]..su=F$&GM UF6J'K6J!6J'KL'-e$Y !3` $MM,LD&t$EI%+\\_!z$^//E1BC
!!),Z8	!+I!(!3!3Y	5J!KJ +J7DKK+ ", &5 - 
(DIIL6,ABCc !Pt (Ls   /O:
O:
O?
c                s   V P                   '       d   R # / pV P                  P                  4        F  w  r#\        VP	                  R4      4      pV'       g   K)  \        V4      pVR,          P                  4       pVR,          P                  4       pRp\        V4      ^ 8X  d   Rp\        V4      ^ 8X  d   RpV'       d   K  Wa9  d   / W&   WqV,          9  d   . W,          V&   W,          V,          P                  V4       K  	  Wn         R # )Nrf   r   r   FT)	r:   r8   r!   r3   r   r    r   r"   rA   )	rB   r:   rC   rD   r   Zid_dictZlmfgZlmdlZbadr-   r)   rn   ZPPDs._init_idsw  s    888 $		 2GW[[/:;B#R(G5>''*D5>''*DCDzQDzQ	t9$"$	$IdO""G,/ !32 r/   )r;   r:   rp   rq   r9   r8   r<   )NN)NNNNN)r   NNN)r   NNNNrN   ) Z__name__Z
__module__Z__qualname__Z__firstlineno__Z__doc__ZSTATUS_SUCCESSZSTATUS_MODEL_MISMATCHZSTATUS_GENERIC_DRIVERZSTATUS_NO_DRIVERr   rZ   ru   ro   r   rt   r[   rY   rE   rM   rU   rV   rX   r]   rd   r   r   rr   rs   rH   rn   Z__static_attributes__Z__classdictcell__)Z__classdict__s   @r)   r   r   5  s      N"--;;M))33I))33I ++77K((11H$n . "7"$9!1	4NIPV $"QDLKZ?(Bw"r&PkDZ r/   c                  s    \        R 4       R# )zBusage: ppds.py [--deviceid] [--list-models] [--list-ids] [--debug]N)r?   rk   r/   r)   
_show_helpr     s    	OPr/   )"rO   r5   r    r   r   Z	itertoolsrj   r   rK   Zos.pathr=   rS   r   r   r   r   Z__all__Zcompiler   r   r%   r&   r   r    r   r   r   ZIr   r   r.   r3   r   r   rk   r/   r)   <module>r      s	  .  &        	 , 
 
2:: " # $ bjj*+,bjj ( ) * bjj   ! " 

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

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

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