
    Hd                      |   d Z ddlmZmZmZ ddlmZ ddlmZm	Z	 ddl
mZ ddlmZmZmZ ddlmZ ddlmZmZmZmZmZ ed	z   Zed
z   ZdZdZ G d d	e          Z	 	 ddedededee         def
dZdedee         fdZ 	 ddedee         defdZ!dedefdZ"dededefdZ#dedeeef         dee         fdZ$dS )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.    )DictIteratorOptional)DBusConnection)	SS_PREFIXSS_PATH)Session)LockedExceptionItemNotFoundExceptionPromptDismissedException)Item)DBusAddressWrapperexec_promptformat_secretopen_sessionunlock_objects
CollectionServicez(/org/freedesktop/secrets/aliases/defaultz+/org/freedesktop/secrets/collection/sessionc                      e Zd ZdZedfdededee         ddfdZ	de
fdZdd	Zde
fd
ZddZddZdee         fdZdeeef         dee         fdZdefdZdeddfdZ	 	 ddedeeef         dede
dedefdZdS )r   zRepresents a collection.N
connectioncollection_pathsessionreturnc                     || _         || _        || _        t          |t          |          | _        | j                            d           d S )NLabel)r   r   r   r   COLLECTION_IFACE_collectionget_property)selfr   r   r   s       8lib/python3.11/site-packages/secretstorage/collection.py__init__zCollection.__init__$   sQ     $/$,($'$j2 2$(((((    c                 P    t          | j                            d                    S )zDReturns :const:`True` if item is locked, otherwise
		:const:`False`.Locked)boolr   r   r   s    r    	is_lockedzCollection.is_locked.   s#     
d++H55	6	66r"   c                 L    |                                  rt          d          dS )zSIf collection is locked, raises
		:exc:`~secretstorage.exceptions.LockedException`.zCollection is locked!N)r'   r
   r&   s    r    ensure_not_lockedzCollection.ensure_not_locked3   s/     
^^ 2	0	1	112 2r"   c                 8    t          | j        | j        g          S )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&   s    r    unlockzCollection.unlock9   s     
$*>)?	@	@@r"   c                     t          t          t          | j                  }|                    dd| j        g           dS )zLocks the collection.LockaoN)r   r   SERVICE_IFACEr   callr   )r   services     r    lockzCollection.lockE   s7    wtGG'	,,vtd2344444r"   c                     |                                   | j                            dd          \  }|dk    r)t          | j        |          \  }}|rt          d          dS dS )z/Deletes the collection and all items inside it.Delete /Prompt dismissed.N)r)   r   r0   r   r   r   )r   prompt	dismissed_results       r    deletezCollection.deleteJ   s{    !!(B//'&s] 8#DOV<<9g 8
"#6
7
778 88 8r"   c              #   ~   K   | j                             d          D ]}t          | j        || j                  V   dS )z3Returns a generator of all items in the collection.ItemsN)r   r   r   r   r   )r   	item_paths     r    get_all_itemszCollection.get_all_itemsS   sO      #0099 8 8i	doy$,	7	777778 8r"   
attributesc              #      K   | j                             dd|          \  }|D ]}t          | j        || j                  V   dS )z^Returns a generator of items with the given attributes.
		`attributes` should be a dictionary.SearchItemsa{ss}N)r   r0   r   r   r   )r   r@   resultr>   s       r    search_itemszCollection.search_itemsX   s\       !!-*EE'& 8 8i	doy$,	7	777778 8r"   c                 h    | j                             d          }t          |t                    sJ |S )zReturns the collection label.r   )r   r   
isinstancestrr   labels     r    	get_labelzCollection.get_label_   s3    


'
'
0
0%	E3			,r"   rJ   c                 f    |                                   | j                            dd|           dS )z!Sets collection label to `label`.r   sN)r)   r   set_propertyrI   s     r    	set_labelzCollection.set_labele   s5    e44444r"   F
text/plainsecretreplacecontent_typec                 B   |                                   | j        st          | j                  | _        t	          | j        ||          }t
          dz   d|ft
          dz   d|fi}| j                            dd|||          \  }}	t          | j        || j                  S )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.LabelrM   zItem.AttributesrC   
