+
    Qi;D                    t  a  0 t $ ^ RIHt ^ RIt^ RIt^ RIHtHt ^ RIH	t	 ^ RI
Ht ^ RIHt ^ RIHtHtHtHtHt ]P*                  R,8  d   ^ RIHt M^ RIHt ^R	IHtHtHtHt ^R
IHt ]P>                  ! R. R-O4      t R t!R t"R t#]! RR7       ! R R]$4      4       t%R R lt&R t'R t(R R lt)R t*]! R4      t+]! R4      t,]! RR7       ! R R]$4      4       t-]! RR7       ! R  R!]$4      4       t.]]/.R3,          t0R"t1R#]2R$&   R% R& lt3]! RR7       ! R' R(]$4      4       t4]! 4       t5R) t6 ! R* R+]$4      t7R# ).    )annotationsN)	dataclassfieldwraps)getfullargspec)count)AnyCallableHashableIterableTypeVar)	TypeAlias)	AutomatonOutputTracerTracerTransitioner)preserveNameArgSpecc                   \        V 4      p\        \        VP                  4      VP                  VP
                  VP                  '       d   VP                  MR\        VP                  4      VP                  '       d$   \        VP                  P                  4       4      MR\        VP                  P                  4       4      R7      # )z
Normalize inspect.ArgSpec across python versions
and convert mutable attributes to immutable types.

:param Callable func: A function.
:return: The function's ArgSpec.
:rtype: ArgSpec
argsvarargsvarkwdefaults
kwonlyargskwonlydefaultsr    )getArgsSpecr   tupler   r   r   r   r   r   itemsr   )funcspecs   & 5/usr/lib/python3/dist-packages/automat/_methodical.py_getArgSpecr%   "   s     tD499jj"&---R)262E2E2EE$%%++-.2$**0023
 
    c                X   \        V P                  V P                  ,           V P                  '       d   RMR,           V P                  '       d   RMR,           \
        ;QJ d(    . R V P                   4       F  NK  	  5,           4      # ! R V P                   4       4      ,           4      # )a  
Get the name of all arguments defined in a function signature.

The name of * and ** arguments is normalized to "*args" and "**kwargs".

Return type annotations are omitted, since we don't constrain input methods
to have the same return type as output methods, nor output methods to have
the same output type.

:param ArgSpec spec: A function to interrogate for a signature.
:return: The set of all argument names in `func`s signature.
:rtype: Set[str]
c              3  D   "   T F  q^ ,          R8w  g   K  Vx  K  	  R# 5i)r   returnNr   ).0as   & r$   	<genexpr>_getArgNames.<locals>.<genexpr>L   s     @+atx/?+s    
 )z*argsr   )z**kwargs)setr   r   r   r   r    r   )r#   s   &r$   _getArgNamesr/   9   s     		
//	:2	/ !JJJ=B	0 %@4++@%		A 
 @4++@
@		A r&   c                0   a  \        S 4      V 3R l4       pV# )z
Decorate a function so all its arguments must be passed by keyword.

A useful utility for decorators that take arguments so that they don't
accidentally get passed the thing they're decorating as their first
argument.

Only works for methods right now.
c                   < S! V 3/ VB # Nr   )selfkwfs   &,r$   g_keywords_only.<locals>.g[   s    }}r&   r   )r5   r6   s   f r$   _keywords_onlyr8   P   s"     1X  Hr&   T)frozenc                      ] tR t^bt$ Rt]! RR7      tR]R&   ]! 4       tR]R&   ]! RR7      t	R]R	&   R
R
]
3R R lltR R ltRtR
# )MethodicalStatez%
A state for a L{MethodicalMachine}.
FreprMethodicalMachinemachineCallable[..., Any]methodbool
serializedNc          
     ,    V ^8  d   QhRRRRRRRRR	R
/# )   inputMethodicalInputenterzMethodicalState | Noneoutputsz!Iterable[MethodicalOutput] | None	collectorzCallable[[Iterable[T]], object]r)   Noner   )formats   "r$   __annotate__MethodicalState.__annotate__l   sC     .L .L.L &.L 3	.L
 3.L 
.Lr&   c                   Vf   T pVf   . p\        VP                  4      pV F  p\        VP                  4      pVP                  V4      '       d   K1  \        RP	                  VP
                  P                  VP
                  P                  \        VP
                  4      \        VP
                  4      R7      4      h	  V P                  P                  WW#V4       R# )a  
Declare a state transition within the L{MethodicalMachine} associated
with this L{MethodicalState}: upon the receipt of the `input`, enter
the `state`, emitting each output in `outputs`.

