o
    Fhb                     @  s  d dl mZ d dlZd dlmZ d dlmZ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mZmZ 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" 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, d dl-m.Z. d dl/m0Z0m1Z1 d dl2m3Z3m4Z4 G dd dZ5G dd dZ6G dd de	Z7G dd dZ8G dd dZ9e G dd  d Z:d8d&d'Z;G d(d) d)Z<G d*d+ d+Z=G d,d- d-Z>G d.d/ d/Z?G d0d1 d1Z@eG d2d3 d3ZAG d4d5 d5ZBG d6d7 d7ZCeC ZDdS )9    )annotationsN)defaultdict)	dataclassreplace)Enumauto)
AnyClassVarDictListMappingOptionalTupleTypeUnionoverload)Self)loggers)
Dispatcher)NextMiddlewareType)CallableObjectCallbackType)extract_flags_from_object)Router)SceneException)StateFilter)
FSMContext)StateMemoryStorageRecord)TelegramObjectUpdate)ClassAttrsResolverget_sorted_mro_attrs_resolverc                   @  sh   e Zd Zd#d$d	d
Zd%ddZd&ddZd&ddZd'ddZd(ddZd(ddZ	d%ddZ
d)d d!Zd"S )*HistoryManagerscenes_history
   stater   destinystrsizeintc                 C  s*   || _ || _t|jt|j|dd| _d S )N)r(   )storagekey)_size_stater   r,   r   r-   _history_state)selfr'   r(   r*    r2   D/var/www/html/venv/lib/python3.10/site-packages/aiogram/fsm/scene.py__init__)   s
   zHistoryManager.__init__Optional[str]dataDict[str, Any]returnNonec                   st   | j  I d H }|dg }|||d t|| jkr&|| j d  }tjd|| | j j	|dI d H  d S )Nhistoryr'   r6   z Push state=%s data=%s to historyr:   )
r0   get_data
setdefaultappendlenr.   r   scenedebugupdate_data)r1   r'   r6   history_datar:   r2   r2   r3   push0   s   zHistoryManager.pushOptional[MemoryStorageRecord]c                   s   | j  I d H }|dg }|sd S | }|d }|d }|s+| j i I d H  n
| j j|dI d H  tjd|| t	||dS )Nr:   r'   r6   r<   z!Pop state=%s data=%s from historyr;   )
r0   r=   r>   popset_datarC   r   rA   rB   r   )r1   rD   r:   recordr'   r6   r2   r2   r3   rG   :   s   zHistoryManager.popc                   s8   | j  I d H }|dg }|sd S tdi |d S )Nr:   r2   )r0   r=   r>   r   r1   rD   r:   r2   r2   r3   getI   s   zHistoryManager.getList[MemoryStorageRecord]c                   s,   | j  I d H }|dg }dd |D S )Nr:   c                 S  s   g | ]	}t d i |qS )r2   r   ).0itemr2   r2   r3   
<listcomp>S   s    z&HistoryManager.all.<locals>.<listcomp>)r0   r=   r>   rK   r2   r2   r3   allP   s   zHistoryManager.allc                   s$   t jd | ji I d H  d S )NzClear history)r   rA   rB   r0   rH   r1   r2   r2   r3   clearU   s   zHistoryManager.clearc                   s8   | j  I d H }| j  I d H }| ||I d H  d S N)r/   	get_stater=   rE   r1   r'   r6   r2   r2   r3   snapshotY   s   zHistoryManager.snapshotc                   s*   | j |I d H  | j |I d H  d S rT   )r/   	set_staterH   rV   r2   r2   r3   
_set_state^   s   zHistoryManager._set_statec                   sZ   |   I d H }|s| d i I d H  d S tjd|j|j | |j|jI d H  |jS )NzRollback to state=%s data=%s)rG   rY   r   rA   rB   r'   r6   )r1   previous_stater2   r2   r3   rollbackb   s   zHistoryManager.rollbackN)r%   r&   )r'   r   r(   r)   r*   r+   )r'   r5   r6   r7   r8   r9   )r8   rF   )r8   rM   r8   r9   )r8   r5   )__name__
__module____qualname__r4   rE   rG   rL   rQ   rS   rW   rY   r[   r2   r2   r2   r3   r$   (   s    







r$   c                   @  sb   e Zd Z		d!d"ddZd#ddZd$ddZd%ddZd&ddZd'ddZd&ddZ	d&dd Z
dS )(ObserverDecoratorNnamer)   filterstuple[CallbackType, ...]actionSceneAction | NoneafterOptional[After]r8   r9   c                 C     || _ || _|| _|| _d S rT   )ra   rb   rd   rf   )r1   ra   rb   rd   rf   r2   r2   r3   r4   r      
zObserverDecorator.__init__targetType[Scene] | CallbackTypec                 C  s@   t |dd }|sg }t|d| |t| j|| j| jd d S )N__aiogram_handler__ra   handlerrb   rf   )getattrsetattrr?   HandlerContainerra   rb   rf   )r1   rj   handlersr2   r2   r3   _wrap_filter~   s   zObserverDecorator._wrap_filterr   c                 C  sR   | j d us	J dt|dd }|d u rtt}t|d| t||| j  | j< d S )NzScene action is not specified__aiogram_action__)rd   ro   r   dictrp   r   ra   )r1   rj   rd   r2   r2   r3   _wrap_action   s   zObserverDecorator._wrap_actionc                 C  s8   t |r| jd u r| | |S | | |S td)Nz"Only function or method is allowed)inspect
isfunctionrd   rs   rv   	TypeErrorr1   rj   r2   r2   r3   __call__   s   



