
    Kcd&                        d dl Z d dlZd dlT d dlZ G d de          Z G d d          Z G d de          Zed	k    rd d
lm	Z	  e
d            G d d          Z ed          Z e	j                    Ze                                 e                                  ed          Ze                                 e                                 dS dS )    N)*c                   &    e Zd Zd Zd Zd Zd ZdS )SemanticOperationsc                     g | _         d S N)_operation_stackselfs    -/usr/share/system-config-printer/asyncconn.py__init__zSemanticOperations.__init__   s     "    c                 :    | j                             |           d S r   )r   append)r
   	operations     r   _begin_operationz#SemanticOperations._begin_operation"   s    $$i00000r   c                 8    | j                                          d S r   )r   popr	   s    r   _end_operationz!SemanticOperations._end_operation%   s    !!$$$$$r   c                 @    	 | j         d         S # t          $ r Y d S w xY w)Nr   )r   
IndexErrorr	   s    r   current_operationz$SemanticOperations.current_operation(   s7    	(++ 	 	 	44	s    
N)__name__
__module____qualname__r   r   r   r    r   r   r   r      sP        # # #1 1 1% % %    r   r   c                   8    e Zd Zd Zd Zd Zd Zd Zd Zd Z	dS )	_AsyncMethodCallc                 p    || _         || _        || _        || _        d| _        t          d| z             d S )NF+%s)_fn_reply_handler_error_handler_auth_handler
_destroyed
debugprint)r
   fnreply_handlererror_handlerauth_handlers        r   r   z_AsyncMethodCall.__init__3   s@    ++)EDL!!!!!r   c                 *    t          d| z             d S Nz-%s)r%   r	   s    r   __del__z_AsyncMethodCall.__del__;   s    EDL!!!!!r   c                     | j         rd S t          d| z             d| _         d | _        d | _        d | _        d | _        d | _        d | _        d S NDESTROY: %sT)r$   r%   r!   r"   r#   _reply_data_error_data
_auth_datar	   s    r   destroyz_AsyncMethodCall.destroy>   s^    ? 	FMD()))""!r   c                 *   |                     d          | _        |                     d          | _        |                     d          | _        | j        |d<   | j        |d<   | j        |d<   t          | d| j                    | j        |i | d S )Nr'   r(   r)   z
: calling )	getr0   r1   r2   r'   r(   r)   r%   r    )r
   argskwdss      r   runz_AsyncMethodCall.runK   s    88_5588_55((N33 $ 2_ $ 2_#0^dhh78884 4     r   c                 r    | j         s/t          | d| j                    | j        | | j        g|R   d S d S )Nz: to reply_handler at )r$   r%   r!   r0   r
   r6   s     r   r'   z_AsyncMethodCall.reply_handlerU   i     	@8<8K8KM N N NDt'7?$??????	@ 	@r   c                 r    | j         s/t          | d| j                    | j        | | j        g|R   d S d S )Nz: to error_handler at )r$   r%   r"   r1   r:   s     r   r(   z_AsyncMethodCall.error_handler[   r;   r   c                 r    | j         s/t          | d| j                    | j        | | j        g|R   d S d S )Nz: to auth_handler at )r$   r%   r#   	auth_datar:   s     r   r)   z_AsyncMethodCall.auth_handlera   se     	=ttt7;7I7IK L L LDdn<t<<<<<<	= 	=r   N)
r   r   r   r   r,   r3   r8   r'   r(   r)   r   r   r   r   r   2   s        " " "" " "  ! ! !@ @ @@ @ @= = = = =r   r   c                   V     e Zd Z	 	 	 d fd	Zd Zd Zd Zd Zd Zd	 Z	d
 Z
d Z xZS )
ConnectionNTc
                     t          t                                                      d _        |t	          j                    }|                    d          s|dk    ot          j                    dk    }
 fd} fd} fd}|
r8|r6t          d           dd l
}|                    ||||||	          }| _        n9t          d
           dd l}|                    |||||||||	 
  
        }| _        t           j        j                  }t           j        j                  }g }t%           j                  D ]}|                    d          rt'           j        |          }t          |          |k    rt          |          |k    rTt)           |          s9t+           |                     |                     |                    |           | _        g  _        t          d z             d S )NF/	localhostr   c                 6                         d |           d S r   )_subst_reply_handler)connreplyr'   r
   s     r   subst_reply_handlerz0Connection.__init__.<locals>.subst_reply_handlerz   s!    %%t]EBBBBBr   c                 6                         d |           d S r   )_subst_error_handler)rF   excr(   r
   s     r   subst_error_handlerz0Connection.__init__.<locals>.subst_error_handler}   s!    %%t]C@@@@@r   c                 :                         d | ||           d S r   )_subst_auth_handler)promptrF   methodresourcer)   r
   s       r   subst_auth_handlerz/Connection.__init__.<locals>.subst_auth_handler   s%    $$dL&&(SSSSSr   zUsing polkit-1 connection class)r'   r(   hostport
encryptionparentzUsing IPP connection class)
r'   r(   r)   rS   rT   rU   rV   try_as_rootprompt_allowedsemantic_r   )superr@   r   r$   cups	getServer
startswithosgetuidr%   asyncpk1PK1Connection_connasyncippIPPAuthConnectiontypegetPrinters
getDevicesdirgetattrhasattrsetattr_make_bindingr   	_bindings_methodcalls)r
   r'   r(   r)   rS   rT   rU   rV   rW   rX   use_pkrH   rL   rR   ra   crd   
