
    .Ph                         d dl Z d dlZd dlZddlmZ ddlmZ ddlmZ ddl	m
Z
mZmZmZ 	 d dlZd dlmZ n# e$ r Y n
e$ r Y nw xY wd Z G d	 d
e          Z G d de          ZdS )    N   )KeyringBackend)
properties)SimpleCredential)	InitErrorKeyringLockedPasswordDeleteErrorPasswordSetError)DBusGMainLoopc                      t           t          t          f} t          j        |           5  t
          j        d         cddd           S # 1 swxY w Y   dS )z/
    Safely infer an app id from sys.argv.
    r   N)AttributeError
IndexError	TypeError
contextlibsuppresssysargv)alloweds    X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/keyring/backends/kwallet.py_id_from_argvr      s     j)3G		W	%	%  x{                 s   AAAc                        e Zd ZdZ e            pdZdZdZdZe	j
        defd            Z fdZd	 Zd
 Zd Z fdZd Zd Z xZS )DBusKeyringz!
    KDE KWallet 5 via D-Bus
    zPython keyring libraryNzorg.kde.kwalletd5z/modules/kwalletd5returnc                    dt                      vrt          d          	 t          j        t	                                }n9# t          j        $ r'}t          |                                          |d }~ww xY w|                    | j                  s*| j        |	                                v st          d          dt          j        dd                              d          v rd	S d
S )Ndbuszpython-dbus not installedmainloopzCThe KWallet daemon is neither running nor activatable through D-BusKDEXDG_CURRENT_DESKTOP :gffffff@g@)globalsRuntimeErrorr   
SessionBusr   DBusExceptionget_dbus_messagename_has_ownerbus_namelist_activatable_namesosgetenvsplit)clsbusexcs      r   priorityzDBusKeyring.priority'   s    "":;;;	@/=??;;;CC! 	@ 	@ 	@s335566C?	@ s|,,	|s99;;;;U   BI3R88>>sCCCC3ss   !A A9"A44A9c                 H     t                      j        |i | d| _        d S )N)super__init__handle)selfargkw	__class__s      r   r4   zDBusKeyring.__init__:   s*    #$$$$    c                 z   d}g }| j                             | j        || j                  r| j                             | j        |d| j                  }|                                D ]}|d         }|d         }|                    dd          \  }}| j                             | j        |||| j                  }|dk    r'| j                             | j        ||| j                   | j                             | j        |d| j                  }|s*| j         	                    | j        || j                   d S d S d S )NPythonz*@*r      @*)
iface	hasFolderr5   appidreadPasswordListitemsrsplitwritePasswordremoveEntryremoveFolder)	r6   service
old_folder
entry_listentrykeypasswordusernamerets	            r   _migratezDBusKeyring._migrate>   sW   

:ZDD 	M44Z
 J $))++ 	U 	UAh 8$'JJsA$6$6!'j..K(Hdj  !88J**4;
CTTT44Zdj J  M
''ZLLLLL)	M 	M&M Mr:   c                 0   | j         dk    r!| j                            | j                   rdS t          j        t                                }d}	 |                    | j        | j                  }t          j	        |d          | _        | j        
                    | j                                        || j                  | _         n+# t          j        $ r}t          d| d          |d }~ww xY w| j         dk     rdS |                     |           dS )Nr   Tr   zorg.kde.KWalletzFailed to open keyring: .F)r5   r@   isOpenr   r$   r   
get_objectr(   object_path	InterfaceopennetworkWalletrB   r%   r   rQ   )r6   rI   r.   wId
remote_objes         r   	connectedzDBusKeyring.connectedW   s   ;!z  -- to}777	Dt7GHHJ
4EFFDJ*//$**B*B*D*Dc4:VVDKK! 	D 	D 	D;q;;;<<!C	D ;??5gts   A7C	 	C1C,,C1c                    |                      |          st          d          | j                            | j        ||| j                  sdS | j                            | j        ||| j                  }t          |          S )z,Get password of the username for the serviceFailed to unlock the keyring!N)r]   r   r@   hasEntryr5   rB   readPasswordstrr6   rI   rO   rN   s       r   get_passwordzDBusKeyring.get_passwordj   sx    ~~g&& 	A ?@@@z""4;4:NN 	4:**4;4:VV8}}r:   c                    |"t                                          ||          S |                     |          st          d          | j                            | j        || j                  D ]T}| j                            | j        ||| j                  }t          t          |          t          |                    c S dS )a  Gets the first username and password for a service.
        Returns a Credential instance

        The username can be omitted, but if there is one, it will forward to
        get_password.
        Otherwise, it will return the first username and password combo that it finds.
        Nr_   )r3   get_credentialr]   r   r@   	entryListr5   rB   ra   r   rb   )r6   rI   rO   rN   r9   s       r   rf   zDBusKeyring.get_credentialt   s     77))'8<<<~~g&& 	A ?@@@
,,T['4:NN 	B 	BHz..Wh
 H $CMM3x==AAAAA		B 	Br:   c                     |                      |          st          d          | j                            | j        |||| j                   dS )z,Set password for the username of the serviceCancelled by userN)r]   r
   r@   rF   r5   rB   rc   s       r   set_passwordzDBusKeyring.set_password   sM    ~~g&& 	8"#6777
  gx4:VVVVVr:   c                    |                      |          st          d          | j                            | j        ||| j                  st          d          | j                            | j        ||| j                   dS )z4Delete the password for the username of the service.ri   zPassword not foundN)r]   r	   r@   r`   r5   rB   rG   )r6   rI   rO   s      r   delete_passwordzDBusKeyring.delete_password   s|    ~~g&& 	;%&9:::z""4;4:NN 	<%&:;;;
t{GXtzJJJJJr:   )__name__
__module____qualname____doc__r   rB   walletr(   rV   r   classpropertyfloatr0   r4   rQ   r]   rd   rf   rj   rl   __classcell__r9   s   @r   r   r      s         MOO77EF"H&K    $    M M M2  &  B B B B B*W W WK K K K K K Kr:   r   c                   D     e Zd ZdZdZdZej         fd            Z xZ	S )DBusKeyringKWallet4z!
    KDE KWallet 4 via D-Bus
    zorg.kde.kwalletdz/modules/kwalletdc                 0    t                      j        dz
  S )Nr=   )r3   r0   )r-   r9   s    r   r0   zDBusKeyringKWallet4.priority   s    ww!##r:   )
rm   rn   ro   rp   r(   rV   r   rr   r0   rt   ru   s   @r   rw   rw      s\          "H%K$ $ $ $ $ $ $ $ $r:   rw   )r   r*   r   backendr   compatr   credentialsr   errorsr   r   r	   r
   r   dbus.mainloop.glibr   ImportErrorr   r   r   rw    r:   r   <module>r      sU       				 



 $ $ $ $ $ $       * * * * * * T T T T T T T T T T T T	KKK0000000 	 	 	D 	 	 	D	
  zK zK zK zK zK. zK zK zKz
$ 
$ 
$ 
$ 
$+ 
$ 
$ 
$ 
$ 
$s   
7 AAA