o
    >h                     @  s   U d Z ddlmZ ddlZddlmZ ddlmZmZm	Z	m
Z
mZmZ ejdkr/ddlmZ nddlmZ dZed	ed
Zeded
Zeded
ZG dd deeeef ZG dd deeeef Zeegdf ZdZded< G dd deeeef ZdS )zp
A core state-machine abstraction.

Perhaps something that could be replaced with or integrated into machinist.
    )annotationsN)chain)CallableGenericOptionalSequenceTypeVarHashable)   
   )	TypeAliasz
<no state>State)boundInputOutputc                      s"   e Zd ZdZd fddZ  ZS )	NoTransitionz
    A finite state machine in C{state} has no transition for C{symbol}.

    @ivar state: See C{state} init parameter.

    @ivar symbol: See C{symbol} init parameter.
    stater   symbolr   c                   s(   || _ || _tt| d|| dS )z
        Construct a L{NoTransition}.

        @param state: the finite state machine's state at the time of the
            illegal transition.

        @param symbol: the input symbol for which no transition exists.
        zno transition for {} in {}N)r   r   super	Exception__init__format)selfr   r   	__class__ m/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/automat/_core.pyr   "   s
   	

zNoTransition.__init__)r   r   r   r   )__name__
__module____qualname____doc__r   __classcell__r   r   r   r   r      s    r   c                   @  s   e Zd ZdZd(d)ddZed*d
dZejd+ddZd,ddZd-ddZ	d.ddZ
d/ddZd0d d!Zd1d#d$Zd2d&d'ZdS )3	Automatonzr
    A declaration of a finite state machine.

    Note that this is not the machine itself; it is immutable.
    NinitialState | NonereturnNonec                 C  s0   |du rt }|dusJ || _t | _d| _dS )zJ
        Initialize the set of transitions and the initial state.
        N)	_NO_STATE_initialStateset_transitions_unhandledTransition)r   r#   r   r   r   r   9   s   
zAutomaton.__init__r   c                 C  s   | j S )z8
        Return this automaton's initial state.
        )r(   r   r   r   r   initialStateD   s   zAutomaton.initialStater   c                 C  s$   | j turtd| j || _ dS )z
        Set this automaton's initial state.  Raises a ValueError if
        this automaton already has an initial state.
        zinitial state already set to {}N)r(   r'   
ValueErrorr   )r   r   r   r   r   r-   K   s
   


inStateinputSymbolr   outStateoutputSymbolstuple[Output, ...]c           	      C  sR   | j D ]\}}}}||kr||krtd|||q| j |||t|f dS )z
        Add the given transition to the outputSymbol. Raise ValueError if
        there is already a transition with the same inState and inputSymbol.
        z,already have transition from {} to {} via {}N)r*   r.   r   addtuple)	r   r/   r0   r1   r2   	anInStateanInputSymbol
anOutState_r   r   r   addTransitionY   s   zAutomaton.addTransitionSequence[Output]c                 C  s   |t |f| _dS )z
        All unhandled transitions will be handled by transitioning to the given
        error state and error-handling output symbols.
        N)r5   r+   )r   r1   r2   r   r   r   unhandledTransitionp   s   zAutomaton.unhandledTransition7frozenset[tuple[State, Input, State, Sequence[Output]]]c                 C  s
   t | jS )z"
        All transitions.
        )	frozensetr*   r,   r   r   r   allTransitionsy   s   
zAutomaton.allTransitions
set[Input]c                 C  s   dd | j D S )zG
        The full set of symbols acceptable to this automaton.
        c                 S  s   h | ]\}}}}|qS r   r   .0r/   r0   r1   outputSymbolr   r   r   	<setcomp>   s    
z*Automaton.inputAlphabet.<locals>.<setcomp>)r*   r,   r   r   r   inputAlphabet   s   zAutomaton.inputAlphabetset[Output]c                 C     t tdd | jD S )zR
        The full set of symbols which can be produced by this automaton.
        c                 s  s    | ]	\}}}}|V  qd S Nr   )rB   r/   r0   r1   r2   r   r   r   	<genexpr>   s
    

z+Automaton.outputAlphabet.<locals>.<genexpr>)r)   r   from_iterabler*   r,   r   r   r   outputAlphabet   s
   
zAutomaton.outputAlphabetfrozenset[State]c                 C  rG   )zc
        All valid states; "Q" in the mathematical description of a state
        machine.
        c                 s  s     | ]\}}}}||fV  qd S rH   r   rA   r   r   r   rI      s
    

z#Automaton.states.<locals>.<genexpr>)r>   r   rJ   r*   r,   r   r   r   states   s
   
zAutomaton.statestuple[State, Sequence[Output]]c                 C  sP   | j D ]\}}}}||f||fkr|t|f  S q| jdu r%t||d| jS )zI
        A 2-tuple of (outState, outputSymbols) for inputSymbol.
        N)r   r   )r*   listr+   r   )r   r/   r0   r6   r7   r1   r2   r   r   r   outputForInput   s   
zAutomaton.outputForInputrH   )r#   r$   r%   r&   )r%   r   )r   r   r%   r&   )r/   r   r0   r   r1   r   r2   r3   )r1   r   r2   r;   r%   r&   )r%   r=   )r%   r@   )r%   rF   )r%   rL   )r/   r   r0   r   r%   rN   )r   r   r   r    r   propertyr-   setterr:   r<   r?   rE   rK   rM   rP   r   r   r   r   r"   2   s    


	

	
r"   z<Callable[[State, Input, State], OutputTracer[Output] | None]r   Tracerc                   @  s.   e Zd ZdZdddZdddZdddZdS )TransitionerzA
    The combination of a current state and an L{Automaton}.
    	automatonAutomaton[State, Input, Output]r-   r   c                 C  s   || _ || _d | _d S rH   )
_automaton_state_tracer)r   rU   r-   r   r   r   r      s   
zTransitioner.__init__tracer#Tracer[State, Input, Output] | Noner%   r&   c                 C  s
   || _ d S rH   )rY   )r   rZ   r   r   r   setTrace   s   
zTransitioner.setTracer0   r   4tuple[Sequence[Output], OutputTracer[Output] | None]c                 C  s<   | j | j|\}}d}| jr| | j||}|| _||fS )zC
        Transition between states, returning any outputs.
        N)rW   rP   rX   rY   )r   r0   r1   r2   	outTracerr   r   r   
transition   s   zTransitioner.transitionN)rU   rV   r-   r   )rZ   r[   r%   r&   )r0   r   r%   r]   )r   r   r   r    r   r\   r_   r   r   r   r   rT      s
    

rT   )r    
__future__r   sys	itertoolsr   typingr   r   r   r   r   r	   version_infor   typing_extensionsr'   r   r   r   r   r   r"   OutputTracerrS   __annotations__rT   r   r   r   r   <module>   s"    
{