HEX
Server: Apache/2.4.65 (Unix) OpenSSL/3.5.5
System: Linux cpanel.ns-taberra.com 5.14.0-681.el9.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Feb 11 20:19:22 UTC 2026 x86_64
User: asif201 (1002)
PHP: 8.3.0
Disabled: NONE
Upload Files
File: //usr/share/system-config-printer/__pycache__/asyncipp.cpython-39.pyc
a

��z_�h�@s�ddlZddlZddlZddlmZddlmZddlmZddlmZddlZe�	d�ddl
Z
ddlTddlZddlZej
ejejd�Gd	d
�d
ej�ZGdd�d�ZGd
d�d�ZGdd�de�Zedkr�ed�Gdd�d�Ze�e��dS)�N)�GObject)�GLib)�Gdk)�Gtkz1.9.60)�*)�domain�	localedirc@sPeZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zddd
�Zdd�Z	dd�Z
dS)�_IPPConnectionThreadNc

Csntj�|�|�d�||_||_||_||_|	|_||_	||_
||_t�
d�|_||_d|_td|�dS)NT�F�+%s)�	threading�Thread�__init__�	setDaemon�_queue�_conn�host�port�_encryption�_reply_handler�_error_handler�
_auth_handler�queue�Queue�_auth_queue�user�
_destroyed�
debugprint)
�selfZmyqueue�conn�
reply_handler�
error_handler�auth_handlerrrr�
encryption�r$�,/usr/share/system-config-printer/asyncipp.pyr0s
z_IPPConnectionThread.__init__cCst�d|�dS�Nz-%s��debugr�rr$r$r%�__del__Csz_IPPConnectionThread.__del__cCs|j�|�dS�N)r�put�r�passwordr$r$r%�
set_auth_infoFsz"_IPPConnectionThread.set_auth_infoc
Cs�|jdurt��|_|jdur(t��|_|jdur<t��|_|jrPt�|j�n
t�	�|_t�
|j�z$tj|j|j|jd�}|�
d�Wn2ty�}zd}|�|�WYd}~n
d}~00td�|j��|_|j��}tdt|��|du�r|j���q�n|j�r|j��q�d|_|\}}}}}}	|dk�r@||_|dk�rP||_|	dk�r`|	|_|dk�r|d|_t�|j�td|j�t�
|j�z6tj|j|j|jd�}td�|j��|�
d�Wq�t�y}z(td	�|j��|�|�WYd}~q�d}~00q�z`td
|�||g|�Ri|��}
|tjjjk�rb|
ik�rbt�tjd��td�|�
|
�Wn@t�y�}z&td
t|��|�|�WYd}~n
d}~00|j��q�td�|` |`|`|`|`|`!~t�
d�dS)N)rrr#zAwaiting further instructionsz
Next task: %sFTrzSet user=%s; reconnecting...z...reconnectedz	...failedzCall %s�z
...successz...failure (%s)zThread exiting)"r�cupsZ	getServerrZgetPortrZ
getEncryptionrZsetUser�getUserZsetPasswordCB2�_auth�
Connection�_reply�RuntimeError�_errorrr�empty�idle�get�reprZ	task_donerrrrZadminGetServerSettings�__call__�IPPError�IPP_NOT_AUTHORIZED�	Exceptionrr)rr�e�item�fn�args�kwdsZrhZehZah�resultr$r$r%�runIs�






� 








�

 
 z_IPPConnectionThread.runcCsd|_|j�d�dS)NT)rrr,r)r$r$r%�stop�sz_IPPConnectionThread.stopcs:����fdd�}�jdur dSt�||��j��}|S)Ncs>t���dur ��|�j�n��|�j���t��dS�NF)r�
threads_enterrr�
threads_leave)�prompt�r�method�resourcerr$r%�prompt_auth�sz/_IPPConnectionThread._auth.<locals>.prompt_authr0)rr�idle_addrr:)rrKrrMrNrOr.r$rLr%r3�s