@param input: The input triggering a state transition.

@param enter: The resulting state.

@param outputs: The outputs to be triggered as a result of the declared
    state transition.

@param collector: The function to be used when collecting output return
    values.

@raises TypeError: if any of the `outputs` signatures do not match the
    `inputs` signature.

@raises ValueError: if the state transition from `self` via `input` has
    already been defined.
Nzdmethod {input} signature {inputSignature} does not match output {output} signature {outputSignature})rF   outputinputSignatureoutputSignature)
r/   argSpecissubset	TypeErrorrL   rA   __name__r   r?   _oneTransition)r3   rF   rH   rI   rJ   	inputArgsrP   
outputArgss   &&&&&   r$   uponMethodicalState.uponl   s    8 =E?G /	F%fnn5J&&y11228&#ll33%}}55'25<<'@(3FMM(B	 39 3	 	  	##DKr&   c                   V ^8  d   QhRR/# rE   r)   strr   )rL   s   "r$   rM   rN           $ $s $r&   c                	.    V P                   P                  # r2   rA   rV   r3   s   &r$   _nameMethodicalState._name       {{###r&   r   )rV   
__module____qualname____firstlineno____doc__r   r?   __annotations__rA   rC   listrZ   rc   __static_attributes__r   r&   r$   r;   r;   b   sQ     "'E!2G2!&F(%(J(
 )-5959.L`$ $r&   r;   c               (    V ^8  d   QhRRRRRRRR/# )	rE   oselfobjectsymbolr^   	automaton=Automaton[MethodicalState, MethodicalInput, MethodicalOutput]r)   z@Transitioner[MethodicalState, MethodicalInput, MethodicalOutput]r   )rL   s   "r$   rM   rM      s2       M F	r&   c                j    \        WR4      pVf#   \        VVP                  4      p\        WV4       V# )z
Get a L{Transitioner}
N)getattrr   initialStatesetattr)rn   rp   rq   transitioners   &&& r$   _transitionerFromInstancerx      s>     5$/L#""
 	|,r&   c                     R # r2   r   r   r&   r$   _emptyrz      s    r&   c                     R# )	docstringNr   r   r&   r$   
_docstringr}      s    r&   c                    V ^8  d   QhRRRR/# )rE   r5   r@   r)   rK   r   )rL   s   "r$   rM   rM      s     8 8& 84 8r&   c                    V P                   P                  \        P                   P                  \        P                   P                  39  d   \	        R 4      hR# )zfunction body must be emptyN)__code__co_coderz   r}   
ValueError)r5   s   &r$   assertNoCoder      sC     	zz&//"9"9:;N;N;V;V!WW677 Xr&   c                   \        \        VP                  R,          V 4      4      pVP                  '       d   T pM'V UUu. uF  w  rgWcP                  9   g   K  VNK  	  ppp\        V4      pV F  w  rWV
3,          pK  	  \        VP                  RRR1,          VP                  RRR1,          4      pV UUu/ uF  w  rgWh9  g   K  WgbK  	  pppVP                  V4       VP                  '       d   TpW]3# VP                  R,          VP                  ,           pVP                  4        UUu/ uF  w  rgWn9   g   K  WgbK  	  pppW]3# u uppi u uppi u uppi )af  
Filter out arguments that were passed to input that output won't accept.

:param tuple args: The *args that input received.
:param dict kwargs: The **kwargs that input received.
:param ArgSpec inputSpec: The input's arg spec.
:param ArgSpec outputSpec: The output's arg spec.
:return: The args and kwargs that output will accept.
:rtype: Tuple[tuple, dict]
:   NNN)	r    zipr   r   r   updater   r   r!   )r   kwargs	inputSpec
outputSpec
named_argsreturn_argsnvpassed_arg_namesnamevaluer   full_kwargsreturn_kwargsall_accepted_namess   &&&&           r$   _filterArgsr      sQ    s9>>"-t45J &0HZTQ13GqqZH V}!5M) "9>>$B$'););DbD)ABH$,JHDA0I414HKJv# %% (__R0:3H3HH(..0
0TQA4KDAD0 	 
 %%) I K
s$   EE<
EE3
EETRF)eqc                      ] tR t^t$ Rt]! RR7      tR]R&   ]! 4       tR]R&   ]! RR7      t	R]R	&   ]! ]
RR
7      tR]R&   ]! RRR7      tR]R&   R R ltRR R lltR R ltRtR# )rG   z&
An input for a L{MethodicalMachine}.
Fr<   rr   rq   r@   rA   r^   rp   )default_factoryr=   z1dict[MethodicalState, Callable[[Iterable[T]], R]]
collectors)initr=   r   rS   c                   V ^8  d   QhRR/# rE   r)   rK   r   )rL   s   "r$   rM   MethodicalInput.__annotate__  s     " "t "r&   c                	d    \        V P                  4      V n        \        V P                  4       R # r2   )r%   rA   rS   r   rb   s   &r$   __post_init__MethodicalInput.__post_init__  s    "4;;/T[[!r&   Nc               $    V ^8  d   QhRRRRRR/# )rE   rn   ro   typerK   r)   r   )rL   s   "r$   rM   r     s!      V 4 6 r&   c                   a aa \        SS P                  S P                  4      o\        S P                  4      \        S P                  4      R VV V3R ll4       4       pV# )z
Return a function that takes no arguments and returns values returned
by output functions produced by the given L{MethodicalInput} in
C{oself}'s current state.
c               $    V ^8  d   QhRRRRRR/# )rE   r   ro   r   r)   r   )rL   s   "r$   rM   -MethodicalInput.__get__.<locals>.__annotate__  s!     	% 	%6 	%V 	% 	%r&   c                 R  < SP                   ! S.V O5/ VB  SP                  pSP                  S4      w  r4SP                  V,          p. pV FO  pVe	   V! V4       \	        WSP
                  VP
                  4      w  rV! S.VO5/ V	B p
VP                  V
4       KQ  	  V! V4      # r2   )rA   _state
transitionr   r   rS   append)r   r   previousStaterI   	outTracerrJ   valuesrP   r+   kr   rn   r3   rw   s   *,         r$   doInput(MethodicalInput.__get__.<locals>.doInput  s     KK///(//M#/#:#:4#@ W6IF!(f%"4v~~Nu.q.A.e$ " V$$r&   )rx   rp   rq   r   rA   r   )r3   rn   r   r   rw   s   ff& @r$   __get__MethodicalInput.__get__  sS     1T^^T	dkk	"	t{{		% 	% 
 
#	% r&   c                   V ^8  d   QhRR/# r]   r   )rL   s   "r$   rM   r   &  r_   r&   c                	.    V P                   P                  # r2   ra   rb   s   &r$   rc   MethodicalInput._name&  re   r&   )rS   r2   )rV   rf   rg   rh   ri   r   rq   rj   rA   rp   dictr   rS   r   r   rc   rl   r   r&   r$   rG   rG      s~     PUPIL  "'F(U#FC#DI5EJA  %e4GW4"4$ $r&   rG   c                      ] tR tRt$ Rt]! RR7      tR]R&   R]R&   ]! RRRR	7      tR
]R&   R R lt	RR lt
R tR R ltRtR# )MethodicalOutputi*  z'
An output for a L{MethodicalMachine}.
Fr<   r>   r?   r@   rA   )r   r=   comparer   rS   c                   V ^8  d   QhRR/# r   r   )rL   s   "r$   rM   MethodicalOutput.__annotate__4  s     < <t <r&   c                	J    \        V P                  4      V P                  R &   R# )rS   N)r%   rA   __dict__rb   s   &r$   r   MethodicalOutput.__post_init__4  s    #.t{{#;i r&   Nc                v    \        RP                  VP                  V P                  P                  R7      4      h)zH
Outputs are private, so raise an exception when we attempt to get one.
zf{cls}.{method} is a state-machine output method; to produce this output, call an input method instead.)clsrA   )AttributeErrorrL   rV   rA   r3   rn   r   s   &&&r$   r   MethodicalOutput.__get__7  s<     DDJFMM$++*>*> EK E
 	
r&   c                .    V P                   ! V.VO5/ VB # )z
Call the underlying method.
)rA   )r3   rn   r   r   s   &&*,r$   __call__MethodicalOutput.__call__B  s     {{5242622r&   c                   V ^8  d   QhRR/# r]   r   )rL   s   "r$   rM   r   H  r_   r&   c                	.    V P                   P                  # r2   ra   rb   s   &r$   rc   MethodicalOutput._nameH  re   r&   r   r2   )rV   rf   rg   rh   ri   r   r?   rj   rS   r   r   r   rc   rl   r   r&   r$   r   r   *  sK     "'E!2G2%eUCGWC<	
3$ $r&   r   z4Callable[[str, str, str], StringOutputTracer | None]r   StringTracerc                    V ^8  d   QhRRRR/# )rE   wrappedStringTracer | Noner)   zATracer[MethodicalState, MethodicalInput, MethodicalOutput] | Noner   )rL   s   "r$   rM   rM   P  s       Fr&   c                &   a  S f   R # R V 3R llpV# )Nc               (    V ^8  d   QhRRRRRRRR/# )rE   stater;   rF   rG   rP   r)   z%OutputTracer[MethodicalOutput] | Noner   )rL   s   "r$   rM    wrapTracer.<locals>.__annotate__V  s0         
/	r&   c                   <a S! V P                  4       VP                  4       VP                  4       4      oSe   V3R l# R # )Nc                0   < S! V P                  4       4      # r2   rc   )outresults   &r$   <lambda>,wrapTracer.<locals>.tracer.<locals>.<lambda>]  s    vciik2r&   r   )r   rF   rP   r   r   s   &&&@r$   tracerwrapTracer.<locals>.tracerV  s4    
 v||~F22r&   r   )r   r   s   f r$   
wrapTracerr   P  s       Mr&   c                  `    ] tR tRt$ ]! RR7      tR]R&   ]! RR7      tR]R&   RR	 R
 lltRt	R# )MethodicalTraceric  Fr<   rr   rq   r^   rp   Nc               $    V ^8  d   QhRRRRRR/# )rE   rn   ro   r   r)   zCallable[[StringTracer], None]r   )rL   s   "r$   rM   MethodicalTracer.__annotate__j  s$      #)	'r&   c                	Z   a \        WP                  V P                  4      oR  V3R llpV# )c                    V ^8  d   QhRRRR/# )rE   r   r   r)   rK   r   )rL   s   "r$   rM   .MethodicalTracer.__get__.<locals>.__annotate__o  s     	6 	60 	6T 	6r&   c                <   < SP                  \        V 4      4       R # r2   )setTracer   )r   rw   s   &r$   r   *MethodicalTracer.__get__.<locals>.setTraceo  s    !!*V"45r&   )rx   rp   rq   )r3   rn   r   r   rw   s   &&& @r$   r   MethodicalTracer.__get__j  s*     1T^^T	6 	6 r&   r   r2   )