zObserverDecorator.__call__ActionContainerc                 C     t | j| jtjS rT   )r|   ra   rb   SceneActionleaverR   r2   r2   r3   r         zObserverDecorator.leaveType[Scene]c                 C  s   t | j| jtj|S rT   )r|   ra   rb   r~   enterrz   r2   r2   r3   r      s   zObserverDecorator.enterc                 C  r}   rT   )r|   ra   rb   r~   exitrR   r2   r2   r3   r      r   zObserverDecorator.exitc                 C  r}   rT   )r|   ra   rb   r~   backrR   r2   r2   r3   r      r   zObserverDecorator.back)NN)
ra   r)   rb   rc   rd   re   rf   rg   r8   r9   )rj   rk   r8   r9   )rj   r   r8   r9   )rj   r   r8   r   )r8   r|   )rj   r   r8   r|   )r]   r^   r_   r4   rs   rv   r{   r   r   r   r   r2   r2   r2   r3   r`   q   s    


	



r`   c                   @  s$   e Zd Ze Ze Ze Ze ZdS )r~   N)r]   r^   r_   r   r   r   r   r   r2   r2   r2   r3   r~      s
    
r~   c                   @  s$   e Zd Z	ddddZdddZdS )r|   Nra   r)   rb   Tuple[CallbackType, ...]rd   r~   rj   (Optional[Union[Type[Scene], State, str]]r8   r9   c                 C  rh   rT   )ra   rb   rd   rj   )r1   ra   rb   rd   rj   r2   r2   r3   r4      ri   zActionContainer.__init__wizardSceneWizardc                   s   | j tjkr| jd ur|| jI d H  d S | j tjkr&| I d H  d S | j tjkr5| I d H  d S | j tjkrD| I d H  d S d S rT   )rd   r~   r   rj   gotor   r   r   r1   r   r2   r2   r3   execute   s   zActionContainer.executerT   )
ra   r)   rb   r   rd   r~   rj   r   r8   r9   r   r   r8   r9   )r]   r^   r_   r4   r   r2   r2   r2   r3   r|      s    r|   c                   @  s   e Zd Z	ddddZdS )rq   Nra   r)   rn   r   rb   r   rf   rg   r8   r9   c                 C  rh   rT   rm   )r1   ra   rn   rb   rf   r2   r2   r3   r4      ri   zHandlerContainer.__init__rT   )
ra   r)   rn   r   rb   r   rf   rg   r8   r9   )r]   r^   r_   r4   r2   r2   r2   r3   rq      s    rq   c                   @  sb   e Zd ZU ded< 	 ded< 	 ded< 	 dZded	< 	 dZded
< 	 dZded< 	 eZded< dS )SceneConfigr5   r'   zList[HandlerContainer]rr   z,Dict[SceneAction, Dict[str, CallableObject]]actionsNzOptional[bool]reset_data_on_enterreset_history_on_entercallback_query_without_stater"   attrs_resolver)	r]   r^   r_   __annotations__r   r   r   r#   r   r2   r2   r2   r3   r      s   
 r   argsr   kwargsr8   r9   c                    s   d S rT   r2   )r   r   r2   r2   r3   _empty_handler   s   r   c                   @  s8   e Zd Z	ddd
