
    Kih                         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  e j*                  e      Z G d
 dej0                  e      Zy# e$ r Y 0e$ r Y 6w xY w)    N)closing)ExceptionTrap   )backend)KeyringBackend)
properties)SimpleCredential)	InitErrorKeyringLockedPasswordDeleteErrorc                   b    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y)KeyringzSecret Service KeyringzPython keyring libraryreturnc                    t               5 }t        j                   d d d        rt        d      t        j                  dk  rt        d      	 t        t        j                               5 }t        j                  |      st        d      	 d d d        y# 1 sw Y   }xY w# 1 sw Y   yxY w# t        j                  $ r}t        d|       |d }~ww xY w)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       j/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/keyring/backends/SecretService.pypriorityzKeyring.priority!   s    _ 	#""	#788**V3DEE	R0023 z$??
K&4  L 	# 	#  00 	R!EaSIJPQQ	RsA   BB0 -!B$B0 B!$B-)B0 -B0 0CCCc                    t        j                         }	 t        | d      r!t        j                  || j                        }nt        j
                  |      }|j                         r+|j                          |j                         rt        d      |S # t        j                  $ r}t        d| d      |d}~ww xY w)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*55c4;T;TU
*AA#F
 !##%#$FGG 00 	M?s!DE1L	Ms   AB B=(B88B=c                 r    t        |d      r|j                          |j                         rt        d      y )Nr(   zFailed to unlock the item!)r$   r(   r'   r   )r)   items     r   r(   zKeyring.unlockG   s0    4"KKM>> <==     c                 >   | j                         }t        |j                        5  |j                  | j	                  ||            }|D ]<  }| j                  |       |j                         j                  d      c cddd       S  	 ddd       y# 1 sw Y   yxY w)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
Z**+ 	9++DKK,JKE 9D!(//88		9 	99	9 	9 	9s   ABBBc                     | j                         }| j                  ||| j                        }d| d| d}t        |j                        5  |j                  |||d       ddd       y# 1 sw Y   yxY w)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   sz    224
[[(

[K
 
&	;Z**+ 	N""5*h"M	N 	N 	Ns   A,,A5c                 &   | j                         }t        |j                        5  |j                  | j	                  ||            }|D ]  }|j                         c cddd       S  	 ddd       t        d      # 1 sw Y   t        d      xY w)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
Z**+ 	%++DKK,JKE %{{}$	% 	%%	% ""566		% ""566s   8A=(A==Bc                    | j                   | j                     }| j                  ||      }| j                         }t	        |j
                        5  |j                  |      }|D ]h  }| j                  |       |j                         j                  |d         }t        ||j                         j                  d            c cddd       S  	 ddd       y# 1 sw Y   yxY w)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   s     dkk*GX.224
Z**+ 	U++E2E UD!..044VJ5GH'$//2C2J2J72STT	U 	UU	U 	U 	Us   A4CCC#N)r   
__module____qualname____doc__r?   r   classpropertyfloatr    r,   r(   r:   rD   rG   rN    r/   r   r   r      sI     $E  $&>9N7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      sz      (  $  * 	1 g!\Ug&& \U  	 		s   
A' 'A5.A54A5