
    .Ph6                        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 dZ	 d dlZd d	lmZmZ  ej        d
d           d dlmZ dZn# eeef$ r Y nw xY w e j        e          Z G d dej        e          ZdS )    N   )backend)KeyringBackend)
properties)SimpleCredential)KeyringLockedPasswordDeleteErrorPasswordSetErrorF)GioGLibSecret1)r   Tc                       e Zd ZdZdZed             Zej        d             Z	ej
        defd            Zd Zd Zd	 Zd
 ZdS )Keyringzlibsecret KeyringzPython keyring libraryc           	          t           j                            dt           j        j        |                     t           j        j        t           j        j        t           j        j                            S )Nzorg.freedesktop.Secret.Genericapplication)r   SchemanewSchemaFlagsNONE_querySchemaAttributeTypeSTRINGselfs    Z/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/keyring/backends/libsecret.pyschemazKeyring.schema!   sY    }  ,#KK*1*1"6=   
 
 	
    c                     t           j        S )N)r   COLLECTION_DEFAULTr   s    r   
collectionzKeyring.collection-   s    ((r   returnc                     t           st          d          	 t          j                            t          j        j        d            n'# t          j        $ r}t          d          |d }~ww xY wdS )Nzlibsecret requiredz*Can't open a session to the secret serviceg333333@)		availableRuntimeErrorr   Serviceget_syncServiceFlagsOPEN_SESSIONr   Error)clserrors     r   priorityzKeyring.priority1   s~     	53444	XN##F$7$DdKKKKz 	X 	X 	XKLLRWW	X ss   /A A,A''A,c                 x   |                      ||| j                  }	 t          j        | j        |t          j        j        d          }na# t          j        $ rO}t          j	        d          }|
                    |t          j        j                  rt          d          | d}~ww xY w|D ]}	 |                                                                c S # t          j        $ rO}t          j	        d          }|
                    |t          j        j                  rt          d          | d}~ww xY wdS )z,Get password of the username for the servicer   Ng-io-error-quarkFailed to unlock the item!secret-error)r   appidr   password_search_syncr   SearchFlagsUNLOCKr   r+   quark_try_stringmatchesr   IOErrorEnumFAILEDr   retrieve_secret_syncget_text	IS_LOCKED)r   serviceusername
attributesitemsr-   quarkitems           r   get_passwordzKeyring.get_password>   sN   [[(
[KK
	/Z);)BD EE z 	 	 	)*<==E}}UCO$:;; M#$@AAuL		
  	 	D0022;;=====:   -n====(>?? Q'(DEE5P		 	s1   +A B)A
B$$B)1%CD7(A
D22D7c                    |                      ||| j                  }d| d| d}	 t          j        | j        || j        ||d          }n# t          j        $ r}t          j        d          }|	                    |t          j        j
                  rt          d          |t          j        d          }|	                    |t          j        j                  rt          d          | d}~ww xY w|st          d	          dS )
z,Set password for the username of the servicer   zPassword for 'z' on ''Nr2   z Failed to unlock the collection!r0   zFailed to store password!)r   r3   r   password_store_syncr   r"   r   r+   r7   r8   r=   r   r   r9   r:   r
   )	r   r>   r?   passwordr@   labelstoredr-   rB   s	            r   set_passwordzKeyring.set_passwordS   s$   [[(
[KK
;;;;;;	/Z%4 FF z 	 	 	).99E}}UFL$:;; S#$FGGUR)*<==E}}UCO$:;; S#$FGGUR	  	@"#>???	@ 	@s   #A C3BC..C3c                    |                      ||| j                  }	 t          j        | j        |t          j        j        d          }na# t          j        $ rO}t          j	        d          }|
                    |t          j        j                  rt          d          | d}~ww xY w|D ]}	 t          j        | j        |                                d          }na# t          j        $ rO}t          j	        d          }|
                    |t          j        j                  rt          d          | d}~ww xY w|c S t%          d          )z/Delete the stored password (only the first one)r   Nr0   r1   r2   zNo such password!)r   r3   r   r4   r   r5   r6   r   r+   r7   r8   r   r9   r:   r   password_clear_syncget_attributesr=   r	   )	r   r>   r?   r@   rA   r-   rB   rC   removeds	            r   delete_passwordzKeyring.delete_passwordf   se   [[(
[KK
	/Z);)BD EE z 	 	 	)*<==E}}UCO$:;; M#$@AAuL		
  
	 
	D 4K!4!4!6!6  :   -n====(>?? Q'(DEE5P	
 NNN!"5666s1   +A B)A
B$$B)1-CD=.A
D88D=c                    |                      ||          }	 t          j        | j        |t          j        j        d          }na# t          j        $ rO}t          j        d          }|	                    |t          j        j                  rt          d          | d}~ww xY w|D ]}|                                                    d          }	 t!          ||                                                                          c S # t          j        $ rO}t          j        d          }|	                    |t          j        j                  rt          d          | d}~ww xY wdS )aW  Get the first username and password for a service.
        Return 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.
        Nr0   r1   r?   r2   )r   r   r4   r   r5   r6   r   r+   r7   r8   r   r9   r:   r   rN   getr   r;   r<   r=   )r   r>   r?   queryrA   r-   rB   rC   s           r   get_credentialzKeyring.get_credential   s    GX..	/UF$6$=t EE z 	 	 	)*<==E}}UCO$:;; M#$@AAuL		
  
	 
	D**,,00<<H'd7799BBDD     :   -n====(>?? Q'(DEE5P	
	 
	s1   +A B"A
BB"3DE%A
E  E%N)__name__
__module____qualname____doc__r3   propertyr   r   NonDataPropertyr"   classpropertyfloatr.   rD   rK   rP   rT    r   r   r   r      s        $E	
 	
 X	
 ) )  ) 
 
 
 
 
  *@ @ @&7 7 72    r   r   )logging r   r   compatr   credentialsr   errorsr   r	   r
   r%   gigi.repositoryr   r   require_versionr   AttributeErrorImportError
ValueError	getLoggerrU   logSchemeSelectabler   r]   r   r   <module>rl      sa          $ $ $ $ $ $       * * * * * *          			III''''''''Bx%%%$$$$$$IIZ0 	 	 	D	 g!!    g&     s   %A AA