o
    FhL                     @   s   d dl mZ d dlmZ d dlmZ d dlmZ d dlmZm	Z	 d dl
mZmZmZmZmZmZmZmZ d dlmZ d dlmZ d d	lmZmZmZmZ eG d
d dZG dd deZG dd deZG dd deZdS )    )Lock)defaultdict)asynccontextmanager)copy)	dataclassfield)AnyAsyncGeneratorDefaultDictDictHashableMappingOptionaloverload)DataNotDictLikeError)State)BaseEventIsolationBaseStorage	StateType
StorageKeyc                   @   s8   e Zd ZU eedZeeef e	d< dZ
ee e	d< dS )MemoryStorageRecord)default_factorydataNstate)__name__
__module____qualname__r   dictr   r   strr   __annotations__r   r    r    r    M/var/www/html/venv/lib/python3.10/site-packages/aiogram/fsm/storage/memory.pyr      s   
 r   c                
   @   s   e Zd ZdZdddZdddZdded	eddfd
dZdede	e
 fddZdedee
ef ddfddZdedee
ef fddZedede
de	e fddZedede
dedefddZ	ddede
de	e de	e fddZdS )MemoryStoragez
    Default FSM storage, stores all data in :class:`dict` and loss everything on shutdown

    .. warning::

        Is not recommended using in production in due to you will lose all data
        when your bot restarts
    returnNc                 C      t t| _d S N)r   r   storageselfr    r    r!   __init__+   s   
zMemoryStorage.__init__c                       d S r%   r    r'   r    r    r!   close0      zMemoryStorage.closekeyr   c                    s"   t |tr	|jn|| j| _d S r%   )
isinstancer   r   r&   )r(   r-   r   r    r    r!   	set_state3   s    zMemoryStorage.set_statec                    s   | j | jS r%   )r&   r   r(   r-   r    r    r!   	get_state6   s   zMemoryStorage.get_stater   c                    s4   t |tstdt|j | | j| _d S )Nz-Data must be a dict or dict-like object, got )r.   r   r   typer   r   r&   r   )r(   r-   r   r    r    r!   set_data9   s   
zMemoryStorage.set_datac                    s   | j | j S r%   )r&   r   r   r0   r    r    r!   get_data@   s   zMemoryStorage.get_datastorage_keydict_keyc                    r*   r%   r    )r(   r5   r6   r    r    r!   	get_valueC   r,   zMemoryStorage.get_valuedefaultc                    r*   r%   r    )r(   r5   r6   r8   r    r    r!   r7   F   r,   c                    s   | j | j}t|||S r%   )r&   r   r   get)r(   r5   r6   r8   r   r    r    r!   r7   I   s   r#   Nr%   )r   r   r   __doc__r)   r+   r   r   r/   r   r   r1   r   r   r3   r   r4   r   r7   r    r    r    r!   r"   !   s,    
	
r"   c                   @   s0   e Zd Zededed fddZd	ddZdS )
DisabledEventIsolationr-   r#   NNc                 C  s   d V  d S r%   r    r0   r    r    r!   lockQ   s   
zDisabledEventIsolation.lockNc                    r*   r%   r    r'   r    r    r!   r+   U   r,   zDisabledEventIsolation.closer:   )r   r   r   r   r   r	   r>   r+   r    r    r    r!   r<   P   s    r<   c                   @   s:   e Zd ZdddZededed fddZdd	d
ZdS )SimpleEventIsolationr#   Nc                 C   r$   r%   )r   r   _locksr'   r    r    r!   r)   Z   s   zSimpleEventIsolation.__init__r-   r=   c              	   C  sP   | j | }|4 I d H  d V  W d   I d H  d S 1 I d H s!w   Y  d S r%   )r@   )r(   r-   r>   r    r    r!   r>   ^   s
   
.zSimpleEventIsolation.lockc                    s   | j   d S r%   )r@   clearr'   r    r    r!   r+   d   s   zSimpleEventIsolation.closer:   )	r   r   r   r)   r   r   r	   r>   r+   r    r    r    r!   r?   Y   s
    
r?   N) asyncior   collectionsr   
contextlibr   r   dataclassesr   r   typingr   r	   r
   r   r   r   r   r   aiogram.exceptionsr   aiogram.fsm.stater   aiogram.fsm.storage.baser   r   r   r   r   r"   r<   r?   r    r    r    r!   <module>   s    (/	