
    tf                     n    d Z ddlmZ dZ G d de          Z G d de          Z G d d	e          Zd
S )zp
A core state-machine abstraction.

Perhaps something that could be replaced with or integrated into machinist.
    )chainz
<no state>c                   "     e Zd ZdZ fdZ xZS )NoTransitionz
    A finite state machine in C{state} has no transition for C{symbol}.

    @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.
    c                     || _         || _        t          t          |                               d                    ||                     d S )Nzno transition for {} in {})statesymbolsuper	Exception__init__format)selfr   r   	__class__s      L/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/automat/_core.pyr   zNoTransition.__init__   sP    
i''(//>>	
 	
 	
 	
 	
    )__name__
__module____qualname____doc__r   __classcell__)r   s   @r   r   r      sB         
 
 
 
 
 
 
 
 
r   r   c                   r    e Zd ZdZd Zed             Zej        d             Zd Zd Z	d Z
d Zd	 Zd
 ZdS )	Automatonzr
    A declaration of a finite state machine.

    Note that this is not the machine itself; it is immutable.
    c                 D    t           | _        t                      | _        dS )zJ
        Initialize the set of transitions and the initial state.
        N)	_NO_STATE_initialStateset_transitionsr   s    r   r   zAutomaton.__init__'   s     'EEr   c                     | j         S )z8
        Return this automaton's initial state.
        )r   r   s    r   initialStatezAutomaton.initialState/   s    
 !!r   c                 ~    | 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   s     r   r   zAutomaton.initialState7   sK     Y..1889KLLN N N #r   c                     | j         D ]6\  }}}}||k    r)||k    r#t          d                    ||                    7| 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 {} via {}N)r   r!   r   addtuple)	r   inStateinputSymboloutStateoutputSymbols	anInStateanInputSymbol
anOutState_s	            r   addTransitionzAutomaton.addTransitionE   s     :>9J 	[ 	[5Yz1W$$+)E)E <CCG[YY[ [ [k8U=-A-AB	
 	
 	
 	
 	
r   c                 *    t          | j                  S )z"
        All transitions.
        )	frozensetr   r   s    r   allTransitionszAutomaton.allTransitionsV   s     *+++r   c                 $    d | j         D             S )zG
        The full set of symbols acceptable to this automaton.
        c                     h | ]	\  }}}}|
S  r3   .0r%   r&   r'   outputSymbols        r   	<setcomp>z*Automaton.inputAlphabet.<locals>.<setcomp>a   s9     E E E !/+x!-  E E Er   )r   r   s    r   inputAlphabetzAutomaton.inputAlphabet]   s,    E E262CE E E 	Er   c                 b    t          t          j        d | j        D                                 S )zR
        The full set of symbols which can be produced by this automaton.
        c              3   $   K   | ]\  }}}}|V  d S Nr3   )r5   r%   r&   r'   r(   s        r   	<genexpr>z+Automaton.outputAlphabet.<locals>.<genexpr>j   s>          ?+x            r   )r   r   from_iterabler   r   s    r   outputAlphabetzAutomaton.outputAlphabete   sG          $       
 
 	
r   c                 b    t          t          j        d | j        D                                 S )zc
        All valid states; "Q" in the mathematical description of a state
        machine.
        c              3   (   K   | ]\  }}}}||fV  d S r;   r3   r4   s        r   r<   z#Automaton.states.<locals>.<genexpr>x   sE           ?+x (#           r   )r/   r   r=   r   r   s    r   stateszAutomaton.statesr   sG    
      $	       
 
 	
r   c                 |    | j         D ]$\  }}}}||f||fk    r|t          |          fc S %t          ||          )zI
        A 2-tuple of (outState, outputSymbols) for inputSymbol.
        )r   r   )r   listr   )r   r%   r&   r)   r*   r'   r(   s          r   outputForInputzAutomaton.outputForInput   si    
 *.):	7 	7 &Y}%)])CCC $}"5"56666 D====r   N)r   r   r   r   r   propertyr   setterr-   r0   r8   r>   rA   rD   r3   r   r   r   r       s         " " " " " X" 
# 
# 
#
 
 
", , ,E E E

 

 


 
 
> > > > >r   r   c                   $    e Zd ZdZd Zd Zd ZdS )TransitionerzA
    The combination of a current state and an L{Automaton}.
    c                 0    || _         || _        d | _        d S r;   )
_automaton_state_tracer)r   	automatonr   s      r   r   zTransitioner.__init__   s    #"r   c                     || _         d S r;   )rL   )r   tracers     r   setTracezTransitioner.setTrace   s    r   c                    | j                             | j        |          \  }}d}| j        rR|                     | j                                        |                                |                                          }|| _        ||fS )zC
        Transition between states, returning any outputs.
        N)rJ   rD   rK   rL   _name)r   r&   r'   r(   	outTracers        r   
transitionzTransitioner.transition   s     #'/"@"@AL#N #N-	< 	7T[%6%6%8%8%0%6%6%8%8%-^^%5%57 7I y))r   N)r   r   r   r   r   rP   rT   r3   r   r   rH   rH      sK           
  * * * * *r   rH   N)	r   	itertoolsr   r   r
   r   objectr   rH   r3   r   r   <module>rW      s          	
 
 
 
 
9 
 
 
$i> i> i> i> i> i> i> i>X* * * * *6 * * * * *r   