o
    œ¨Êhw  ã                   @   sž   d dl Z d dlZd dlZddlmZ ddlmZ ddlmZm	Z	m
Z
 zd dlZd dlmZ W n ey7   Y n	 ey?   Y nw e  e¡ZG dd„ deƒZdS )é    Né   )Ú
properties)ÚKeyringBackend)Ú	InitErrorÚPasswordDeleteErrorÚExceptionRaisedContextc                   @   sX   e Zd ZdZej ejd ¡pdZ	e
jedd„ ƒƒZdd„ Zdd	„ Zd
d„ Zdd„ ZdS )ÚKeyringzSecret Service Keyringr   zPython keyring libraryc              
   C   sŽ   t ƒ �}tj W d   ƒ n1 sw   Y  |rtdƒ‚ttdƒs%tdƒ‚zt ¡ }tt |¡ƒ W dS  tj	yF } ztd| ƒ‚d }~ww )NzSecretStorage requiredÚget_default_collectionz#SecretStorage 1.0 or newer requiredz&Unable to initialize SecretService: %sé   )
r   ÚsecretstorageÚ__name__ÚRuntimeErrorÚhasattrÚ	dbus_initÚlistÚget_all_collectionsÚ
exceptionsÚ"SecretServiceNotAvailableException)ÚclsÚexcÚbusÚe© r   úP/var/www/html/env/lib/python3.10/site-packages/keyring/backends/SecretService.pyÚpriority   s"   ÿ
ýÿ€ÿzKeyring.priorityc              
   C   s|   t  ¡ }zt| dƒrt  || j¡}nt  |¡}W n tjy+ } ztd| ƒ‚d}~ww | 	¡ r<| 
¡  | 	¡ r<tdƒ‚|S )zŸIf 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   r   Ú
Collectionr   r	   r   ÚSecretStorageExceptionr   Ú	is_lockedÚunlock)Úselfr   Ú
collectionr   r   r   r   Úget_preferred_collection,   s"   
ÿ
€€ÿz Keyring.get_preferred_collectionc                 C   s\   |   ¡ }| ||dœ¡}|D ]}t|dƒr#| ¡ r#| ¡ d r#tdƒ‚| ¡  d¡  S dS )z5Get password of the username for the service
        ©ÚusernameÚservicer   r   zfailed to unlock itemzutf-8N)r"   Úsearch_itemsr   r   r   r   Ú
get_secretÚdecode©r    r%   r$   r!   ÚitemsÚitemr   r   r   Úget_password?   s   ÿ
üzKeyring.get_passwordc                 C   s8   |   ¡ }| j||dœ}d||f }|j|||dd� dS )z5Set password for the username of the service
        )Úapplicationr%   r$   zPassword for '%s' on '%s'T)ÚreplaceN)r"   ÚappidÚcreate_item)r    r%   r$   Úpasswordr!   Ú
attributesÚlabelr   r   r   Úset_passwordK   s   ýzKeyring.set_passwordc                 C   s4   |   ¡ }| ||dœ¡}|D ]}| ¡   S tdƒ‚)z8Delete the stored password (only the first one)
        r#   zNo such password!)r"   r&   Údeleter   r)   r   r   r   Údelete_passwordW   s   ÿzKeyring.delete_passwordN)r   Ú
__module__Ú__qualname__Ú__doc__ÚosÚpathÚbasenameÚsysÚargvr/   r   ÚClassPropertyÚclassmethodr   r"   r,   r4   r6   r   r   r   r   r      s    r   )Úloggingr=   r:   Úutilr   Úbackendr   Úerrorsr   r   r   r   Úsecretstorage.exceptionsr   ÚImportErrorÚAttributeErrorÚ	getLoggerr   Úlogr   r   r   r   r   Ú<module>   s     þ
