
    k7ie&                     \   S r SSKJr  SSKJr  SSKJrJr  SSKJ	r	  SSK
JrJrJr  SSKJr  SSKJrJrJrJrJr  \S	-   r\S
-   rSrSr " S S	5      r  SS\S\S\S\	S-  S\4
S jjrS\S\\   4S jr SS\S\	S-  S\4S jjrS\S\4S jrS\S\S\4S jr S\S\!\\4   S\\   4S jr"g)az  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 blocks until user accepts or declines it).
Creating new items and editing existing ones is possible only in unlocked
collections.
    )Iterator)DBusConnection)SS_PATH	SS_PREFIX)Session)ItemNotFoundExceptionLockedExceptionPromptDismissedException)Item)DBusAddressWrapperexec_promptformat_secretopen_sessionunlock_objects
CollectionServicez(/org/freedesktop/secrets/aliases/defaultz+/org/freedesktop/secrets/collection/sessionc                       \ rS rSrSr\S4S\S\S\S-  SS4S jjr	S\
4S	 jrSS
 jrSS\S-  S\
4S jjrSS jrSS jrS\\   4S jrS\\\4   S\\   4S jrS\4S jrS\SS4S jr  SS\S\\\4   S\S\
S\S\4S jjrS\4S jrSrg)r   -   zRepresents a collection.N
connectioncollection_pathsessionreturnc                     Xl         X0l        X l        [        U[        U5      U l        U R
                  R                  S5        g )NLabel)r   r   r   r   COLLECTION_IFACE_collectionget_property)selfr   r   r   s       R/home/james-whalen/.local/lib/python3.13/site-packages/secretstorage/collection.py__init__Collection.__init__0   s=     %.--z;%%g.    c                 J    [        U R                  R                  S5      5      $ )zBReturns :const:`True` if item is locked, otherwise
:const:`False`.Locked)boolr   r   r   s    r   	is_lockedCollection.is_locked:   s      D$$11(;<<r"   c                 D    U R                  5       (       a  [        S5      eg)zQIf collection is locked, raises
:exc:`~secretstorage.exceptions.LockedException`.zCollection is locked!N)r'   r	   r&   s    r   ensure_not_lockedCollection.ensure_not_locked?   s"     >>!"9:: r"   timeoutc                 B    [        U R                  U R                  /US9$ )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.

:raises: ``TimeoutError`` if `timeout` (in seconds) passed
   and the prompt was neither accepted nor dismissed.

.. versionchanged:: 3.0
   No longer accepts the ``callback`` argument.