dZdddZdddZdddZdS )SceneHandlerWrapperNrA   r   rn   r   rf   rg   r8   r9   c                 C  s   || _ t|| _|| _d S rT   )rA   r   rn   rf   )r1   rA   rn   rf   r2   r2   r3   r4      s   

zSceneHandlerWrapper.__init__eventr    r   r   c           	   	     s   |d }|d }|d }| j t| j j|||j||dd}| jj||fi |I d H }| jrCtdd| jj| jj }|	|j
I d H  |S )Nr'   scenesevent_updatescene_configmanagerr'   update_typer   r6   r   rf   r2   )rA   r   __scene_config__
event_typern   callrf   r|   rd   r   r   )	r1   r   r   r'   r   r   rA   resultaction_containerr2   r2   r3   r{     s0   zSceneHandlerWrapper.__call__r   c                 C  s   | S rT   r2   rR   r2   r2   r3   	__await__!  s   zSceneHandlerWrapper.__await__r)   c                 C  s8   d| j  d| jj }| jr|d| j 7 }|d7 }|S )NzSceneHandlerWrapper(z, z, after=))rA   rn   callbackrf   )r1   r   r2   r2   r3   __str__$  s
   zSceneHandlerWrapper.__str__rT   )rA   r   rn   r   rf   rg   r8   r9   )r   r    r   r   r8   r   )r8   r   )r8   r)   )r]   r^   r_   r4   r{   r   r   r2   r2   r2   r3   r      s    


r   c                      sd   e Zd ZU dZded< 	 ddd	Zd fddZedddZeddddZ	ed ddZ
  ZS )!Scenea  
    Represents a scene in a conversation flow.

    A scene is a specific state in a conversation where certain actions can take place.

    Each scene has a set of filters that determine when it should be triggered,
    and a set of handlers that define the actions to be executed when the scene is active.

    .. note::
        This class is not meant to be used directly. Instead, it should be subclassed
        to define custom scenes.
    zClassVar[SceneConfig]r   r   r   r8   r9   c                 C  s   || _ | | j _d S rT   )r   rA   r   r2   r2   r3   r4   =  s   zScene.__init__r   r   c              	     sf  | dd }| dd }| dd }| dd }| dd }t jdi | g }tt}| jD ]-}	t|	ts8q0t|	dd }
