+
    QDbF?  c                   sJ   ^ RI t ^ RI5 ^ RIt^ RIt^ RIt^ RIHt ^ RIHt ^ RIH	t	 ^ RI
t
^ RIt^ RIt^ RIHt ^ RIHt ^ RIt ^ RItRtR tR t ! R R4      t ! R R]P*                  4      t ! R R4      t]R8X  d   ^ RIt]! ]P6                  4      ^8  d   ]! R4       ]P:                  ! ^4       ]! R4       ]P>                  ! 4       t R t!]P6                  ^,          t"]! 4       t#]#PI                  ]"]!4       ] PK                  4        R# R#    R	t ! R
 R4      t L; i)    N)Z*)Gdk)Gtk)TimedOperation)GObject)GLibTFc                   s*    ] tR t^(t ! R R4      tRtR# )pysmbc                   s    ] tR t^)tRtR# )pysmb.AuthContext N)__name__
__module____qualname____firstlineno____static_attributes__r       1/usr/share/system-config-printer/probe_printer.pyAuthContextr   )   s    r   r   r   N)r	   r
   r   r   r   r   r   r   r   r   r   (   s    	 	r   r   c                 s   . pR pR pR pRp\        V 4      p\        V4       F  pW,          pV'       d   WX,          pR pK  VR8X  d   RpRpK,  V'       d`   V'       d   VR8X  d   R pKG  WX,          pKQ  VP                  4       '       d   VP                  V4       RpR pK~  VR8X  d   RpK  WX,          pK  VR8X  d   RpRpK  VP                  4       '       d   K  RpWX,          pK  	  VR8w  d   VP                  V4       V# )F Z\TZ")lenrangeZisspaceappend)	linewordsZescapedZquotedZin_wordZwordnZiZchs	   &        r   wordsepr   ,   s    EGFGDT
AAYWJDG:GG9"FJDd#s
SyZZ]]
A D rzdLr   c                 sL    V P                  R ^4      w  r!Rp \        P                  ! W!\        P                  \        P
                  4      pV FE  pVw  rgrp
 \        P                  ! WgV4      pVP                  R4        TP                  T
4        T# 	  V#   \         d    T p Li ; i  \        P                  \        P                  3 d    . p Li ; i  \        P                   d    Rp K  i ; i  \        P                   d    TP                  4        Rp K  i ; i):Ng      ?)splitZ
ValueErrorsocketgetaddrinfo	AF_UNSPECSOCK_STREAMgaierrorerrorZ
settimeoutZconnectclose)hostnameporthostsairesafsocktypeproto	canonnamesas   &&         r   open_socketr-   ]   s   ^^C+
 	AF,<,< & 2 24
 -0*e	bE2ALL	IIbM
 	H  H3   OOV\\*  || 	A	
 || 	GGIA	sF   B 4B- (CC8B*)B*-'CCC54C58'D#"D#c                   s>   a  ] tR t^{t o R tR tR tR tR tRt	V t
R# )	LpdServerc                s.    Wn         ^V n        RV n        R# )i   FNr"   max_lpt_comstop)selfr"      &&r   __init__ZLpdServer.__init__|   s     	r   c                s   \        V P                  R 4      pV'       g   R# \        V4        VP                  RV,          P	                  R4      4       VP                  R4      P                  R4      p\        \        V4      4       \        T4      ^ 8  dM   \        T^ ,          4      ^ 8X  d6    TP                  R4       TP                  4        TP                  T4       R#  TP                  4        R#   \        P                   d0   p\        T4        TP                  4        M    M; i Rp?R# Rp?ii ; i    Lq; i    R# ; i)i  Nz%s
zUTF-8i   Fs   
T)r-   r"   
debugprintZsendZencodeZrecvdecodereprr   r    r!   r   Zordr   )r2   nameresultr%   ZdataZmsgs   &&&   r   probe_queueZLpdServer.probe_queue   s	   s+4	FFHtO++G4566$<&&w/DtDz" t9Q;3tAw<?w
 MM$	GGI 1 || 	sO
		sH   AC7 0!D> %E 7D;D6D)(D6)D-+D66D;>EE
c                s    . ROp\        V P                  4       F4  pVP                  RV,          RV,          RV,          RV,          .4       K6  	  \        ^24       F  pVP                  RV,          4       K  	  V# )PASSTHRUzLPT%dzLPT%d_PASSTHRUzCOM%dzCOM%d_PASSTHRUzpr%d)r;   ZpsZlpZPORT1r   )r   r0   Zextendr   )r2   Z	candidateZnrs   &  r   get_possible_queue_namesZ"LpdServer.get_possible_queue_names   sv    9	))*Bw|/"4&|/"46 7 +
 *Bfrk*  r   c                s*    \        R 4       RV n        R# )z!LpdServer exiting: destroy calledTN)r5   r1   r2      &r   destroyZLpdServer.destroy   s    78	r   c                sf   . pV P                  4        F  p\        P                  ! 4       '       d   \        P                  ! 4        K2  V P                  '       d    V# V P                  W!4      pVf    V# V'       g   VP                  R4      '       d    V# \        P                  ! R4       K  	  V# )Npr皙?)	r<   r   Zevents_pendingZmain_iterationr1   r:   
startswithtimesleep)r2   r9   r8   founds   &   r   probeZLpdServer.probe   s    114D$$''""%yyy  $$T2E} 	 T__d33  JJsO 5  r   r/   N)r	   r
   r   r   r4   r:   r<   r?   rF   r   __classdictcell__Z__classdict__   @r   r.   r.   {   s$     
"H
 r   r.   c                   s6   a  ] tR t^t o RtR tR tR tRtV t	R# )BackgroundSmbAuthContextzEAn SMB AuthContext class that is only ever run from
a non-GUI thread.c                s    \         P                  ! 4       V n        \        P                  P
                  ! V .VO5/ VB  R # N)	threadingZEvent
_gui_eventr   r   r4   )r2   argsZkwargss   &*,r   r4   Z!BackgroundSmbAuthContext.__init__   s.    #//,""D:4:6:r   c                s    \         P                  ! 4        \        P                  P	                  V 4      p\         P
                  ! 4        Wn        V P                  P                  4        R # rK   )	r   Zthreads_enterr   r   perform_authenticationZthreads_leave!_do_perform_authentication_resultrM   Zset)r2   r9      & r   _do_perform_authenticationZ3BackgroundSmbAuthContext._do_perform_authentication   sF    ""994@17.r   c                s   V P                   ^ 8X  gI   V P                  '       d7   V P                  '       d%   V P                  '       d2   V P                  '       g    \        P
                  P                  V 4      # V P                  P                  4        \        P                  ! ^V P                  4       V P                  P                  4        V P                  # )r    )ZpassesZ
has_failedZauth_calledZtried_guestr   r   rO   rM   Zclearr   Ztimeout_addrR   ZwaitrP   r=   r>   r   rO   Z/BackgroundSmbAuthContext.perform_authentication   s    KK1   d&6&6&6$$;;TBB !T<<=555r   )rP   rM   N)
r	   r
   r   r   Z__doc__r4   rR   rO   r   rG   rH   rI   r   rJ   rJ      s     ;6 6r   rJ   c                   sf   a  ] tR t^t o R tR tR tR tRR ltR t	R t
R	 tR
 tR tR tRtV tR# )PrinterFinderc                s    R V n         R# )FN)quitr=   r>   r   r4   ZPrinterFinder.__init__   s	    	r   c                sX    Wn         W n        \        V P                  R  R7      V n        R# )c                 s    R # rK   r   )ZxZyr3   r   Z<lambda>Z$PrinterFinder.find.<locals>.<lambda>   s    tr   )callbackN)r"   callback_fnr   _do_findop)r2   r"   rV   s   &&&r   findZPrinterFinder.find   s      & $--:KLr   c                sH    V P                   P                  4        R V n        R# )TN)rX   cancelrT   r=   r>   r   rZ   ZPrinterFinder.cancel   s    	r   c                sv   \        4       V n        V P                  V P                  V P                  V P
                  V P                  V P                  3 F   pV P                  '       d    R #  V! 4        K"  	  V P                  '       g   V P                  R 4       R # R #   \         d    \        4         Kc  i ; irK   )Zdict_cached_attributes_probe_hplip_probe_jetdirect
_probe_ipp_probe_snmp
_probe_lpd
_probe_smbrT   	ExceptionnonfatalExceptionrV   )r2   ZfnrQ   r   rW   ZPrinterFinder._do_find   s    "&&$$((??##????$B yyy%$ yyyd# 	  %!$%s   -BB87B8Nc                s    R RRRV,          /pV'       d   W4R&   VP                  V P                  4       \        P                  ! V3/ VB p\	        RV,          4       V P                  V4       R# )device-classZnetworkdevice-infoz%sdevice-locationDevice found: %sN)Zupdater[   cupshelpersDevicer5   rV   )r2   uriinfolocationdevice_dictZ
new_devices   &&&&  r   _new_deviceZPrinterFinder._new_device  sh    &	%td{5+3)*D334 ''<<
&,-*%r   c                s    \        R 4       \        P                  ! RV P                  .R\        P                  \        P
                  \        P                  R7      pTP                  4       w  r4TP                  ^ 8w  d   \        RTP                  ,          4       R# T P                  '       d   \        R4       R# TP                  4       P                  R4       F  p\        T4      p\        T4      pT^8X  d	   Tw  rp
rpMT^8X  d   Tw  rrpMT^8X  d   Tw  rrMKE  RTR	T
R
T/pT^8X  d   \        RX,          4       YR&   T^8X  d   XTR&   \         P"                  ! T	3/ TB p\        RT	,          4       T P%                  T4       YP&                  R	&   XT P&                  R&   K  	  \        R4       R#   \         d7   p\        R4       TP                  \        P                  8X  d    Rp?R# h Rp?ii ; i)zsnmp: tryingz/usr/lib/cups/backend/snmpTrN   Z	close_fdsZstdinstdoutstderrzsnmp: no goodNzsnmp: no good (return code %d)Z
rd   device-make-and-modelre   zsnmp: Device ID found:
%sz	device-idrf   rg   	device_idz
snmp: done)r5   
subprocessPopenr"   DEVNULLPIPEOSErrorerrnoENOENTcommunicate
returncoderT   r6   r   r   r   rh   ri   rV   r[   )r2   perp   rq   r   r   r   Zdevice_classrj   Zmake_and_modelrk   rs   Zdevice_locationrm   devices   &               r   r_   ZPrinterFinder._probe_snmp  s   	'  (D(,(7,0(2(:(:)3)3););=A ==+<<181<<GH999(MM$**D1DTNEUAAv5:3N/aGLDN)a<A9ND*L3^)42K Av8%& '+4K(Av1@-. ''<<F*S01f% @N##$;<3<D##K0= 2@ 	L!a  	(ww%,,&	s   AF; ;G<*G76G77G<c                s   \        R 4       \        V P                  4      pVP                  4        F  pV P                  '       d   \        R4        R# VP                  V. 4      pVf   \        R4        MrV'       d0   RV P                  : RV: 2pV P                  W@P                  4       V'       g   VP                  R4      '       d    M\        P                  ! R4       K  	  \        R4       R# )	zlpd: tryingzlpd: no goodNzlpd: couldn't connectzlpd:///r@   rA   z	lpd: done)
r5   r.   r"   r<   rT   r:   rn   rB   rC   rD   )r2   Zlpdr8   rE   rj   s   &    r   r`   ZPrinterFinder._probe_lpdL  s    M"'003DyyyN+OOT2.E}34u'+}}d;  mm4T__d33JJsO% 4( 	K r   c                s,   R V P                   9   d   V P                   R ,          R8w  d   V P                   R ,          P                  4       P                  R4      '       g\   V P                   R ,          P                  4       P                  R4      '       g&   \        RV P                   R ,          ,          4       R#  \        R4       \        P
                  ! RRV P                  .R	\        P                  \        P                  \        P                  R
7      pTP                  4       w  r4TP                  ^ 8w  d   \        RTP                  ,          4       R# T P                  '       d   \        R4       R# TP                  4       P!                  4       p\        RT,          4       TP#                  R4      R8w  d   T P%                  YU4       \        R4       R#   \         d,   pTP                  \        P                  8X  d    Rp?R# h Rp?ii ; i)rr   ZUnknownZhpZhewlettz#hplip: no good (Non-HP printer: %s)Nzhplip: tryingz
hp-makeuriz-cTro   zhplip: no good (return code %d)zhplip: no goodzhplip: uri is %sr   zhplip: donei)r[   ZlowerrB   r5   rt   ru   r"   rv   rw   rx   ry   rz   r{   r|   rT   r6   ZstriprY   rn   )r2   r}   r~   rp   rq   rj      &     r   r\   ZPrinterFinder._probe_hplipe  s   #t'>'>>##$;<	I''(?@FFITTVZ[[''(?@FFITTV_``=//0GHI J	(  dDMM'J,0(2(:(:)3)3););	=A ==+<<19ALLHI999()mm$$'&,-88S>RS&M")  	ww%,,&		s   <AG H(HHHc                s   \         '       g   R # \        4       p^ p\        4       '       d   ^
p\        P                  P                  VVP                  R7      p. pRV P                  ,          p\        R4        VP                  4       ^ 8  dB   V P                  '       d   \        R4       R #  VP                  V4      P                  4       pKV   T P                  '       d   \        R4       R # T F  pTP.                  \        P                  P0                  8X  g   K.  R\2        P4                  ! T P                  4      : R\2        P4                  ! TP6                  4      : 2pRT P                  ,          p	T P9                  YY4       K  	  \        R	4       R #   \         d   pTP                  T4        R p?EKD  R p?ii ; i  \         dj   pTP                   w  rgT\"        P$                  \"        P&                  \"        P(                  39  d   \        R\+        Yg34      ,          4        R p?ELdR p?i \-        4         ELv; i)
N)debugZauth_fnz	smb://%s/zsmb: tryingzsmb: no goodzRuntime error: %szsmb://r   zSMB (%s)z	smb: done)PYSMB_AVAILABLErJ   Zget_debuggingr   ZsmbcZContextrU   r"   r5   rO   rT   ZopendirZgetdentsrb   ZfailedRuntimeErrorrN   ry   rz   ZEACCESZEPERMr7   rc   Z	smbc_typeZPRINTER_SHAREsmburiZurlquoter8   rn   )
r2   Z	smbc_authr   ZctxZentriesrj   r~   r%   Zentryrk   s
   &         r   ra   ZPrinterFinder._probe_smb  s   ,/	Ejj  *3*<*< ! >DMM)M"	!2259999/)!kk3/88;G :  999'E%**":"::'-'F'-

