/usr/lib/python3/dist-packages/secretstorage/__pycache__
Edit: /usr/lib/python3/dist-packages/secretstorage/__pycache__/collection.cpython-310.pyc (8361B)
o
j_ @ sN d Z ddlmZmZmZ ddlmZ ddlmZm Z ddl
mZ ddlm
Z
mZmZ ddlmZ ddlmZmZmZmZmZ ed Zed
ZdZdZG d
d d eZ d"dedededee def
ddZdedee fddZ d#dedee defddZ!dedefddZ"dededefddZ#dedeeef dee fd d!Z$dS )$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. )DictIteratorOptional)DBusConnection) SS_PREFIXSS_PATH)Session)LockedExceptionItemNotFoundExceptionPromptDismissedException)Item)DBusAddressWrapperexec_prompt
format_secretopen_sessionunlock_objects
CollectionServicez(/org/freedesktop/secrets/aliases/defaultz+/org/freedesktop/secrets/collection/sessionc
@ s e Zd ZdZedfdededee ddfddZ de
fd d
Zd$ddZde
fd
dZ
d$ddZd$ddZdee fddZdeeef dee fddZdefddZdeddfddZ d%dedeeef ded e
d!edefd"d#ZdS )&r zRepresents a collection.N
connectioncollection_pathsessionreturnc C s0 || _ || _|| _t|t|| _| jd d S )NLabel)r r r r
COLLECTION_IFACE_collectionget_property)selfr r r r :/usr/lib/python3/dist-packages/secretstorage/collection.py__init__$ s zCollection.__init__c C s t | jdS )zDReturns :const:`True` if item is locked, otherwise
:const:`False`.Locked)boolr r r r r r is_locked. s zCollection.is_lockedc C s | rtddS )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| jgS )a Requests unlocking the collection.
Returns a boolean representing whether the prompt has been
dismissed; that means :const:`False` on successful unlocking
and :const:`True` if it has been dismissed.
.. versionchanged:: 3.0
No longer accepts the ``callback`` argument.
)r r r r" r r r unlock9 s
zCollection.unlockc C s$ t tt| j}|dd| jg dS )zLocks the collection.LockaoN)r
r
SERVICE_IFACEr callr )r servicer r r lockE s zCollection.lockc C sD | | jdd\}|dkrt| j|\}}|r tddS dS )z/Deletes the collection and all items inside it.Delete /Prompt dismissed.N)r$ r r) r r r )r prompt dismissed_resultr r r deleteJ s zCollection.deletec c s* | j dD ]}t| j|| jV qdS )z3Returns a generator of all items in the collection.ItemsN)r r r r r )r item_pathr r r
get_all_itemsS s zCollection.get_all_items
attributesc c s4 | j dd|\}|D ]}t| j|| jV qdS )z^Returns a generator of items with the given attributes.
`attributes` should be a dictionary.SearchItemsa{ss}N)r r) r r r )r r7 resultr5 r r r search_itemsX s
zCollection.search_itemsc C s | j d}t|ts
J |S )zReturns the collection label.r )r r
isinstancestrr labelr r r get_label_ s zCollection.get_labelr? c C s | | jdd| dS )z!Sets collection label to `label`.r sN)r$ r set_propertyr> r r r set_labele s zCollection.set_labelF
text/plainsecretreplacecontent_typec
C sl | | js
t| j| _t| j||}td d|ftd d|fi}| jdd|||\}} t| j|| jS )ac Creates 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.z
Item.LabelrA zItem.Attributesr9
CreateItemza{sv}(oayays)b) r$ r r r r r r r) r )
r r? r7 rE rF rG _secret
propertiesnew_itemr0 r r r create_itemj s
zCollection.create_item)r N)FrD )__name__
__module____qualname____doc__DEFAULT_COLLECTIONr r= r r r r! r# r$ r% r+ r3 r r r6 r r; r@ rC bytesrL r r r r r ! s>
r- Nr r? aliasr r c C s |st | }td d|fi}ttt| }|dd||\}}t|dkr+t| ||dS t| |\}} |r8t d| \}
}|
dksBJ t| ||dS ) zCreates a new :class:`Collection` with the given `label` and `alias`
and returns it. This action requires prompting.
:raises: :exc:`~secretstorage.exceptions.PromptDismissedException`
if the prompt is dismissed.
zCollection.LabelrA CreateCollectionza{sv}s )r r/ o)
r r r
r r( r) lenr r r )r r? rS r rJ r* r r0 r1 r: signaturer r r create_collection s rY c c s. t tt| }|dD ]}t| |V qdS )z1Returns a generator of all available collections.CollectionsN)r
r r( r r )r r* r r r r get_all_collections s
r[ c C s, zt | W S ty t| dd| Y S w )zAReturns the default collection. If it doesn't exist,
creates it.Defaultdefault)r r
rY )r r r r r get_default_collection s
r^ c C s^ zt | W S ty Y nw zt | tW S ty Y nw tt| }|r+|d S td)zReturns any collection, in the following order of preference:
- The default collection;
- The "session" collection (usually temporary);
- The first collection in the collections list.r zNo collections found.)r r
SESSION_COLLECTIONlistr[ )r collectionsr r r get_any_collection s
rb c C s: t tt| }|dd|\}t|dkrtdt| |S )zReturns the collection with the given `alias`. If there is no
such collection, raises
:exc:`~secretstorage.exceptions.ItemNotFoundException`. ReadAliasrA rU zNo collection with such alias.)r
r r( r) rW r
r )r rS r* r r r r get_collection_by_alias s
rd r7 c c s> t tt| }|dd|\}}|| D ]}t| |V qdS )zpReturns a generator of items in all collections with the given
attributes. `attributes` should be a dictionary.r8 r9 N)r
r r( r) r )r r7 r* lockedunlockedr5 r r r r; s r; )r- N)N)%rP typingr r r jeepney.io.blockingr secretstorage.definesr r secretstorage.dhcryptor secretstorage.exceptionsr r
r secretstorage.itemr secretstorage.utilr
r r r r r r( rQ r_ objectr r= rY r[ r^ rb rd r; r r r r
sL ^