rV   rf   rg   rh   r   rq   rj   rp   r   rl   r   r&   r$   r   r   c  s3    OTPIL  U#FC# r&   r   c                 @    R\        \        \        4      4      ,           # )z$
Create a unique Python identifier.
_symbol_)r^   nextcounterr   r&   r$   gensymr   x  s     DM***r&   c                      ] tR tRtRtR tRR lt]RR R ll4       t]R 4       t	]R	 4       t
R
 t]R 4       t]R 4       t]R R l4       tR tRtR# )r>   i  zY
A L{MethodicalMachine} is an interface to an L{Automaton} that uses methods
on a class.
c                	P    \        4       V n        / V n        \        4       V n        R # r2   )r   
_automaton	_reducersr   _symbolrb   s   &r$   __init__MethodicalMachine.__init__  s    #+xr&   Nc                $    Ve   \        R4      hV # )z
L{MethodicalMachine} is an implementation detail for setting up
class-level state; applications should never need to access it on an
instance.
z.MethodicalMachine is an implementation detail.)r   r   s   &&&r$   r   MethodicalMachine.__get__  s      !QRRr&   c               $    V ^8  d   QhRRRRRR/# )rE   initialrB   terminalrC   r   r   )rL   s   "r$   rM   MethodicalMachine.__annotate__  s$      /3IQr&   c                   a aa VV V3R lpV# )a  
Declare a state, possibly an initial state or a terminal state.

