
    .Ph$                     z   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	          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       X/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/secretstorage/collection.py__init__zCollection.__init__%   sQ     %.--z; ;%%g.....    c                 P    t          | j                            d                    S )zJReturns :const:`True` if item is locked, otherwise
        :const:`False`.Locked)boolr   r   r   s    r    	is_lockedzCollection.is_locked/   s#     D$11(;;<<<r"   c                 L    |                                  rt          d          dS )zYIf collection is locked, raises
        :exc:`~secretstorage.exceptions.LockedException`.zCollection is locked!N)r'   r
   r&   s    r    ensure_not_lockedzCollection.ensure_not_locked4   s/     >> 	;!"9:::	; 	;r"   c                 8    t          | j        | j        g          S )aA  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.unlock:   s     do0D/EFFFr"   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.lockF   s7    $WmT_MMVTD$8#9:::::r"   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.deleteK   sx       "''"55S==!,T_f!E!EIw D./BCCC =D Dr"   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_itemsT   sS      )66w?? 	A 	AIt	4<@@@@@@	A 	Ar"   
attributesc              #      K   | j                             dd|          \  }|D ]}t          | j        || j                  V   dS )zdReturns 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_itemsY   s`       "''w
KK 	A 	AIt	4<@@@@@@	A 	Ar"   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     --g66%%%%%%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_labelf   s5       %%gsE:::::r"   F
text/plainsecretreplacecontent_typec                 
   |                                   | j        st          | j                  | _        t	          | j        ||          }t
          dz   d|ft
          dz   d|fi}| j                            dd|||          \  }}	t          |          dk    rt          | j        || j                  S t          | j        |	          \  }
}|
rt          d          |\  }}|d	k    sJ t          | j        || j                  S )
a  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   r7   o)r)   r   r   r   r   r   r   r0   lenr   r   r   )r   rJ   r@   rQ   rR   rS   _secret
propertiesr>   r8   r9   rD   	signatures                r    create_itemzCollection.create_itemk   s    	   | 	9'88DLflCC$sEl))GZ+@

 !,11
 
	6 y>>ADLAAA'@@	6 	@*+>???%	9CDOY===r"   )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   bytesr\    r"   r    r   r   "   s       "" );.2/ /> /"%/"7+/7;/ / / /=4 = = = =
; ; ; ;
G 
G 
G 
G 
G; ; ; ;
D D D DAx~ A A A A
AtCH~ A(4. A A A A3    ;s ;t ; ; ; ; 49(4> > >$sCx. >!>,0>"%>9=> > > > > >r"   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}srV   )r   r7   rW   )
r   r   r   r   r/   r0   rX   r   r   r   )r   rJ   rd   r   rZ   r1   r   r8   r9   rD   r[   s              r    create_collectionrg      s      +z**003,?J -DDG%ll+=x+5u> >OV
?a*owGGGG#J77Iv <&':;;;!'Ij/7CCCCr"   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_collectionsrj      sW       -DDG"//>> 6 6_5555556 6r"   c                 f    	 t          |           S # t          $ r t          | dd|          cY S w xY w)zDReturns the default collection. If it doesn't exist,
    creates it.Defaultdefault)r   r   rg   )r   r   s     r    get_default_collectionrn      sO    L*%%%  L L L Y	7KKKKKL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listrj   )r   collectionss     r    get_any_collectionrs      s    *%%%     *&8999    *:6677K =1~#$;<<<s    
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   rV   zNo collection with such alias.)r   r   r/   r0   rX   r   r   )r   rd   r1   r   s       r    get_collection_by_aliasrv      s_    
 !-DDG||Ke<<O
?q  #$DEEEj/222r"   r@   c              #      K   t          t          t          |           }|                    dd|          \  }}||z   D ]}t	          | |          V  dS )zsReturns 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       !-DDG||M7JGGFHh& * *	:y))))))* *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/   ra   rp   r   rH   rg   rj   rn   rs   rv   rE   rc   r"   r    <module>r      s  
  
  , + + + + + + + + + . . . . . . 4 4 4 4 4 4 4 4 * * * * * *          # # # # # #- - - - - - - - - - - - - - |+ I%? B h> h> h> h> h> h> h> h>V LN37D D. D DS D'0D<FD D D D06N 6x
7K 6 6 6 6 9=L L~ L$,W$5LAKL L L L=> =j = = = =.	3 	3#&	3+5	3 	3 	3 	3*^ *!#s(^*08* * * * * *r"   