|
sAq0|d u rH|
j	}|d u rO|
j
}|d u rV|
j}|d u r]|
j}q0|d u rdt}|| D ]:\}}t|dd  }ry|| t|tr|t|jt|j|jd t|d	r|j D ]\}}|| | qqht||t|||||d
| _d S )Nr'   r   r   r   r   r   rl   rf   rt   )r'   rr   r   r   r   r   r   r2   )rG   super__init_subclass__r   ru   	__bases__
issubclassr   ro   r   r   r   r   r#   extend
isinstancer`   r?   rq   ra   r   rb   rf   hasattrrt   itemsupdater   r   )clsr   
state_namer   r   r   r   rr   r   baseparent_scene_configra   valuescene_handlersrd   action_handlers	__class__r2   r3   r   D  sd   




zScene.__init_subclass__routerr   c                 C  s   | j }t }|jD ]#}|j|j jt| |j|jdg|j	R dt
|ji ||j q	|D ]}|jr9|dkr9q/|j| t|j q/dS )z^
        Adds the scene to the given router.

        :param router:
        :return:
        r   flagscallback_queryN)r   setrr   	observersra   registerr   rn   rf   rb   r   addr   filterr   r'   )r   r   r   used_observersrn   observer_namer2   r2   r3   add_to_router~  s(   
	zScene.add_to_routerNra   r5   c                 C  s>   |du rd| j  d| j d| jj}t|d}| | |S )zM
        Returns the scene as a router.

        :return: new router
        NzScene '.z' for state ra   )r^   r_   r   r'   r   r   )r   ra   r   r2   r2   r3   	as_router  s   

zScene.as_routerhandler_kwargsr   c                   s   d fd	d
}|S )z
        Create an entry point handler for the scene, can be used to simplify the handler
        that starts the scene.

        >>> router.message.register(MyScene.as_handler(), Command("start"))
        r   r    r   ScenesManagermiddleware_kwargsr   r8   r9   c                   s&   |j  fi i |I d H  d S rT   )r   )r   r   r   r   r   r2   r3   enter_to_scene_handler  s   $z0Scene.as_handler.<locals>.enter_to_scene_handlerN)r   r    r   r   r   r   r8   r9   r2   )r   r   r   r2   r   r3   
as_handler  s   	zScene.as_handlerr   r   r   r8   r9   r   r   r8   r9   rT   )ra   r5   r8   r   )r   r   r8   r   )r]   r^   r_   __doc__r   r4   r   classmethodr   r   r   __classcell__r2   r2   r   r3   r   ,  s   
 
:r   c                   @  s   e Zd ZdZd;ddZd<ddZd=d>ddZd<ddZd<ddZd<dd Z	d?d#d$Z
d@d'd(ZdAd*d+ZdBd,d-ZedCd0d1ZedDd3d1ZdEdFd5d1Z	4dEdGd7d8ZdHd9d:Zd4S )Ir   as  
    A class that represents a wizard for managing scenes in a Telegram bot.

    Instance of this class is passed to each scene as a parameter.
    So, you can use it to transition between scenes, get and set data, etc.

    .. note::

        This class is not meant to be used directly. Instead, it should be used
        as a parameter in the scene constructor.

    r   r   r   r   r'   r   r   r)   r   r    r6   r7   c                 C  s.   || _ || _|| _|| _|| _|| _d| _dS )a  
        A class that represents a wizard for managing scenes in a Telegram bot.

        :param scene_config: The configuration of the scene.
        :param manager: The scene manager.
        :param state: The FSMContext object for storing the state of the scene.
        :param update_type: The type of the update event.
        :param event: The TelegramObject represents the event.
        :param data: Additional data for the scene.
        N)r   r   r'   r   r   r6   rA   )r1   r   r   r'   r   r   r6   r2   r2   r3   r4     s   
zSceneWizard.__init__r   r   r8   r9   c                   s|   t jd| jj | jjr| ji I dH  | jjr$| jj	
 I dH  | j| jjI dH  | jtjfi |I dH  dS )a  
        Enter method is used to transition into a scene in the SceneWizard class.
        It sets the state, clears data and history if specified,
        and triggers entering event of the scene.

        :param kwargs: Additional keyword arguments.
        :return: None
        zEntering scene %rN)r   rA   rB   r   r'   r   rH   r   r   r:   rS   rX   
_on_actionr~   r   r1   r   r2   r2   r3   r     s   	zSceneWizard.enterT_with_historyboolc                   sH   t jd| jj |r| jj I dH  | jt	j
fi |I dH  dS )a"  
        Leaves the current scene.
        This method is used to exit a scene and transition to the next scene.

        :param _with_history: Whether to include history in the snapshot. Defaults to True.
        :param kwargs: Additional keyword arguments.
        :return: None

        zLeaving scene %rN)r   rA   rB   r   r'   r   r:   rW   r   r~   r   )r1   r   r   r2   r2   r3   r     s
   
zSceneWizard.leavec                   s`   t jd| jj | jj I dH  | jt	j
fi |I dH  | jjdddi|I dH  dS )z
        Exit the current scene and enter the default scene/state.

        :param kwargs: Additional keyword arguments.
        :return: None
        zExiting scene %rN_check_activeFrT   )r   rA   rB   r   r'   r   r:   rS   r   r~   r   r   r   r2   r2   r3   r     s
    zSceneWizard.exitc                   sb   t jd| jj | jdddi|I dH  | jj I dH }| jj	|fddi|I dH  dS )z
        This method is used to go back to the previous scene.

        :param kwargs: Keyword arguments that can be passed to the method.
        :return: None
        z$Back to previous scene from scene %sr   FNr   r2   )
