File: //lib/python3/dist-packages/keyring/backends/__pycache__/SecretService.cpython-38.pyc
U
ۦ�\v
� @ s� d dl Z ddlmZ ddlmZ ddlmZmZmZm Z zd dl
Z
d dlmZ W n& e
k
rd Y n ek
rv Y nX e �e�ZG dd� de�ZdS )� N� )�
properties)�KeyringBackend)� InitError�PasswordDeleteError�ExceptionRaisedContext�
KeyringLockedc @ sF e Zd ZdZdZejedd� ��Zdd� Z dd� Z
d d
� Zdd� Zd
S )�KeyringzSecret Service KeyringzPython keyring libraryc
C s� t � �}tj W 5 Q R X |r$td��ttd�s6td��zt�� }tt�|�� W n0 tj k
r� } ztd| ��W 5 d }~X Y nX dS )NzSecretStorage required�get_default_collectionz#SecretStorage 1.0 or newer requiredz&Unable to initialize SecretService: %s� )
r �
secretstorage�__name__�RuntimeError�hasattr� dbus_init�listZget_all_collections�
exceptions�SecretStorageException)�cls�exc�bus�e� r �@/usr/lib/python3/dist-packages/keyring/backends/SecretService.py�priority s
�zKeyring.priorityc
C s� t �� }z(t| d�r$t �|| j�}n
t �|�}W n0 tjk
r` } ztd| ��W 5 d}~X Y nX |� � r�|�
� |� � r�td��|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 r r � is_locked�unlockr )�selfr �
collectionr r r r �get_preferred_collection) s
�z Keyring.get_preferred_collectionc C sX | � � }|�||d��}|D ]6}t|d�r2|�� |�� rBtd��|�� �d� S dS )z5Get password of the username for the service
��username�servicer zFailed to unlock the item!zutf-8N)r! �search_itemsr r r r Z
get_secret�decode�r r$ r# r �items�itemr r r �get_password= s �
zKeyring.get_passwordc C s8 | � � }| j||d�}d||f }|j|||dd� dS )z5Set password for the username of the service
)Zapplicationr$ r# zPassword for '%s' on '%s'T)�replaceN)r! �appidZcreate_item)r r$ r# Zpasswordr Z
attributesZlabelr r r �set_passwordJ s �zKeyring.set_passwordc C s8 | � � }|�||d��}|D ]}|�� S td��dS )z8Delete the stored password (only the first one)
r"