z_IPPConnectionThread._authcs,�fdd�}�js(�jr(t�|�j|�dS)Ncs&�js"t��|�j|�t��dSrH�rrrIrrJ)�handlerrEr)r$r%�
send_reply�s
z/_IPPConnectionThread._reply.<locals>.send_reply)rrrrP)rrErSr$r)r%r5�sz_IPPConnectionThread._replycs:�fdd�}�js6�jr6td�j�t�|�j|�dS)Ncs&�js"t��|�j|�t��dSrHrQ)rR�excr)r$r%�
send_error�s
z/_IPPConnectionThread._error.<locals>.send_errorzAdd %s to idle)rrrrrP)rrTrUr$r)r%r7�sz_IPPConnectionThread._error)NNNNNNN)NNN)�__name__�
__module__�__qualname__rr*r/rFrGr3r5r7r$r$r$r%r	/s�
c
r	c@sTeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zdd
d�Z	dd�Z
dd�ZdS)�
IPPConnectiona�
    This class starts a new thread to handle IPP operations.

    Each IPP operation method takes optional reply_handler,
    error_handler and auth_handler parameters.

    If an operation requires a password to proceed, the auth_handler
    function will be called.  The operation will continue once
    set_auth_info (in this class) is called.

    Once the operation has finished either reply_handler or
    error_handler will be called.
    Nc	
Cs�td�||_t��|_t|j||||||||d�	|_|j��ttj	j
�}	g}
ttj	�D]H}|ddkrlqZttj	|�}t|�|	kr�qZt
|||�|��|
�|�qZ|
|_td|�dS)NzNew IPPConnection�r r!r"rrrr#r� r)rZ_parentrrr	�thread�start�typer1r4ZgetPrinters�dir�getattr�setattr�
_make_binding�append�bindings)
rr r!r"rrrr#�parentZ
methodtyperd�fnamerBr$r$r%r�s.
�
zIPPConnection.__init__cCst�d|�dSr&r'r)r$r$r%r*szIPPConnection.__del__cCsPtd|�|jD]}t||�q|j��rLtd�|j��t�d|j�dS)NzDESTROY: %szStopping worker threadr
)	rrd�delattrr\�is_aliverGrZtimeout_add_seconds�_reap_thread)rZbindingr$r$r%�destroys


zIPPConnection.destroycCs(|jjr|j��dStd|j�dS)NFz Thread %s still processing tasksT)r\r9r�joinrr)r$r$r%ris

zIPPConnection._reap_threadcCs|j�|�dS)z*Call this from your auth_handler function.N)r\r/r-r$r$r%r/szIPPConnection.set_auth_infocCs&td�|j�d|fi||df�dS)NzReconnect...TF)rrr,)rrr r!r$r$r%�	reconnect!s�zIPPConnection.reconnectcs��fdd�S)Ncs�j�g|�Ri|��Sr+)�_call_function)rCrD�rBrr$r%�<lambda>'�z-IPPConnection._make_binding.<locals>.<lambda>r$)rrBr$rnr%rb&szIPPConnection._make_bindingcOsjd}}}d|vr"|d}|d=d|vr8|d}|d=d|vrN|d}|d=|j�||||||f�dS�NFr r!r")rr,)rrBrCrDr r!r"r$r$r%rm)s�zIPPConnection._call_function)NNNNNNNN)NN)rVrWrX�__doc__rr*rjrir/rlrbrmr$r$r$r%rY�s�


