
    /dM                         d dl m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	 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 ej        e          Z G d	 d
ej        e          ZdS )    )closingN   )backend)
properties)KeyringBackend)SimpleCredential)	InitErrorPasswordDeleteErrorExceptionRaisedContextKeyringLockedc                   Z    e Zd ZdZdZej        d             Zd Zd Z	d Z
d Zd Zd	 Zd
S )KeyringzSecret Service KeyringzPython keyring libraryc                    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|z            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: %s   )
r   secretstorage__name__RuntimeError__version_tuple__r   	dbus_initcheck_service_availability
exceptionsSecretStorageException)clsexc
connectiones       >lib/python3.11/site-packages/keyring/backends/SecretService.pypriorityzKeyring.priority    s   #%% 	#""	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	97888*V3 	FDEEE	M02233 z$?
KK &4                 0 	M 	M 	MG!KLLL	M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|z            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: %s.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_collection3   s    
 %''	Ht344 G*5c4;TUU

*A#FF
0 	H 	H 	HBQFGGG	H!! 	H##%% H#$FGGGs   ?A A;$A66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.unlockF   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_passwordL   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                    ||          }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 '{}' on '{}'T)replaceN)r*   r1   appidformatr   r   create_item)r'   r5   r6   passwordr)   
attributeslabels          r   set_passwordzKeyring.set_passwordU   s    2244
[[(
[KK
+228WEE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   BB
B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   r0   r1   deleter
   r4   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.
        r6   r/   N)schemesschemer1   r*   r   r   r0   r&   get_attributesgetr   r2   r3   )r'   r5   r6   rH   queryr)   r7   r,   s           r   get_credentialzKeyring.get_credentialf   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   classpropertyr   r*   r&   r8   rB   rE   rL    r-   r   r   r      s          $E  $  &> > >9 9 9N N N7 7 7U U U U Ur-   r   )
contextlibr   logging r   _compatr   r   credentialsr   errorsr	   r
   r   r   r   secretstorage.exceptionsr   ImportErrorAttributeError	getLoggerr   logSchemeSelectabler   rQ   r-   r   <module>r^      sb                            $ $ $ $ $ $ * * * * * *           	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	