.. versionchanged:: 3.5
   Added ``timeout`` argument.
)r,   )r   r   r   )r   r,   s     r   unlockCollection.unlockE   s       doo0D0D/EwWWr"   c                 ~    [        [        [        U R                  5      nUR	                  SSU R
                  /5        g)zLocks the collection.LockaoN)r   r   SERVICE_IFACEr   callr   )r   services     r   lockCollection.lockW   s-    $WmT__MVTD$8$8#9:r"   c                     U R                  5         U R                  R                  SS5      u  nUS:w  a+  [        U R                  U5      u  p#U(       a  [        S5      egg)z/Deletes the collection and all items inside it.Delete /Prompt dismissed.N)r*   r   r4   r   r   r
   )r   prompt	dismissed_results       r   deleteCollection.delete\   s[     ""''"5S=!,T__f!EI./BCC  r"   c              #      #    U R                   R                  S5       H%  n[        U R                  XR                  5      v   M'     g7f)z3Returns a generator of all items in the collection.ItemsN)r   r   r   r   r   )r   	item_paths     r   get_all_itemsCollection.get_all_itemse   s6     ))66w?It	<<@@ @s   AA
attributesc              #      #    U R                   R                  SSU5      u  nU H%  n[        U R                  X0R                  5      v   M'     g7f)z\Returns a generator of items with the given attributes.
`attributes` should be a dictionary.SearchItemsa{ss}N)r   r4   r   r   r   )r   rG   resultrD   s       r   search_itemsCollection.search_itemsj   sB      ""''w
KIt	<<@@  s   AAc                 j    U R                   R                  S5      n[        U[        5      (       d   eU$ )zReturns the collection label.r   )r   r   
isinstancestrr   labels     r   	get_labelCollection.get_labelq   s0      --g6%%%%%r"   rR   c                 ^    U R                  5         U R                  R                  SSU5        g)z!Sets collection label to `label`.r   sN)r*   r   set_propertyrQ   s     r   	set_labelCollection.set_labelw   s&     %%gsE:r"   secretreplacecontent_typec                     U R                  5         U R                  (       d  [        U R                  5      U l        [	        U R                  X55      n[
        S-   SU4[
        S-   SU40nU R                  R                  SSUUU5      u  p[        U5      S:  a   [        U R                  XR                  5      $ [        U R                  U	5      u  pU
(       a  [        S5      eUu  pUS	:X  d   e[        U R                  XR                  5      $ )
aY  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.LabelrV   zItem.AttributesrJ   
CreateItemza{sv}(oayays)b   r<   o)r*   r   r   r   r   r   r   r4   lenr   r   r
   )r   rR   rG   rZ   r[   r\   _secret
propertiesrD   r=   r>   rK   	signatures                r   create_itemCollection.create_item|   s     	 ||'8DLfC$sEl))GZ+@

 !,,11
	 y>ALLAA'@	*+>??%	CDOOY==r"   c                 H    SU R                  5       < SU R                  < S3$ )Nz<Collection z path=>)rS   r   r&   s    r   __repr__Collection.__repr__   s&    dnn.18L8L7OqQQr"   )r   r   r   r   )r   NN)Fz
text/plain)__name__
__module____qualname____firstlineno____doc__DEFAULT_COLLECTIONr   rP   r   r    r%   r'   r*   floatr.   r6   r@   r   r   rE   dictrL   rS   rX   bytesre   ri   __static_attributes__ r"   r   r   r   -   s   " );+//> /"%/!D./48/=4 =
;Xedl Xd X$;
DAx~ A
AtCH~ A(4. A3 ;s ;t ; 49(4> >$sCx. >!>,0>"%>9=>BR# Rr"   Nr   rR   aliasr   r   c                 0   U(       d  [        U 5      n[        S-   SU40n[        [        [        U 5      nUR                  SSXB5      u  pg[        U5      S:  a
  [        XUS9$ [        X5      u  pU(       a  [        S5      eU	u  pU
S:X  d   e[        XUS9$ )	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.
zCollection.LabelrV   CreateCollectionza{sv}sr_   )r   r<   r`   )
r   r   r   r   r3   r4   ra   r   r   r
   )r   rR   rw   r   rc   r5   r   r=   r>   rK   rd   s              r   create_collectionrz      s     z*003,?J -DG%ll+=x+5>O
?a*wGG#J7I&':;;!'Ij7CCr"   c              #      #    [        [        [        U 5      nUR                  S5       H  n[	        X5      v   M     g7f)z1Returns a generator of all available collections.CollectionsN)r   r   r3   r   r   )r   r5   r   s      r   get_all_collectionsr}      s3      -DG"//>55 ?s   <>c                 V     [        U 5      $ ! [         a    [        U SSU5      s $ f = f)z@Returns the default collection. If it doesn't exist,
creates it.Defaultdefault)r   r   rz   )r   r   s     r   get_default_collectionr      s5    L*%%  L Y	7KKLs   
 ((c                      [        U 5      $ ! [         a     Of = f [        U [        5      $ ! [         a     Of = f[        [	        U 5      5      nU(       a  US   $ [        S5      e)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   zNo collections found.)r   r   SESSION_COLLECTIONlistr}   )r   collectionss     r   get_any_collectionr      st    *%%   *&899  *:67K1~#$;<<s   
 
. 
;;c                     [        [        [        U 5      nUR                  SSU5      u  n[	        U5      S::  a  [        S5      e[        X5      $ )zReturns the collection with the given `alias`. If there is no
such collection, raises
:exc:`~secretstorage.exceptions.ItemNotFoundException`.	ReadAliasrV   r_   zNo collection with such alias.)r   r   r3   r4   ra   r   r   )r   rw   r5   r   s       r   get_collection_by_aliasr      sK    
 !-DG||Ke<O
?q #$DEEj22r"   rG   c              #      #    [        [        [        U 5      nUR                  SSU5      u  p4X4-    H  n[	        X5      v   M     g7f)zoReturns a generator of items in all collections with the given
attributes. `attributes` should be a dictionary.rI   rJ   N)r   r   r3   r4   r   )r   rG   r5   lockedunlockedrD   s         r   rL   rL      sB      !-DG||M7JGF&	:)) 's   AA)r:   Nrk   )#rp   collections.abcr   jeepney.io.blockingr   secretstorage.definesr   r   secretstorage.dhcryptor   secretstorage.exceptionsr   r	   r
   secretstorage.itemr   secretstorage.utilr   r   r   r   r   r   r3   rq   r   r   rP   rz   r}   r   r   r   rs   rL   rv   r"   r   <module>r      s9   % . 4 * 
 $  |+ I%? B qR qRh LN04D. D DS D&~D9CD06N 6x
7K 6 6:L~ L$+dNL>HL=> =j =.	3 	3#&	3+5	3*^ *!#s(^*08*r"   