
    .Ph_                    b   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  e            5 Z	 d d	lmZmZ ej         n# e$ r d dlZd dlZej         Y nw xY wddd           n# 1 swxY w Y    ej        e          Z G d
 d          Z G d de          Z G d de          ZdS )    )annotationsN)ExceptionTrap   )KeyringBackend)
properties)SimpleCredential)PasswordDeleteError)
pywintypes	win32credc                      e Zd ZddZd ZdS )PersistenceNc                8    t          |dt          j                  S )N_persist)getattrr   CRED_PERSIST_ENTERPRISE)selfkeyringtypes      X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/keyring/backends/Windows.py__get__zPersistence.__get__   s    w
I,MNNN    c                    t          |t                    r@d|                    dd                                          z   }t	          t
          |          }||_        dS )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__zPersistence.__set__"   sW     eS!! 	-"U]]3%<%<%B%B%D%DDDIt,,E r   N)__name__
__module____qualname__r   r"    r   r   r   r      s;        O O O O
! 
! 
! 
! 
!r   r   c                  $    e Zd Zed             ZdS )DecodingCredentialc                    | d         }	 |                     d          S # t          $ r4 |                     d          }t                              d           |cY S w xY w)zM
        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    zDecodingCredential.value0   s}    
 $%	%;;x(((! 	% 	% 	% $G 4 4KKB   %$$$	%s    ;AAN)r$   r%   r&   propertyr    r'   r   r   r)   r)   /   s-        % % X% % %r   r)   c                      e Zd ZdZ e            Zej        dd            Ze	d             Z
d ZddZd Zd Zd Zd Zd Zd ZdS )WinVaultKeyringaf  
    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}
    returnfloatc                2    t           rt          d          dS )zA
        If available, the preferred backend on Windows.
        zRequires Windows and pywin32   )missing_depsRuntimeError)clss    r   priorityzWinVaultKeyring.priorityU   s     
  	?=>>>qr   c                    |  d| S )N@r'   )usernameservices     r   _compound_namezWinVaultKeyring._compound_name^   s    &&W&&&r   c                @    |                      ||          }|o|j        S r#   )_resolve_credentialr    r   r@   r?   ress       r   get_passwordzWinVaultKeyring.get_passwordb   s$    &&w99 sy r   r@   r   r?   
str | NoneDecodingCredential | Nonec                    |                      |          }|r|r5|d         |k    r)|                      |                     ||                    }|S NUserName)_read_credentialrA   rD   s       r   rC   z#WinVaultKeyring._resolve_credentialf   s^     ##G,, 	Ph 	P3z?h#>#>''(;(;Hg(N(NOOC
r   c                    	 t          j        t           j        |          }n4# t          j        $ r"}|j        dk    r|j        dk    rY d }~d S  d }~ww xY wt          |          S )NType
TargetName  CredRead)r   rR   CRED_TYPE_GENERICr
   errorwinerrorfuncnamer)   )r   targetrE   es       r   rL   z WinVaultKeyring._read_credentialp   s    	$0V  CC  	 	 	zT!!ajJ&>&>ttttt	 "#&&&s    # AAAAc                    |                      |          }|r:|d         }|                     ||          }|                     |||j                   |                     ||t	          |                     d S rJ   )rL   rA   _set_passwordr    r   )r   r@   r?   passwordexisting_pwexisting_usernamerW   s          r   set_passwordzWinVaultKeyring.set_password{   s    ++G44 	 +J 7(():GDDF!!  
 	7Hc(mm<<<<<r   c                x    t          t          j        |||d| j                  }t          j        |d           d S )NzStored using python-keyring)rO   rP   rK   r+   CommentPersistr   )dictr   rS   persist	CredWrite)r   rW   r?   r[   
credentials        r   rZ   zWinVaultKeyring._set_password   sH    ,#1L
 
 

 	J*****r   c                    |                      ||          }d}||fD ]<}|                     |          }|r#|d         |k    rd}|                     |           =|st          |          d S )NFrK   T)rA   rL   _delete_passwordr	   )r   r@   r?   compounddeletedrW   r\   s          r   delete_passwordzWinVaultKeyring.delete_password   s    &&x99x' 	. 	.F//77K .{:6(BB%%f--- 	/%g...	/ 	/r   c                    	 t          j        t           j        |           d S # t          j        $ r"}|j        dk    r|j        dk    rY d }~d S  d }~ww xY w)NrN   rQ   
CredDelete)r   rl   rS   r
   rT   rU   rV   )r   rW   rX   s      r   rg   z WinVaultKeyring._delete_password   sq    	 i&AfUUUUUU 	 	 	zT!!ajL&@&@	s    $ AAAAc                h    |                      ||          }|ot          |d         |j                  S rJ   )rC   r   r    rD   s       r   get_credentialzWinVaultKeyring.get_credential   s3    &&w99C'JCCCr   N)r5   r6   )r@   r   r?   rG   r5   rH   )r$   r%   r&   __doc__r   rc   r   classpropertyr<   staticmethodrA   rF   rC   rL   r^   rZ   rj   rg   rn   r'   r   r   r4   r4   A   s         " kmmG    ' ' \'! ! !   	' 	' 	'= = =	+ 	+ 	+	/ 	/ 	/  D D D D Dr   r4   )
__future__r   loggingjaraco.contextr   backendr   compatr   credentialsr   errorsr	   r9   win32ctypes.pywin32r
   r   r$   ImportError	getLoggerr.   r   rb   r)   r4   r'   r   r   <module>r|      s   " " " " " "  ( ( ( ( ( ( $ $ $ $ $ $       * * * * * * ( ( ( ( ( (]__ ======== 	    	               g!!! ! ! ! ! ! ! !"% % % % % % % %$gD gD gD gD gDn gD gD gD gD gDs4   A+AA+AA+AA++A/2A/