rYc@sheZdZddd�Zdd�Zdd�Zdd	�Zdd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�_IPPAuthOperationNcCshd|_d|_d|_d|_d|_d|_||_||_|jj|_	||_
||_||_||_
||_td|�dS)NFr0r)�_auth_called�
_dialog_shown�
_use_password�_cancel�
_reconnect�_reconnected�_userr�try_as_root�_try_as_root�
_client_fn�_client_args�_client_kwds�_client_reply_handler�_client_error_handlerr)rr r!rrrBrCrDr$r$r%rAs
z_IPPAuthOperation.__init__cCst�d|�dSr&r'r)r$r$r%r*Tsz_IPPAuthOperation.__del__cCs|`|`|`|`|`|`dSr+)rr}r~rr�r�r)r$r$r%�_destroyWsz_IPPAuthOperation._destroyc	Cs|jdurtd�|�||�S|jr:td|�|�|�S|jrxd|_d|_td||jf�|j|j|j	|jd�dSd}t
|�tjkr�|j
\}}|tjks�|tjks�|tjkr�|tjk}n |tjkr�|�||�S|�|�SnRt
|�tjk�r(|j
\}|tjk�s|tjk�r|tjk}n
|�|�Sn
|�|�S|�rFtd|�ntd|�|j�r�|jd	k�r�|jjjd
dk�s�|�r�td�d	|_|j|j|j	|jd�dS|j�s�|�|�S|jj}|jj}tjj||d
�d|_td||jf�|j|j|j	|jd�dS)NzConnection/reconnection failedz,%s (_error_handler): canceled so chaining upFTz,%s (_error_handler): reconnecting (as %s)...�r r!z%s (_error_handler): forbiddenz#%s (_error_handler): not authorized�rootr�/zAuthentication: Try as root�rrr0)r}r�_reconnect_errorrwr7rxryrzrl�_reconnect_replyr^r1r=rCr>Z
IPP_FORBIDDENZIPP_AUTHENTICATION_CANCELEDZIPP_SERVICE_UNAVAILABLEZ	HTTPErrorZHTTP_UNAUTHORIZEDZHTTP_FORBIDDENr|rr\rrtr�authconn�global_authinfocache�remove_auth_inforv)	rrrTZ	forbiddenr@�m�srrr$r$r%r!_s�

��

��
�
����
���z_IPPAuthOperation.error_handlercCs�|jdkrj|jdurt��|_|jr�|jj}|jj}tjj	||d�}|r�|d|jkrf|d|_
d|_~n&|jj}|jj}tjj||d�d|_
d|_|jr�t
d�d|_|�|j
�dSd|_|js�|�|j
�dS|j�r"tj|jjddtjjtjjtd�d	�}|�td
��|��|��d}	|j�r8|j��}	|	du�rRtj|jd�}ntd�|	}
tj|
|jd
�}|� d�|jdu�r�t��|_|�ddg�|�!d�|�"d�|�#�|�$d|j%�d|_dS)NFr�rr
Tr0z%Supplying password after reconnectionzNot authorized�reZmodalZdestroy_with_parentZmessage_typeZbuttons�textzThe password may be incorrect.)rezAuthentication (%s))�titlere�username�response)&rtrzr1r2r\rrr�r��lookup_auth_inforvryr�rr/�prompt_allowedrur�
MessageDialogrre�MessageType�ERROR�ButtonsTypeZCLOSE�_�format_secondary_textrFrj�semantic�current_operationZ
AuthDialogZ
set_promptZfield_grab_focusZset_keep_above�show_all�connect�_on_auth_dialog_response)rrKrrMrNrr�creds�d�opr�r$r$r%r"�st


�
�
�

�



z_IPPAuthOperation.auth_handlercCs0d|_|jj�|j|j|j|j|j|j	f�dSrH)
rtrrr,r}r~rr�r!r"r)r$r$r%�submit_task�s�z_IPPAuthOperation.submit_taskcCs�|��\}}|dkr|j}tjj||f|jjj|jjjd�||_	|�
�|tjj
ksb|tjjkr�d|_|j�d�tjj|jjj|jjjd�td�dS||jkr�||_|j�|�td�dS||_||_d|_|j�d�td|j�dS)Nr0r�Tz
Auth canceledzPassword supplied.zWill try as %s)Z
get_auth_inforzr�r�Zcache_auth_inforr\rrZ_dialog�hider�ResponseType�CANCELZDELETE_EVENTrwr/r�rrvrx)r�dialogr�rr.r$r$r%r��s>��
��
z*_IPPAuthOperation._on_auth_dialog_responsecCs$td|j�|jdur |��dS)NzConnected as %s)rrzr}r��rrrEr$r$r%r�s
z"_IPPAuthOperation._reconnect_replycCs td|j�|jjs$|�|�dSd}|jr8|j��}|durJtd�}ntd�|}tj	|jj
ddtjjtj
j|d�}|jdur�t|�tkr�d}n"t|�tjkr�|jd}nt|�}|�td|��|�tjtjjtd	�tjj�|�tjj�|�d
|j�td|||f�|��dS)NzFailed to connect as %szCUPS server errorzCUPS server error (%s)Tr�z!service-error-service-unavailabler
z3There was an error during the CUPS operation: '%s'.ZRetryr�z7%s (_reconnect_error): presenting error dialog (%s; %s)) rrzrr�r7r�r�r�rr�rer�r�r�ZNONEr}r^r6r1r=rCr;r�Zadd_buttonsZSTOCK_CANCELr�r��OKZset_default_responser��_on_retry_server_error_responseZshow)rrrTr��msgr��messager$r$r%r�%sB



