
    /d                         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 ddl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)SimpleCredential)PasswordDeleteError)PasswordSetError	InitErrorKeyringLocked)
properties)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    8lib/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             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/kwalletd5c                    dt                      vrt          d          	 t          j        t	                                }n8# 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    " 	<:;;;	7/=??;;;CC! 	7 	7 	7s3355666	7 s|,,	|s99;;;	 U   BI3R88>>sCCC 	3ss   !A A8!A33A8c                 H     t                      j        |i | d| _        d S )N)super__init__handle)selfargkw	__class__s      r   r3   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	hasFolderr4   appidreadPasswordListitemsrsplitwritePasswordremoveEntryremoveFolder)	r5   service
old_folder
entry_listentrykeypasswordusernamerets	            r   _migratezDBusKeyring._migrate?   s[   

:ZDD 	M44Z
 J $))++ 	U 	UAh 8$'JJsA$6$6!'j..K(Hdj  !8 UJ**4;
CTTT44Zdj J  M
''ZLLLLL)	M 	M&M Mr9   c                 ,   | 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|z            d }~ww xY w| j         dk     rdS |                     |           dS )Nr   Tr   zorg.kde.KWalletzFailed to open keyring: %s.F)r4   r?   isOpenr   r#   r   
get_objectr'   object_path	InterfaceopennetworkWalletrA   r$   r   rP   )r5   rH   r-   wId
remote_objes         r   	connectedzDBusKeyring.connectedX   s	   ;! 	z  -- to}777	?t7GHHJ
4EFFDJ*//$**B*B*D*Dc4:VVDKK! 	? 	? 	?9A=>>>	? ;? 	5gts   A7C	 	C/C**C/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?   hasEntryr4   rA   readPasswordstrr5   rH   rN   rM   s       r   get_passwordzDBusKeyring.get_passwordk   sx    ~~g&& 	A ?@@@z""4;4:NN 	4:**4;4:VV8}}r9   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]   )r2   get_credentialr[   r	   r?   	entryListr4   rA   r_   r   r`   )r5   rH   rN   rM   r8   s       r   rd   zDBusKeyring.get_credentialu   s      	=77))'8<<<~~g&& 	A ?@@@
,,T['4:NN 	B 	BHz..Wh
 H $CMM3x==AAAAA		B 	Br9   c                     |                      |          st          d          | j                            | j        |||| j                   dS )z,Set password for the username of the serviceCancelled by userN)r[   r   r?   rE   r4   rA   ra   s       r   set_passwordzDBusKeyring.set_password   sM    ~~g&& 	8"#6777
  gx4:VVVVVr9   c                    |                      |          st          d          | j                            | j        ||| j                  st          d          | j                            | j        ||| j                   dS )z4Delete the password for the username of the service.rg   zPassword not foundN)r[   r   r?   r^   r4   rA   rF   )r5   rH   rN   s      r   delete_passwordzDBusKeyring.delete_password   s|    ~~g&& 	;%&9:::z""4;4:NN 	<%&:;;;
t{GXtzJJJJJr9   )__name__
__module____qualname____doc__r   rA   walletr'   rT   r
   classpropertyr/   r3   rP   r[   rb   rd   rh   rj   __classcell__r8   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r9   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<   )r2   r/   )r,   r8   s    r   r/   zDBusKeyringKWallet4.priority   s    ww!##r9   )
rk   rl   rm   rn   r'   rT   r
   rp   r/   rq   rr   s   @r   rt   rt      s\          "H%K$ $ $ $ $ $ $ $ $r9   rt   )r   r)   r   backendr   credentialsr   errorsr   r   r   r	   _compatr
   r   dbus.mainloop.glibr   ImportErrorr   r   r   rt    r9   r   <module>r}      sa   



 				     $ $ $ $ $ $ * * * * * * ( ( ( ( ( ( ? ? ? ? ? ? ? ? ? ?            	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   
; A	A	A	