This is a decorator for methods, but it will modify the method so as
not to be callable any more.

@param initial: is this state the initial state?  Only one state on
    this L{automat.MethodicalMachine} may be an initial state; more
    than one is an error.

@param terminal: Is this state a terminal state?  i.e. a state that the
    machine can end up in?  (This is purely informational at this
    point.)

@param serialized: a serializable value to be used to represent this
    state to external systems.  This value should be hashable; L{str}
    is a good type to use.
c                V   < \        SV SR 7      pS'       d   VSP                  n        V# ))r?   rA   rC   )r;   r   ru   )stateMethodr   r   r3   rC   s   & r$   	decorator*MethodicalMachine.state.<locals>.decorator  s*    #[ZE /4,Lr&   r   )r3   r   r   rC   r   s   ff&f r$   r   MethodicalMachine.state  s    .	 r&   c                   a  V 3R lpV# )z5
Declare an input.

This is a decorator for methods.
c                H   < \        SP                  V SP                  R 7      # ))rq   rA   rp   )rG   r   r   )inputMethodr3   s   &r$   r   *MethodicalMachine.input.<locals>.decorator  s    "//+dll r&   r   r3   r   s   f r$   rF   MethodicalMachine.input  s    	
 r&   c                   a  V 3R lpV# )z