����z"_IPPAuthOperation._reconnect_errorcCsn|��|tjjkrHtd||jjjf�|jj|jjj|j	|j
d�n"td|�|�t�
dtd���dS)Nz/%s: got retry response, reconnecting (as %s)...r�z%s: got cancel responserzOperation canceled)rjrr�r�rrr\rrlr�r�r7r1r=r�)rr�r�r$r$r%r�Ls��z1_IPPAuthOperation._on_retry_server_error_responsecCsTtd|t|�f�|jrDtd||jf�|�|j|�|��ntd|�dS)Nz%s (_error): handling %sz%s (_error): calling %sz(%s (_error): no client error handler set)rr;r�rr�)rrTr$r$r%r7Xs�
z_IPPAuthOperation._error)NNNN)NN)rVrWrXrr*r�r!r"r�r�r�r�r�r7r$r$r$r%rs@s�
S
A
 'rsc
@s&eZdZd	dd�Zdd�Zdd�ZdS)
�IPPAuthConnectionNTc
Csx||_|	|_||_|
|_d}tjj||d�}|rJ|ddks@|rH|d}~t|||�}
tj	|||
j
|
j||||d�dS)Nr�rr�rZ)rer�r{r�r�r�r�rsrYrr!r")rr r!r"rrr#rer{r�r�rr�r�r$r$r%rfs$��zIPPAuthConnection.__init__cCsd|_t�|�dSr+)r�rYrjr)r$r$r%rj~szIPPAuthConnection.destroycOsrd}}}d|vr"|d}|d=d|vr8|d}|d=d|vrN|d}|d=t||||jj|||�}|��dSrq)rsr\rr�)rrBrCrDr r!r"r�r$r$r%rm�s�z IPPAuthConnection._call_function)
NNNNNNNTTN)rVrWrXrrjrmr$r$r$r%r�es�
r��__main__Tc@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�UIcCs�t��}|�d|j�tj�d�}|�d|j�t��}|�|ddd�|�	|�tj�d�|_
|j
�d|j�|j
�d�|�|j
ddd�d|_
|��dS)NrjZConnectZclickedFrzGet Devices)rZWindowr�rjZButtonZnew_with_label�connect_clickedZVBoxZ
pack_start�add�get_devices_button�get_devices�
set_sensitiverr�)r�w�bZvboxr$r$r%r�s
zUI.__init__cCs.z|j��Wnty Yn0t��dSr+)rrj�AttributeErrorrZ	main_quit)rZwindowr$r$r%rj�s
z
UI.destroycCs&|jr|j��t|j|jd�|_dS)Nr�)rrjr��	connected�connect_failed�rZbuttonr$r$r%r��s

�zUI.connect_clickedcCs tdt|��|j�d�dS)NzSuccess: %sT)rr;r�r�r�r$r$r%r��szUI.connectedcCs*tdt|��|j�d�|j��dS)NzExc %sF)rr;r�r�rrj�rrrTr$r$r%r��szUI.connect_failedcCs*|�d�td�|jj|j|jd�dS)NFzGetting devicesr�)r�rrZ
getDevices�get_devices_reply�get_devices_errorr�r$r$r%r��s


�zUI.get_devicescCs6||jkrtd�dStdt|��|j�d�dS)NzIgnoring stale replyzGot devices: %sT�rrr;r�r�r�r$r$r%r��s

zUI.get_devices_replycCs6||jkrtd�dStdt|��|j�d�dS)NzIgnoring stale errorzError getting devices: %sTr�r�r$r$r%r��s

zUI.get_devices_errorN)rVrWrXrrjr�r�r�r�r�r�r$r$r$r%r��sr�)rZconfigr1Z
gi.repositoryrrrrrZrequirer�r(�gettext�installZPACKAGErr
r	rYrsr�rVZ
set_debuggingr��mainr$r$r$r%�<module>s2
/c'1>