HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/secretstorage/__pycache__/collection.cpython-38.pyc
U

E�,W��@s�dZddlZddlmZmZddlmZmZddlm	Z	ddl
mZmZm
Z
mZmZmZmZedZedZd	Zd
ZGdd�de�Zdd
d�Zdd�Zddd�Zdd�Zdd�Zdd�ZdS)arCollection 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@sreZdZdZedfdd�Zdd�Zdd�Zdd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zddd�ZdS)rzRepresents a collection.NcCsLt||�}||_||_||_t|t�|_t|tj�|_	|j	j
tddd�dS)N�Label�ss�Z	signature)r�bus�session�collection_pathr�COLLECTION_IFACE�collection_iface�dbus�PROPERTIES_IFACE�collection_props_iface�Get)�selfrrrZcollection_obj�r�:/usr/lib/python3/dist-packages/secretstorage/collection.py�__init__!s
��
�zCollection.__init__cCst|jjtddd��S)zDReturns :const:`True` if item is locked, otherwise
		:const:`False`.ZLockedrr)�boolrrr�rrrr�	is_locked-s
�zCollection.is_lockedcCs|��rtd��dS)zSIf collection is locked, raises
		:exc:`~secretstorage.exceptions.LockedException`.zCollection is locked!N)r!rr rrr�ensure_not_locked3szCollection.ensure_not_lockedcCst|j|jg|�S)aRequests 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
rr)r�callbackrrr�unlock9szCollection.unlockcCs,t|jt�}t|t�}|j|jgdd�dS)zLocks the collection.ZaorN)rrrr�
SERVICE_IFACEZLockr)r�service_obj�
service_ifacerrr�lockAs
zCollection.lockcCs|��|jjdd�dS)z/Deletes the collection and all items inside it.�rN)r"rZDeleter rrr�deleteGszCollection.deleteccs.|jjtddd�D]}t|j||j�VqdS)z3Returns a generator of all items in the collection.ZItemsrrN)rrrrrr)r�	item_pathrrr�
get_all_itemsLs�
zCollection.get_all_itemsccs0|jj|dd�}|D]}t|j||j�VqdS)z^Returns a generator of items with the given attributes.
		`attributes` should be a dictionary.�a{ss}rN)r�SearchItemsrrr)r�
attributes�resultr+rrr�search_itemsRs
�zCollection.search_itemscCs|jjtddd�}t|�S)zReturns the collection label.rrr)rrrr�r�labelrrr�	get_labelZs
�zCollection.get_labelcCs |��|jjtd|dd�dS)z!Sets collection label to `label`.rZssvrN)r"r�Setrr2rrr�	set_label`s

�zCollection.set_labelF�
text/plainc	Csr|��|jst|j�|_t|j||�}tj|dd�}td|td|i}|jj	|||dd�\}}t
|j||j�S)acCreates a new :class:`~secretstorage.item.Item` with given
		`label` (unicode string), `attributes` (dictionary) and `secret`
		(bytestring). If `replace` is :const:`True`, replaces the existing
		item with the same attributes. If `content_type` is given, also
		sets the content type of the secret (``text/plain`` by default).
		Returns the created item.rrz
Item.LabelzItem.Attributesza{sv}(oayays)b)r"rrrr
rZ
DictionaryrrZ
CreateItemr)	rr3r/Zsecret�replaceZcontent_type�
propertiesZnew_item�promptrrr�create_itemfs ��
zCollection.create_item)N)Fr7)�__name__�
__module__�__qualname__�__doc__�DEFAULT_COLLECTIONrr!r"r$r(r*r,r1r4r6r;rrrrrs
�r)cCs�|st|�}td|i}t|t�}t�|t�}|j||dd�\}}t|�dkr\t	|||d�St
||�\}	}
|	rvtd��t	||
|d�S)aCreates a new :class:`Collection` with the given `label` and `alias`
	and returns it. This action requires prompting. If prompt is dismissed,
	raises :exc:`~secretstorage.exceptions.ItemNotFoundException`. This is
	synchronous function, uses loop from GLib API.zCollection.Labelza{sv}sr�)rzPrompt dismissed.)rrrrr�	Interfacer%ZCreateCollection�lenrr	r)rr3�aliasrr9r&r'rr:Z	dismissed�unlockedrrr�create_collection{s
�
rFccs>t|t�}t�|tj�}|jtddd�D]}t||�Vq(dS)z1Returns a generator of all available collections.ZCollectionsrrN)rrrrBrrr%r)rr&Zservice_props_ifacerrrr�get_all_collections�s
��
rGcCs2z
t|�WStk
r,t|dd|�YSXdS)zAReturns the default collection. If it doesn't exist,
	creates it.ZDefault�defaultN)rrrF)rrrrr�get_default_collection�s
�rIcCsfz
t|�WStk
rYnXzt|t�WStk
r@YnXtt|��}|rZ|dStd��dS)z�Returns any collection, in the following order of preference:

	- The default collection;
	- The "session" collection (usually temporary);
	- The first collection in the collections list.rzNo collections found.N)rr�SESSION_COLLECTION�listrG)r�collectionsrrr�get_any_collection�s
rMcCsBt|t�}t�|t�}|j|dd�}t|�dkr8td��t||�S)z�Returns the collection with the given `alias`. If there is no
	such collection, raises
	:exc:`~secretstorage.exceptions.ItemNotFoundException`.�srrAzNo collection with such alias.)	rrrrBr%Z	ReadAliasrCrr)rrDr&r'rrrr�get_collection_by_alias�s
rOccsFt|t�}t�|t�}|j|dd�\}}||D]}t||�Vq0dS)zpReturns a generator of items in all collections with the given
	attributes. `attributes` should be a dictionary.r-rN)rrrrBr%r.r)rr/r&r'�lockedrEr+rrrr1�s
�
r1)r)N)N)r?rZsecretstorage.definesrrZsecretstorage.exceptionsrrZsecretstorage.itemrZsecretstorage.utilrrr	r
rrr
rr%r@rJ�objectrrFrGrIrMrOr1rrrr�<module>s $]