
    k7i_                    d   S SK Jr  S SKrS SKJr  SSKJr  SSKJr  SSK	J
r
  SSKJr  \" 5        r S S	KJrJr  \R"                    SSS5        \R&                  " \5      r " S
 S5      r " S S\5      r " S S\5      rg! \ a    S SKrS SKr\R"                     NWf = f! , (       d  f       Na= f)    )annotationsN)ExceptionTrap   )KeyringBackend)
properties)SimpleCredential)PasswordDeleteError)
pywintypes	win32credc                  $    \ rS rSrSS jrS rSrg)Persistence   Nc                8    [        US[        R                  5      $ )N_persist)getattrr   CRED_PERSIST_ENTERPRISE)selfkeyringtypes      R/home/james-whalen/.local/lib/python3.13/site-packages/keyring/backends/Windows.py__get__Persistence.__get__   s    w
I,M,MNN    c                    [        U[        5      (       a3  SUR                  SS5      R                  5       -   n[	        [
        U5      nX!l        g)z
Set the persistence value on the Keyring. Value may be
one of the win32cred.CRED_PERSIST_* constants or a
string representing one of those constants. For example,
'local machine' or 'session'.
CRED_PERSIST_ _N)
isinstancestrreplaceupperr   r   r   )r   r   valueattrs       r   __set__Persistence.__set__"   sA     eS!!"U]]3%<%B%B%DDDIt,E r    N)__name__
__module____qualname____firstlineno__r   r$   __static_attributes__r&   r   r   r   r      s    O
!r   r   c                  $    \ rS rSr\S 5       rSrg)DecodingCredential/   c                    U S   n UR                  S5      $ ! [         a+    UR                  S5      n[        R                  S5        Us $ f = f)z=
Attempt to decode the credential blob as UTF-16 then UTF-8.
CredentialBlobzutf-16zutf-8zjRetrieved a UTF-8 encoded credential. Please be aware that this library only writes credentials in UTF-16.)decodeUnicodeDecodeErrorlogwarning)r   creddecoded_cred_utf8s      r   r"   DecodingCredential.value0   s[    
 $%	%;;x((! 	% $G 4KKB %$	%s    2AAr&   N)r(   r)   r*   r+   propertyr"   r,   r&   r   r   r.   r.   /   s    % %r   r.   c                      \ rS rSrSr\" 5       r\R                  SS j5       r	\
S 5       rS r      SS jrS rS rS	 rS
 rS rS rSrg)WinVaultKeyringA   a6  
WinVaultKeyring stores encrypted passwords using the Windows Credential
Manager.

Requires pywin32

This backend does some gymnastics to simulate multi-user support,
which WinVault doesn't support natively. See
https://github.com/jaraco/keyring/issues/47#issuecomment-75763152
for details on the implementation, but here's the gist:

Passwords are stored under the service name unless there is a collision
(another password with the same service name but different user name),
in which case the previous password is moved into a compound name:
{username}@{service}
c                0    [         (       a  [        S5      eg)z1
If available, the preferred backend on Windows.
zRequires Windows and pywin32   )missing_depsRuntimeError)clss    r   priorityWinVaultKeyring.priorityU   s    
 <=>>r   c                    U  SU 3$ )N@r&   )usernameservices     r   _compound_nameWinVaultKeyring._compound_name^   s    1WI&&r   c                N    U R                  X5      nU=(       a    UR                  $ r'   )_resolve_credentialr"   r   rG   rF   ress       r   get_passwordWinVaultKeyring.get_passwordb   s!    &&w9 syy r   c                    U R                  U5      nU(       a  U(       a)  US   U:w  a   U R                  U R                  X!5      5      nU$ NUserName)_read_credentialrH   rL   s       r   rK   #WinVaultKeyring._resolve_credentialf   sD     ##G,h3z?h#>''(;(;H(NOC
r   c                     [         R                  " [         R                  US9n[        U5      $ ! [        R                   a+  nUR
                  S:X  a  UR                  S:X  a   S nAg e S nAff = f)NType
TargetName  CredRead)r   rZ   CRED_TYPE_GENERICr
   errorwinerrorfuncnamer.   )r   targetrM   es       r   rS    WinVaultKeyring._read_credentialp   sd    	$$00VC "#&&	  	zzT!ajjJ&>	s   #0 A/ A*)A**A/c                    U R                  U5      nU(       a3  US   nU R                  XQ5      nU R                  UUUR                  5        U R                  X[	        U5      5        g rQ   )rS   rH   _set_passwordr"   r   )r   rG   rF   passwordexisting_pwexisting_usernamer_   s          r   set_passwordWinVaultKeyring.set_password{   sd    ++G4 +J 7(():DF!!!
 	7c(m<r   c           	     ~    [        [        R                  UUUSU R                  S9n[        R                  " US5        g )NzStored using python-keyring)rW   rX   rR   r1   CommentPersistr   )dictr   r[   persist	CredWrite)r   r_   rF   rd   
credentials        r   rc   WinVaultKeyring._set_password   s:    ,,#1LL

 	J*r   c                    U R                  X!5      nSnX4 H;  nU R                  U5      nU(       d  M  US   U:X  d  M(  SnU R                  U5        M=     U(       d  [        U5      eg )NFrR   T)rH   rS   _delete_passwordr	   )r   rG   rF   compounddeletedr_   re   s          r   delete_passwordWinVaultKeyring.delete_password   sm    &&x9'F//7K{{:6(B%%f-	 (
 %g.. r   c                     [         R                  " [         R                  US9  g ! [        R                   a+  nUR
                  S:X  a  UR                  S:X  a   S nAg e S nAff = f)NrV   rY   
CredDelete)r   rx   r[   r
   r\   r]   r^   )r   r_   r`   s      r   rr    WinVaultKeyring._delete_password   sP    	  i&A&AfU 	zzT!ajjL&@	s   #& A% A A  A%c                h    U R                  X5      nU=(       a    [        US   UR                  5      $ rQ   )rK   r   r"   rL   s       r   get_credentialWinVaultKeyring.get_credential   s-    &&w9C'JCCr   r&   N)returnfloat)rG   r   rF   z
str | Noner}   zDecodingCredential | None)r(   r)   r*   r+   __doc__r   rm   r   classpropertyrB   staticmethodrH   rN   rK   rS   rg   rc   ru   rr   r{   r,   r&   r   r   r;   r;   A   s}    " mG  ' '!&0	"	'=	+	/Dr   r;   )
__future__r   loggingjaraco.contextr   backendr   compatr   credentialsr   errorsr	   r?   win32ctypes.pywin32r
   r   r(   ImportError	getLoggerr4   r   rl   r.   r;   r&   r   r   <module>r      s    "  ( $  * (_= 	  !! !"% %$gDn gD]   	 _s(   B!BBB!BB!!
B/