
    .Phh                         d dl Z d dlmZ d dlmZ ddlm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Zd dlmZ n# e$ r Y n
e$ r Y nw xY w e j        e          Z G d
 dej        e          ZdS )    N)closing)ExceptionTrap   )backend)KeyringBackend)
properties)SimpleCredential)	InitErrorKeyringLockedPasswordDeleteErrorc                   `    e Zd ZdZdZej        defd            Zd Z	d Z
d Zd Zd	 Zd
 ZdS )KeyringzSecret Service KeyringzPython keyring libraryreturnc                    t                      5 }t          j         d d d            n# 1 swxY w Y   |rt          d          t          j        dk     rt          d          	 t          t          j                              5 }t          j        |          st          d          	 d d d            n# 1 swxY w Y   n*# t          j	        $ r}t          d|           |d }~ww xY wdS )NzSecretStorage required)   r   z#SecretStorage 3.2 or newer requiredzJThe Secret Service daemon is neither running nor activatable through D-Busz$Unable to initialize SecretService:    )
r   secretstorage__name__RuntimeError__version_tuple__r   	dbus_initcheck_service_availability
exceptionsSecretStorageException)clsexc
connectiones       ^/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/keyring/backends/SecretService.pypriorityzKeyring.priority!   s   __ 	#""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	97888*V33DEEE	R02233 z$?
KK &4                 0 	R 	R 	RIaIIJJPQQ	RqsH   (,,$ C $B5)C 5B99C <B9=C C(C##C(c                    t          j                    }	 t          | d          rt          j        || j                  }nt          j        |          }n+# t          j        $ r}t          d| d          |d}~ww xY w|	                                r7|
                                 |	                                rt          d          |S )zIf self.preferred_collection contains a D-Bus path,
        the collection at that address is returned. Otherwise,
        the default collection is returned.
        preferred_collectionz!Failed to create the collection: .Nz Failed to unlock the collection!)r   r   hasattr
Collectionr"   get_default_collectionr   r   r
   	is_lockedunlockr   )selfbus
collectionr   s       r   get_preferred_collectionz Keyring.get_preferred_collection4   s    
 %''	Mt344 G*5c4;TUU

*A#FF
0 	M 	M 	MDDDDEE1L	M!! 	H##%% H#$FGGGs   ?A A=$A88A=c                     t          |d          r|                                 |                                rt          d          d S )Nr(   zFailed to unlock the item!)r$   r(   r'   r   )r)   items     r   r(   zKeyring.unlockG   sL    4"" 	KKMMM>> 	> <===	> 	>    c                 x   |                                  }t          |j                  5  |                    |                     ||                    }|D ]K}|                     |           |                                                    d          c cddd           S 	 ddd           dS # 1 swxY w Y   dS )z,Get password of the username for the serviceutf-8N)r,   r   r   search_items_queryr(   
get_secretdecoder)   serviceusernamer+   itemsr.   s         r   get_passwordzKeyring.get_passwordM   s   2244
Z*++ 	9 	9++DKK,J,JKKE 9 9D!!!((//8888		9 	9 	9 	9 	9 	9 	9 	99	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9 	9s   A+B//B36B3c                    |                                  }|                     ||| j                  }d| d| d}t          |j                  5  |                    |||d           ddd           dS # 1 swxY w Y   dS )z,Set password for the username of the service)applicationzPassword for 'z' on ''T)replaceN)r,   r3   appidr   r   create_item)r)   r7   r8   passwordr+   
attributeslabels          r   set_passwordzKeyring.set_passwordV   s    2244
[[(
[KK
;;;;;;Z*++ 	N 	N""5*h"MMM	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	Ns   A66A:=A:c                 @   |                                  }t          |j                  5  |                    |                     ||                    }|D ]#}|                                c cddd           S 	 ddd           n# 1 swxY w Y   t          d          )z/Delete the stored password (only the first one)NzNo such password!)r,   r   r   r2   r3   deleter   r6   s         r   delete_passwordzKeyring.delete_password^   s    2244
Z*++ 	% 	%++DKK,J,JKKE % %{{}}$$	% 	% 	% 	% 	% 	% 	% 	%%	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% ""5666s   ABB
B
c                    | j         | j                 }|                     ||          }|                                 }t	          |j                  5  |                    |          }|D ]}|                     |           |                                	                    |d                   }t          ||                                                    d                    c cddd           S 	 ddd           dS # 1 swxY w Y   dS )aY  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 use get_password
        and return a SimpleCredential containing  the username and password
        Otherwise, it will return the first username and password combo that it finds.
        r8   r1   N)schemesschemer3   r,   r   r   r2   r(   get_attributesgetr	   r4   r5   )r)   r7   r8   rJ   queryr+   r9   r.   s           r   get_credentialzKeyring.get_credentialg   sz    dk*GX..2244
Z*++ 	U 	U++E22E U UD!!!..0044VJ5GHH'$//2C2C2J2J72S2STTTT	U 	U 	U 	U 	U 	U 	U 	UU	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	U 	Us   BC>>DDN)r   
__module____qualname____doc__r?   r   classpropertyfloatr    r,   r(   r:   rD   rG   rN    r/   r   r   r      s          $E    $  &> > >9 9 9N N N7 7 7U U U U Ur/   r   )logging
contextlibr   jaraco.contextr    r   r   compatr   credentialsr	   errorsr
   r   r   r   secretstorage.exceptionsr   ImportErrorAttributeError	getLoggerr   logSchemeSelectabler   rT   r/   r   <module>rb      sj          ( ( ( ( ( (       $ $ $ $ $ $       * * * * * *         	1111111 	 	 	D 	 	 	D	 g!!\U \U \U \U \Ug& \U \U \U \U \Us   
? AAA