methodtypeinstancemethodtypebindingsfnamer&   	__class__s   ````                  r   r   zConnection.__init__m   s    	z4  )),,, <>##D??C((?DK,? $),,!# 		C 	C 	C 	C 	C 	C	A 	A 	A 	A 	A 	A	T 	T 	T 	T 	T 	T  	k 	9:::OOO&&6I6I-13=/5	 ' 7 7A
 DJJ4555OOO**:M:M9K15D7A398C;I59 + ; ;A DJ4:122
!4:#899$*%% 	( 	(E%% $*e,,BRyyJ&&4998J+J+JD%(( (ud&8&8"&=&=>>>'''!EDL!!!!!r   c                 4    t          j        d| z             d S r+   debugr%   r	   s    r   r,   zConnection.__del__   s    %$,'''''r   c                     t          d| z             d| _        	 | j                                         n# t          $ r Y nw xY w| j        D ]}|                                 | j        D ]}t          | |           d S r.   )r%   r$   rc   r3   AttributeErrorro   rn   delattr)r
   
methodcallbindings      r   r3   zConnection.destroy   s    MD()))	J!!!! 	 	 	D	 + 	" 	"J!!!!~ 	$ 	$GT7####	$ 	$s   5 
AAc                       fdS )Nc                  &     j         g| R i |S r   )_call_function)r6   r7   r&   r
   s     r   <lambda>z*Connection._make_binding.<locals>.<lambda>   s%    %8T%8"%Lt%L%L%Lt%L%L r   r   )r
   r&   s   ``r   rm   zConnection._make_binding   s    LLLLLLr   c                     t          || j        | j        | j                  }| j                            |            |j        |i | d S r   )r   rE   rJ   rN   ro   r   r8   )r
   r&   r6   r7   r}   s        r   r   zConnection._call_function   s]    %r'+'@'+'@'+'?A A
 	  *---
&&&&&&r   c                     |r@|                                  | j                            |          }| j        |= |dd          }|r&| j        s!t	          | d|            || g|R   d S d S d S N   : chaining up to r3   ro   indexr$   r%   )r
   r}   r'   r6   is        r   rE   zConnection._subst_reply_handler        	!!!!''44A!!$8D 	( 	(444GHHHM4'$''''''	( 	( 	( 	(r   c                     |r@|                                  | j                            |          }| j        |= |dd          }|r&| j        s!t	          | d|            || g|R   d S d S d S r   r   )r
   r}   r(   r6   r   s        r   rJ   zConnection._subst_error_handler   r   r   c                     |r6|                                  | j                            |          }| j        |= |r+| j        s&t	          | d|            ||| ||           d S d S d S )Nr   r   )r
   r}   r)   rO   rP   rQ   r   s          r   rN   zConnection._subst_auth_handler   s     	%!!!!''44A!!$ 	: 	:444FGGGL&$99999	: 	: 	: 	:r   c                 :    | j                             |           dS )z*Call this from your auth_handler function.N)threadset_auth_info)r
   passwords     r   r   zConnection.set_auth_info   s    !!8,,,,,r   )	NNNNNNNTT)r   r   r   r   r,   r3   rm   r   rE   rJ   rN   r   __classcell__)rv   s   @r   r@   r@   l   s        :>FJ@D<" <" <" <" <" <"|( ( ($ $ $M M M' ' '( ( (( ( (: : :- - - - - - -r   r@   __main__)GObjectTc                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )Testc                 ^    t                      | _        || _        t          d| z             d S )Nr   )r@   rc   _quitr%   )r
   quits     r   r   zTest.__init__   s,    #DJDJ%%%%%r   c                 4    t          j        d| z             d S r+   rx   r	   s    r   r,   zTest.__del__   s    edl+++++r   c                     t          d| z             | j                                         | j        rt                                           d S d S )Nr/   )r%   rc   r3   r   loopr   r	   s    r   r3   zTest.destroy   sN    ,---J!!!z 		 r   c                 R    | j                             | j        | j                   d S )N)r'   r(   )rc   rh   getDevices_replygetDevices_errorr	   s    r   rh   zTest.getDevices   s;    J!!1F151F " H H H H Hr   c                 N    t          ||           |                                  d S r   )printr3   )r
   rF   results      r   r   zTest.getDevices_reply   s#    4   LLOOOOOr   c                 f    t          t          |                     |                                  d S r   )r   reprr3   )r
   rF   rK   s      r   r   zTest.getDevices_error  s'    4::LLOOOOOr   N)	r   r   r   r   r,   r3   rh   r   r   r   r   r   r   r      sq        	& 	& 	&
	, 	, 	,	 	 		H 	H 	H	 	 		 	 	 	 	r   r   F)r\   r_   ry   objectr   r   r@   r   gi.repositoryr   set_debuggingr   tMainLoopr   rh   r3   r8   r   r   r   <module>r      sy  *  				            (3= 3= 3= 3= 3= 3= 3= 3=tz- z- z- z- z-# z- z- z-x z%%%%%%M4       6 	eA7DLLOOOIILLLdALLOOOHHKKKKKO r   