U
    ‰¾úgì  ã                   @   s‚   d Z ddlmZ ddlmZmZmZmZmZm	Z	m
Z
mZmZ ddlmZmZ edƒZedƒZedƒZG dd	„ d	eeeef ƒZd
S )aO  This module contains a mutable mapping that keeps track of the keys that where accessed.

.. versionadded:: 20.0

Warning:
    Contents of this module are intended to be used internally by the library and *not* by the
    user. Changes to this module are not considered breaking changes and may not be documented in
    the changelog.
é    )ÚUserDict)	ÚFinalÚGenericÚListÚMappingÚOptionalÚSetÚTupleÚTypeVarÚUnion)ÚDEFAULT_NONEÚDefaultValueÚ_VTÚ_KTÚ_Tc                       s  e Zd ZU dZeƒ Zeed< dZddœ‡ fdd„Z	e
eddœ‡ fd	d
„Ze
ddœ‡ fdd„Zee
ee
 f ddœdd„Zee
 dœdd„Zeee
ef  dœdd„Ze
ddœdd„Zee
ef ddœdd„Zefe
eedœ‡ fdd„Zddœ‡ fdd„Zd"de
ee edœd d!„Z‡  ZS )#ÚTrackingDicta'  Mutable mapping that keeps track of which keys where accessed with write access.
    Read-access is not tracked.

    Note:
        * ``setdefault()`` and ``pop`` are considered writing only depending on whether the
            key is present
        * deleting values is considered writing
    ÚDELETED)Ú_write_access_keysN)Úreturnc                    s   t ƒ  ¡  tƒ | _d S ©N)ÚsuperÚ__init__Úsetr   ©Úself©Ú	__class__© úD/tmp/pip-unpacked-wheel-swnnwir2/telegram/ext/_utils/trackingdict.pyr   5   s    
zTrackingDict.__init__)ÚkeyÚvaluer   c                    s   |   |¡ tƒ  ||¡ d S r   )Ú_TrackingDict__track_writer   Ú__setitem__)r   r   r    r   r   r   r"   9   s    
zTrackingDict.__setitem__)r   r   c                    s   |   |¡ tƒ  |¡ d S r   )r!   r   Ú__delitem__©r   r   r   r   r   r#   =   s    
zTrackingDict.__delitem__c                 C   s*   t |tƒr|  j|O  _n| j |¡ d S r   )Ú
isinstancer   r   Úaddr$   r   r   r   Z__track_writeA   s    
zTrackingDict.__track_writec                 C   s   | j }tƒ | _ |S )zUReturns all keys that were write-accessed since the last time this method was called.)r   r   )r   Úoutr   r   r   Úpop_accessed_keysG   s    zTrackingDict.pop_accessed_keysc                    s   ˆ   ¡ }‡ fdd„|D ƒS )zØ
        Returns all keys & corresponding values as set of tuples that were write-accessed since
        the last time this method was called. If a key was deleted, the value will be
        :attr:`DELETED`.
        c                    s   g | ]}|ˆ   |ˆ j¡f‘qS r   )Úgetr   )Ú.0r   r   r   r   Ú
<listcomp>T   s     z9TrackingDict.pop_accessed_write_items.<locals>.<listcomp>)r(   )r   Úkeysr   r   r   Úpop_accessed_write_itemsM   s    z%TrackingDict.pop_accessed_write_itemsc                 C   s   | j  |¡ dS )zŽUse this method have the key returned again in the next call to
        :meth:`pop_accessed_write_items` or :meth:`pop_accessed_keys`
        N)r   r&   r$   r   r   r   Úmark_as_accessedV   s    zTrackingDict.mark_as_accessed)Úmappingr   c                 C   s    |  ¡ D ]\}}|| j|< qdS )z8Like ``update``, but doesn't count towards write access.N)ÚitemsÚdata)r   r/   r   r    r   r   r   Úupdate_no_track^   s    zTrackingDict.update_no_track)r   Údefaultr   c                    s8   || kr|   |¡ t|tƒr(tƒ  |¡S tƒ j||dS )N)r3   )r!   r%   r   r   Úpop©r   r   r3   r   r   r   r4   e   s
    

zTrackingDict.popc                    s"   |   ttƒ  ¡ ƒ¡ tƒ  ¡  d S r   )r!   r   r   r,   Úclearr   r   r   r   r6   p   s    zTrackingDict.clearzTrackingDict[_KT, _T])r   r   r3   r   c                 C   s&   || kr| | S |   |¡ || |< |S r   )r!   r5   r   r   r   Ú
setdefaultv   s
    
zTrackingDict.setdefault)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úobjectr   r   Ú__annotations__Ú	__slots__r   r   r   r"   r#   r   r   r!   r(   r   r	   r-   r.   r   r2   r   r4   r6   r   r   r7   Ú__classcell__r   r   r   r   r   &   s&   
		
ýür   N)r;   Úcollectionsr   Útypingr   r   r   r   r   r   r	   r
   r   Ztelegram._utils.defaultvaluer   r   r   r   r   r   r   r   r   r   Ú<module>   s   	,