a
    y{JhU                     @   s   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 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)	dataclassfield)AnyAsyncGeneratorDefaultDictDictHashableOptional)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   L/var/www/shaz/venv/lib/python3.9/site-packages/aiogram/fsm/storage/memory.pyr      s   
r   c                   @   s   e Zd ZdZddddZddddZdeeddd	d
Zee	e
 dddZeee
ef ddddZeee
ef d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
    Nreturnc                 C   s   t t| _d S N)r   r   storageselfr   r   r   __init__    s    zMemoryStorage.__init__c                    s   d S r!   r   r#   r   r   r   close%   s    zMemoryStorage.close)keyr   r    c                    s    t |tr|jn|| j| _d S r!   )
isinstancer   r   r"   )r$   r'   r   r   r   r   	set_state(   s    zMemoryStorage.set_stater'   r    c                    s   | j | jS r!   )r"   r   r$   r'   r   r   r   	get_state+   s    zMemoryStorage.get_state)r'   r   r    c                    s   |  | j| _d S r!   )copyr"   r   )r$   r'   r   r   r   r   set_data.   s    zMemoryStorage.set_datac                    s   | j | j S r!   )r"   r   r-   r+   r   r   r   get_data1   s    zMemoryStorage.get_data)N)r   r   r   __doc__r%   r&   r   r   r)   r   r   r,   r
   r   r.   r/   r   r   r   r   r      s   	r   c                   @   s2   e Zd Zeeed dddZddddZdS )	DisabledEventIsolationNNr*   c                 C  s
   d V  d S r!   r   r+   r   r   r   lock6   s    zDisabledEventIsolation.lockNr   c                    s   d S r!   r   r#   r   r   r   r&   :   s    zDisabledEventIsolation.close)r   r   r   r   r   r   r3   r&   r   r   r   r   r1   5   s   r1   c                   @   s@   e Zd ZddddZeeed dddZddd	d
ZdS )SimpleEventIsolationNr   c                 C   s   t t| _d S r!   )r   r   _locksr#   r   r   r   r%   ?   s    zSimpleEventIsolation.__init__r2   r*   c              	   C  sL   | j | }|4 I d H  d V  W d   I d H  qH1 I d H s>0    Y  d S r!   )r5   )r$   r'   r3   r   r   r   r3   C   s    
zSimpleEventIsolation.lockc                    s   | j   d S r!   )r5   clearr#   r   r   r   r&   I   s    zSimpleEventIsolation.close)	r   r   r   r%   r   r   r   r3   r&   r   r   r   r   r4   >   s   r4   N)asyncior   collectionsr   
contextlibr   dataclassesr   r   typingr   r   r	   r
   r   r   Zaiogram.fsm.stater   Zaiogram.fsm.storage.baser   r   r   r   r   r   r1   r4   r   r   r   r   <module>   s    	