r   rA   rB   r   r'   r   r   r:   r[   r   )r1   r   	new_scener2   r2   r3   r     s
   "zSceneWizard.backc                   s6   | j jdusJ d| j| j jfi |I dH  dS )z
        This method allows to re-enter the current scene.

        :param kwargs: Additional keyword arguments to pass to the scene.
        :return: None
        NzScene state is not specified)r   r'   r   r   r2   r2   r3   retake  s    zSceneWizard.retakerA   Union[Type[Scene], State, str]c                   s:   | j di |I dH  | jj|fddi|I dH  dS )a  
        The `goto` method transitions to a new scene.
        It first calls the `leave` method to perform any necessary cleanup
        in the current scene, then calls the `enter` event to enter the specified scene.

        :param scene: The scene to transition to. Can be either a `Scene` instance
            `State` instance or a string representing the scene.
        :param kwargs: Additional keyword arguments to pass to the `enter`
            method of the scene manager.
        :return: None
        Nr   Fr2   )r   r   r   )r1   rA   r   r2   r2   r3   r   '  s   "zSceneWizard.gotord   r~   c                   s   | j stdtj d|j| jj | jj|i }|s*tj d|j| jj dS | j	}||vr?tj d|j|| jj dS || j
| j | jfi i | j|I d H  dS )NzScene is not initializedzCall action %r in scene %rzAction %r not found in scene %rFz,Action %r for event %r not found in scene %rT)rA   r   r   rB   ra   r   r'   r   rL   r   r   r   r6   )r1   rd   r   action_configr   r2   r2   r3   r   6  s*   ,zSceneWizard._on_actionMapping[str, Any]c                   s   | j j|dI dH  dS )z
        Sets custom data in the current state.

        :param data: A mapping containing the custom data to be set in the current state.
        :return: None
        r6   N)r'   rH   )r1   r6   r2   r2   r3   rH   O  s   zSceneWizard.set_datac                   s   | j  I dH S )z
        This method returns the data stored in the current state.

        :return: A dictionary containing the data stored in the scene state.
        N)r'   r=   rR   r2   r2   r3   r=   X  s   zSceneWizard.get_datar-   Optional[Any]c                      dS )z
        This method returns the value from key in the data of the current state.

        :param key: The keyname of the item you want to return the value from.

        :return: A dictionary containing the data stored in the scene state.
        Nr2   )r1   r-   r2   r2   r3   	get_value`  s   	zSceneWizard.get_valuedefaultc                   r   )aC  
        This method returns the value from key in the data of the current state.

        :param key: The keyname of the item you want to return the value from.
        :param default: Default value to return, if ``key`` was not found.

        :return: A dictionary containing the data stored in the scene state.
        Nr2   r1   r-   r   r2   r2   r3   r   k  s   
Nc                   s   | j ||I d H S rT   )r'   r   r   r2   r2   r3   r   w  s   Optional[Mapping[str, Any]]c                   s$   |r| | | jj|dI dH S )z
        This method updates the data stored in the current state

        :param data: Optional mapping of data to update.
        :param kwargs: Additional key-value pairs of data to update.
        :return: Dictionary of updated data
        r   N)r   r'   rC   )r1   r6   r   r2   r2   r3   rC   z  s   

zSceneWizard.update_datac                   s   |  i I dH  dS )z9
        Clears the data.

        :return: None
        N)rH   rR   r2   r2   r3   
clear_data  s   zSceneWizard.clear_data)r   r   r   r   r'   r   r   r)   r   r    r6   r7   r   T)r   r   r   r   r8   r9   )rA   r   r   r   r8   r9   )rd   r~   r   r   r8   r   )r6   r   r8   r9   )r8   r7   )r-   r)   r8   r   )r-   r)   r   r   r8   r   rT   )r-   r)   r   r   r8   r   )r6   r   r   r   r8   r7   r\   )r]   r^   r_   r   r4   r   r   r   r   r   r   r   rH   r=   r   r   rC   r   r2   r2   r2   r3   r     s(    









	
r   c                   @  sF   e Zd ZdZd"ddZd#ddZd$ddZ	d%d&ddZd'dd Zd!S )(r   z
    The ScenesManager class is responsible for managing scenes in an application.
    It provides methods for entering and exiting scenes, as well as retrieving the active scene.
    registrySceneRegistryr   r)   r   r    r'   r   r6   r7   r8   r9   c                 C  s.   || _ || _|| _|| _|| _t| j| _d S rT   )r   r   r   r'   r6   r$   r:   )r1   r   r   r   r'   r6   r2   r2   r3   r4     s   zScenesManager.__init__
scene_typer   r   c              	     s2   | j |}|t|j| | j| j| j| jddS )Nr   r   )r   rL   r   r   r'   r   r   r6   )r1   r   r2   r2   r3   
_get_scene  s   zScenesManager._get_sceneOptional[Scene]c                   s:   | j  I d H }z	| |I d H W S  ty   Y d S w rT   )r'   rU   r   r   )r1   r'   r2   r2   r3   _get_active_scene  s   zScenesManager._get_active_sceneTr   r   r   r   c                   s   |r|   I dH }|dur|jjdi |I dH  z
| |I dH }W n ty<   |dur0 | jdI dH  Y dS w |jjdi |I dH  dS )a  
        Enters the specified scene.

        :param scene_type: Optional Type[Scene], State or str representing the scene type to enter.
        :param _check_active: Optional bool indicating whether to check if
            there is an active scene to exit before entering the new scene. Defaults to True.
        :param kwargs: Additional keyword arguments to pass to the scene's wizard.enter() method.
        :return: None
        Nr2   )r   r   r   r   r   r'   rX   r   )r1   r   r   r   active_scenerA   r2   r2   r3   r     s   zScenesManager.enterc                   s4   |   I dH }|sdS |jjdi |I dH  dS )z
        Close method is used to exit the currently active scene in the ScenesManager.

        :param kwargs: Additional keyword arguments passed to the scene's exit method.
        :return: None
        Nr2   )r   r   r   )r1   r   rA   r2   r2   r3   close  s
   zScenesManager.closeN)r   r   r   r)   r   r    r'   r   r6   r7   r8   r9   )r   r   r8   r   )r8   r   r   )r   r   r   r   r   r   r8   r9   r   )	r]   r^   r_   r   r4   r   r   r   r   r2   r2   r2   r3   r     s    



r   c                   @  s^   e Zd ZdZd%d&d	d
Zd'ddZd(ddZd(ddZddd)ddZd*dd Z	d+d#d$Z
dS ),r   zJ
    A class that represents a registry for scenes in a Telegram bot.
    Tr   r   register_on_addr   r8   r9   c                 C  s    || _ || _i | _| | dS )z
        Initialize a new instance of the SceneRegistry class.

        :param router: The router instance used for scene registration.
        :param register_on_add: Whether to register the scenes to the router when they are added.
        N)r   r   _scenes_setup_middleware)r1   r   r   r2   r2   r3   r4     s   zSceneRegistry.__init__c                 C  sH   t |tr|j| j d S |j D ]}|jdv rq|| j qd S )N>   errorr   )	r   r   r   outer_middleware_update_middlewarer   values
event_name_middleware)r1   r   observerr2   r2   r3   r     s   

zSceneRegistry._setup_middlewarern   "NextMiddlewareType[TelegramObject]r   r    r6   r7   r   c                   sB   t |ts
J dt| |j|j|d |d|d< |||I d H S )Nz Event must be an Update instancer'   r   r   r   r'   r6   r   )r   r!   r   r   r   )r1   rn   r   r6   r2   r2   r3   r     s   
z SceneRegistry._update_middlewarec                   s6   |d }t | |j||d |d|d< |||I d H S )Nr   r'   r   r   )r   r   )r1   rn   r   r6   r   r2   r2   r3   r     s   
zSceneRegistry._middlewareN)r   r   r   Optional[Router]c                G  st   |st d|D ]/}|jj| jv rtd|jjd|| j|jj< |r,||  q| jr7| j|  qdS )a  
        This method adds the specified scenes to the registry
        and optionally registers it to the router.

        If a scene with the same state already exists in the registry, a SceneException is raised.

        .. warning::

            If the router is not specified, the scenes will not be registered to the router.
            You will need to include the scenes manually to the router or use the register method.

        :param scenes: A variable length parameter that accepts one or more types of scenes.
            These scenes are instances of the Scene class.
        :param router: An optional parameter that specifies the router
            to which the scenes should be added.
        :return: None
        z$At least one scene must be specifiedzScene with state z already existsN)	
ValueErrorr   r'   r   r   include_routerr   r   r   )r1   r   r   rA   r2   r2   r3   r   $  s   zSceneRegistry.addc                 G  s   | j |d| ji dS )z
        Registers one or more scenes to the SceneRegistry.

        :param scenes: One or more scene classes to register.
        :return: None
        r   N)r   r   )r1   r   r2   r2   r3   r   F  s   zSceneRegistry.registerrA   r   c                 C  sr   t |rt|tr|jj}t|tr|j}|dur#t|ts#t	dz| j
| W S  ty8   t	d|dw )ae  
        This method returns the registered Scene object for the specified scene.
        The scene parameter can be either a Scene object, State object or a string representing
        the name of the scene. If a Scene object is provided, the state attribute
        of the SceneConfig object associated with the Scene object will be used as the scene name.
        If a State object is provided, the state attribute of the State object will be used as the
        scene name. If None or an invalid type is provided, a SceneException will be raised.

        If the specified scene is not registered in the SceneRegistry object,
        a SceneException will be raised.

        :param scene: A Scene object, State object or a string representing the name of the scene.
        :return: The registered Scene object corresponding to the given scene parameter.

        Nz4Scene must be a subclass of Scene, State or a stringzScene z is not registered)rw   isclassr   r   r   r'   r   r   r)   r   r   KeyError)r1   rA   r2   r2   r3   rL   O  s   
zSceneRegistry.getr   )r   r   r   r   r8   r9   r   )rn   r   r   r    r6   r7   r8   r   )r   r   r   r   r8   r9   )r   r   r8   r9   )rA   r   r8   r   )r]   r^   r_   r   r4   r   r   r   r   r   rL   r2   r2   r2   r3   r     s    



"	r   c                   @  sL   e Zd ZU ded< dZded< edddZedd	d
ZedddZdS )Afterr~   rd   Nr   rA   r8   c                 C     | t jdS Nrd   )r~   r   r   r2   r2   r3   r   q     z
After.exitc                 C  r  r  )r~   r   r  r2   r2   r3   r   u  r  z
After.backc                 C  s   | t j|dS )N)rd   rA   )r~   r   )r   rA   r2   r2   r3   r   y  s   z
After.goto)r8   r  )rA   r   r8   r  )	r]   r^   r_   r   rA   r   r   r   r   r2   r2   r2   r3   r  l  s   
 r  c                   @  sN   e Zd ZdddZdddddZdddZdddZdddZdddZdS )ObserverMarkerra   r)   r8   r9   c                 C  s
   || _ d S rT   r   )r1   ra   r2   r2   r3   r4     s   
zObserverMarker.__init__Nr   rb   r   rf   rg   r`   c                G  s   t | j||dS )Nr   )r`   ra   )r1   rf   rb   r2   r2   r3   r{     s
   zObserverMarker.__call__c                 G  s   t | j|tjdS r  )r`   ra   r~   r   )r1   rb   r2   r2   r3   r     r   zObserverMarker.enterc                 C     t | jdtjdS Nr2   r  )r`   ra   r~   r   rR   r2   r2   r3   r     r   zObserverMarker.leavec                 C  r	  r
  )r`   ra   r~   r   rR   r2   r2   r3   r     r   zObserverMarker.exitc                 C  r	  r
  )r`   ra   r~   r   rR   r2   r2   r3   r     r   zObserverMarker.back)ra   r)   r8   r9   )rb   r   rf   rg   r8   r`   )rb   r   r8   r`   )r8   r`   )	r]   r^   r_   r4   r{   r   r   r   r   r2   r2   r2   r3   r  ~  s    



r  c                   @  s   e Zd ZdZedZedZedZedZedZ	edZ
edZed	Zed
ZedZedZedZedZedZdS )OnMarkera}  
    The `OnMarker` class is used as a marker class to define different
    types of events in the Scenes.

    Attributes:

    - :code:`message`: Event marker for handling `Message` events.
    - :code:`edited_message`: Event marker for handling edited `Message` events.
    - :code:`channel_post`: Event marker for handling channel `Post` events.
    - :code:`edited_channel_post`: Event marker for handling edited channel `Post` events.
    - :code:`inline_query`: Event marker for handling `InlineQuery` events.
    - :code:`chosen_inline_result`: Event marker for handling chosen `InlineResult` events.
    - :code:`callback_query`: Event marker for handling `CallbackQuery` events.
    - :code:`shipping_query`: Event marker for handling `ShippingQuery` events.
    - :code:`pre_checkout_query`: Event marker for handling `PreCheckoutQuery` events.
    - :code:`poll`: Event marker for handling `Poll` events.
    - :code:`poll_answer`: Event marker for handling `PollAnswer` events.
    - :code:`my_chat_member`: Event marker for handling my chat `Member` events.
    - :code:`chat_member`: Event marker for handling chat `Member` events.
    - :code:`chat_join_request`: Event marker for handling chat `JoinRequest` events.
    - :code:`error`: Event marker for handling `Error` events.

    .. note::

        This is a marker class and does not contain any methods or implementation logic.
    messageedited_messagechannel_postedited_channel_postinline_querychosen_inline_resultr   shipping_querypre_checkout_querypollpoll_answermy_chat_memberchat_memberchat_join_requestN)r]   r^   r_   r   r  r  r  r  r  r  r  r   r  r  r  r  r  r  r  r2   r2   r2   r3   r    s     r  )r   r   r   r   r8   r9   )E
__future__r   rw   collectionsr   dataclassesr   r   enumr   r   typingr   r	   r
   r   r   r   r   r   r   r   typing_extensionsr   aiogramr   aiogram.dispatcher.dispatcherr   aiogram.dispatcher.event.basesr    aiogram.dispatcher.event.handlerr   r   aiogram.dispatcher.flagsr   aiogram.dispatcher.routerr   aiogram.exceptionsr   aiogram.filtersr   aiogram.fsm.contextr   aiogram.fsm.stater   aiogram.fsm.storage.memoryr   aiogram.typesr    r!   "aiogram.utils.class_attrs_resolverr"   r#   r$   r`   r~   r|   rq   r   r   r   r   r   r   r   r  r  r  onr2   r2   r2   r3   <module>   sR    0I<
5  WT 
,