File: //lib/python3/dist-packages/secretstorage/__pycache__/collection.cpython-38.pyc
U
E�,W� � @ s� d Z ddlZddlmZmZ ddlmZmZ ddlm Z ddl
mZmZm
Z
mZmZmZmZ ed Zed Zd Zd
ZG dd� de�Zdd
d�Zdd� Zddd�Zdd� Zdd� Zdd� ZdS )ar Collection is a place where secret items are stored. Normally, only
the default collection should be used, but this module allows to use any
registered collection. Use :func:`get_default_collection` to get the
default collection (and create it, if necessary).
Collections are usually automatically unlocked when user logs in, but
collections can also be locked and unlocked using
:meth:`Collection.lock` and :meth:`Collection.unlock` methods (unlocking
requires showing the unlocking prompt to user and can be synchronous or
asynchronous). Creating new items and editing existing ones is possible
only in unlocked collection.� N)� SS_PREFIX�SS_PATH)�LockedException�ItemNotFoundException)�Item)�bus_get_object�InterfaceWrapper�exec_prompt_glib�
format_secret�open_session�
to_unicode�unlock_objects�
CollectionZServicez(/org/freedesktop/secrets/aliases/defaultz+/org/freedesktop/secrets/collection/sessionc @ sr e Zd ZdZedfdd�Zdd� Zdd� Zdd d
�Zdd� Z d
d� Z
dd� Zdd� Zdd� Z
dd� Zddd�ZdS )r zRepresents a collection.Nc C sL t ||�}|| _|| _|| _t|t�| _t|tj�| _ | j j
tddd� d S )N�Label�ss�Z signature)r �bus�session�collection_pathr �COLLECTION_IFACE�collection_iface�dbus�PROPERTIES_IFACE�collection_props_iface�Get)�selfr r r Zcollection_obj� r �:/usr/lib/python3/dist-packages/secretstorage/collection.py�__init__! s
��
�zCollection.__init__c C s t | jjtddd��S )zDReturns :const:`True` if item is locked, otherwise
:const:`False`.ZLockedr r )�boolr r r �r r r r � is_locked- s
�zCollection.is_lockedc C s | � � rtd��dS )zSIf collection is locked, raises
:exc:`~secretstorage.exceptions.LockedException`.zCollection is locked!N)r! r r r r r �ensure_not_locked3 s zCollection.ensure_not_lockedc C s t | j| jg|�S )a Requests unlocking the collection. If `callback` is specified,
calls it when unlocking is complete (see
:func:`~secretstorage.util.exec_prompt` description for details).
Otherwise, uses loop from GLib API and returns a boolean
representing whether the operation was dismissed.)r
r r )r �callbackr r r �unlock9 s zCollection.unlockc C s, t | jt�}t|t�}|j| jgdd� dS )zLocks the collection.Zaor N)r r r r �
SERVICE_IFACEZLockr )r �service_obj�
service_ifacer r r �lockA s
zCollection.lockc C s | � � | jjdd� dS )z/Deletes the collection and all items inside it.� r N)r"