Declare an output.

This is a decorator for methods.

This method will be called when the state machine transitions to this
state as specified in the decorated `output` method.
c                   < \        SV R 7      # ))r?   rA   )r   )outputMethodr3   s   &r$   r   +MethodicalMachine.output.<locals>.decorator  s    #DFFr&   r   r  s   f r$   rP   MethodicalMachine.output  s    	G r&   c                n    V P                   P                  WV\        V4      4       WRP                  V&   R# )z
See L{MethodicalState.upon}.
N)r   addTransitionr    r   )r3   
startState
inputTokenendStateoutputTokensrJ   s   &&&&&&r$   rW    MethodicalMachine._oneTransition  s2    $ 	%%HeL.A	
 -6j)r&   c                   a  V 3R lpV# ) c                4   <a  \        S 4      V V3R  l4       pV# )c                ~   < \        V SP                  SP                  4      pS! WP                  P                  4      # r2   )rx   r   r   r   rC   )rn   rw   	decorateer3   s   & r$   	serializeBMethodicalMachine.serializer.<locals>.decorator.<locals>.serialize  s5    84<<  !(;(;(F(FGGr&   r   )r  r  r3   s   f r$   r   /MethodicalMachine.serializer.<locals>.decorator  s$    9H H r&   r   r  s   f r$   
serializerMethodicalMachine.serializer  s    	 r&   c                   a  V 3R lpV# )r  c                4   <a  \        S 4      V V3R  l4       pV# )c                   < S! V .VO5/ VB p/ pSP                   P                  4        F  pWTVP                  &   K  	  \        V SP                  SP                   4      pWC,          Vn        R # r2   )r   statesrC   rx   r   r   )	rn   r   r   r   mapping	eachStaterw   r  r3   s	   &*,    r$   unserializeFMethodicalMachine.unserializer.<locals>.decorator.<locals>.unserialize   si    !%9$9&9!%!7!7!9I4=I001 ":84<<  '.n#r&   r   )r  r#  r3   s   f r$   r   1MethodicalMachine.unserializer.<locals>.decorator  s"    9	 	 r&   r   r  s   f r$   unserializerMethodicalMachine.unserializer  s    	 r&   c                   V ^8  d   QhRR/# )rE   r)   r   r   )rL   s   "r$   rM   r     s     ? ?+ ?r&   c                	B    \        V P                  V P                  4      # r2   )r   r   r   rb   s   &r$   	_setTraceMethodicalMachine._setTrace  s    >>r&   c                @    ^RI Hp V! V P                  R R R R7      # )z
Generate a L{graphviz.Digraph} that represents this machine's
states and transitions.

@return: L{graphviz.Digraph} object; for more information, please
    see the documentation for
    U{graphviz<https://graphviz.readthedocs.io/>}

)makeDigraphc                .    V P                   P                  # r2   ra   )r   s   &r$   r   -MethodicalMachine.asDigraph.<locals>.<lambda>"      (=(=r&   c                .    V P                   P                  # r2   ra   )rF   s   &r$   r   r/  #  r0  r&   c                .    V P                   P                  # r2   ra   )rP   s   &r$   r   r/  $  s    &--*@*@r&   )stateAsStringinputAsStringoutputAsString)
_visualizer-  r   )r3   r-  s   & r$   	asDigraphMethodicalMachine.asDigraph  s$     	,OO==@	
 	
r&   )r   r   r   r2   )FFN)rV   rf   rg   rh   ri   r   r   r8   r   rF   rP   rW   r  r&  propertyr*  r7  rl   r   r&   r$   r>   r>     s    
 
  @    6.    ( ? ?
r&   r>   )   
   r   )8__conditional_annotations__
__future__r   collectionssysdataclassesr   r   	functoolsr   inspectr   r   	itertoolsr	   typingr
   r   r   r   r   version_infotyping_extensionsr   _corer   r   r   r   _introspectionr   
namedtupler   r%   r/   r8   ro   r;   rx   rz   r}   r   r   r   r   rG   r   r^   StringOutputTracerr   rj   r   r   r   r   r>   )r<  s   @r$   <module>rK     sW   " "  
 (  1  = =g+  @ @ (

 
 ..$ $:$f :$ :$z$	8 &&R CLCL e/$f /$ /$d $$v $ $B seTk* Pi P& ev  " '+f
 f
r&   