CreateItemza{sv}(oayays)b)	r)   r   r   r   r   r   r   r0   r   )
r   rJ   r@   rQ   rR   rS   _secret
propertiesnew_itemr8   s
             r    create_itemzCollection.create_itemj   s     	 0t//4<$,=='|c5\  7J"7* %**<9I+5wI I(F	dox	6	66r"   )r   N)FrP   )__name__
__module____qualname____doc__DEFAULT_COLLECTIONr   rH   r   r	   r!   r%   r'   r)   r+   r2   r;   r   r   r?   r   rE   rK   rO   bytesrY    r"   r    r   r   !   s        &8+/) ) )")()48) ) ) )7 7 7 7 7
2 2 2 2
AT 
A 
A 
A 
A5 5 5 5
8 8 8 88HTN 8 8 8 8
8DcN 8x~ 8 8 8 8    5C 5D 5 5 5 5 16%17 7c 7tCH~ 77)-7"76:7 7 7 7 7 7r"   r5   Nr   rJ   aliasr   r   c                 |   |st          |           }t          dz   d|fi}t          t          t          |           }|                    dd||          \  }}t          |          dk    rt          | ||          S t          | |          \  }}	|rt          d          |	\  }
}|
dk    sJ t          | ||          S )	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.LabelrM   CreateCollectionza{sv}s   )r   r7   o)
r   r   r   r   r/   r0   lenr   r   r   )r   rJ   ra   r   rW   r1   r   r8   r9   rD   	signatures              r    create_collectionrh      s     	 %$$'--U|<g}jAA"<<(:H(2E; ;&1 B	J	A	A	AA V44F 6 !4555$OS:@@@@r"   c              #      K   t          t          t          |           }|                    d          D ]}t	          | |          V  dS )z1Returns a generator of all available collections.CollectionsN)r   r   r/   r   r   )r   r1   r   s      r    get_all_collectionsrk      sW      g}jAA,,];; 0 0_://////0 0r"   c                 f    	 t          |           S # t          $ r t          | dd|          cY S w xY w)zAReturns the default collection. If it doesn't exist,
	creates it.Defaultdefault)r   r   rh   )r   r   s     r    get_default_collectionro      sU    	J		   	:yW
 
   s    00c                     	 t          |           S # t          $ r Y nw xY w	 t          | t                    S # t          $ r Y nw xY wt          t	          |                     }|r|d         S t          d          )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listrk   )r   collectionss     r    get_any_collectionrt      s    	J		   $ 
J 2	3	33   $'
3344 7	Q5666s    
7 
AAc                     t          t          t          |           }|                    dd|          \  }t	          |          dk    rt          d          t          | |          S )zReturns the collection with the given `alias`. If there is no
	such collection, raises
	:exc:`~secretstorage.exceptions.ItemNotFoundException`.	ReadAliasrM   rd   zNo collection with such alias.)r   r   r/   r0   rf   r   r   )r   ra   r1   r   s       r    get_collection_by_aliasrw      sb    
 g}jAALLc599A @>???:///r"   r@   c              #      K   t          t          t          |           }|                    dd|          \  }}||z   D ]}t	          | |          V  dS )zpReturns a generator of items in all collections with the given
	attributes. `attributes` should be a dictionary.rB   rC   N)r   r   r/   r0   r   )r   r@   r1   lockedunlockedr>   s         r    rE   rE      sj       g}jAALLDD8# $ $YZ######$ $r"   )r5   N)N)%r]   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/   r^   rq   objectr   rH   rh   rk   ro   rt   rw   rE   r`   r"   r    <module>r      s  
  
  , + + + + + + + + + . . . . . . 4 4 4 4 4 4 4 4 * * * * * *          # # # # # #- - - - - - - - - - - - - - |+ y(? B \7 \7 \7 \7 \7 \7 \7 \7| LN37A A. A AS A'0A<FA A A A.0N 0x
7K 0 0 0 0 9= ~ $,W$5AK   7> 7j 7 7 7 7,	0 	0#&	0+5	0 	0 	0 	0$^ $!#s(^$08$ $ $ $ $ $r"   