'CE!DMM1  +  	K ) ! )$$a(() 	AVVFQu||U[[AA/$-?@	! sI   9&G  G .F G G%F=6G =GG IAH44Ic                sR   R pV P                   V3p\        R4       \        V P                   V4      pV'       g   \        RV,          4       MO\        RV,          4       RV,          pRV P                   ,          pV P                  WE4       VP	                  4        \        R4       R# )i#  zjetdirect: tryingzjetdirect: %s:%d CLOSEDzjetdirect %s:%d OPENzsocket://%s:%dzJetDirect (%s)zjetdirect: doneN)r"   r5   r-   rn   r!   )r2   r#   Zsock_addressr%   rj   rk   r   r   r]   ZPrinterFinder._probe_jetdirect  s    t,'(t,1L@A .=>"\1C#dmm3DS'GGJ%&r   c                sN   \        R 4        \        P                  ! V P                  R\        P                  \        P
                  4      pT Fj  pTw  r4rVpT\        P                  8X  d   T^ ,          R8X  g(   T\        P                  8X  g   KC  T^ ,          R8X  g   KS  \        R4       \        R4        R# 	   \        P                  ! T P                  R7      p TP                  4       p	T	P                  4        F2  w  rTR,          p
TR,          pTR,          pT P                  YT4       K4  	  \        R4       R#   \        P                   d,    \        RT P                  ,          4       \        R4        R# i ; i  \         d    \        R	4       \        R4        R# i ; i  \        P                   dc    \        R
T P                  ,          4       RT P                  ,          p
RT P                  ,          pT P                  Y4       \        R4        R# i ; i)zipp: tryingiw  zipp: can't resolve %szipp: no goodNz	127.0.0.1z::1z#ipp: do not probe local cups server)r$   z$ipp: can't connect to server/printerz0%s is probably not a cups server but IPP printerzipp://%s:631/ippzIPP (%s)z	ipp: donezprinter-uri-supportedzprinter-infozprinter-location)r5   r   r   r"   r   r   r   ZAF_INETZAF_INET6cupsZ
Connectionr   ZgetPrintersZIPPErrorrn   Zitems)r2   r&   r'   r(   r)   r*   r+   r,   ZcZprintersrj   rk   r8   Zqueuerl   s   &              r   r^   ZPrinterFinder._probe_ipp  s   M"	##DMM38H8H$*$6$68B C14.B%Bfnn$A+)=foo%"Q%5.ABN+ 	6A		}}'H $>>,KD/0C(D/0HS1	 - 	K I  	/$--?@'	  	>?'	 }} 	J& '$6C-DS'$	s6   ?E =!F F- <FF!F*)F*-A3H$#H$)r[   rV   r"   rX   rT   rK   )r	   r
   r   r   r4   rY   rZ   rW   rn   r_   r`   r\   ra   r]   r^   r   rG   rH   rI   r   rS   rS      sE     M
$(&:"x!2$#L)!V'")! )!r   rS   Z__main__zNeed printer addressc                 s:    V f   \         P                  4        R # R # rK   )looprT   )r   r>   r   displayr     s    >IIL r   )&rh   r   ry   r   rC   Zgi.repositoryr   r   Ztimedopsr   rt   rL   r   r   r   r   r   r   r   r-   r.   r   rJ   rS   r	   Zsysr   ZargvZprintZexitZset_debuggingZMainLoopr   r   Zaddrr}   rY   Zrunr   r   r   <module>r      s  *       #    !  O,b<L L\6u00 68K! K!Z z
CHH~$%!4D 88A;DAFFD'HHK! YO s   D D"