
    h;D                    \   % S SK Jr  S SKrS SKrS SKJrJr  S SKJr  S SK	J
r  S SKJr  S SKJrJrJrJrJr  \R(                  S:  a  S S	KJr  OS S	KJr  S
SKJrJrJrJr  S
SKJr  \R<                  " S/ SQ5      rS r S r!S r"\" SS9 " S S\#5      5       r$        S,S jr%S r&S r'S-S jr(S r)\" S5      r*\" S5      r+\" SS9 " S S \#5      5       r,\" SS9 " S! S"\#5      5       r-\\./S4   r/S#r0S$\1S%'       S.S& jr2\" SS9 " S' S(\#5      5       r3\" 5       r4S) r5 " S* S+\#5      r6g)/    )annotationsN)	dataclassfieldwraps)getfullargspec)count)AnyCallableHashableIterableTypeVar)   
   )	TypeAlias   )	AutomatonOutputTracerTracerTransitioner)preserveNameArgSpecargsvarargsvarkwdefaults
kwonlyargskwonlydefaultsr   c                   [        U 5      n[        [        UR                  5      UR                  UR
                  UR                  (       a  UR                  OS[        UR                  5      UR                  (       a#  [        UR                  R                  5       5      OS[        UR                  R                  5       5      S9$ )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
 r   )getArgsSpecr   tupler   r   r   r   r   r   itemsr   )funcspecs     Z/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/automat/_methodical.py_getArgSpecr(   "   s     tD499jj"&--R)262E2EE$%%++-.2$**0023
 
    c                    [        U R                  U R                  -   U R                  (       a  SOS-   U R                  (       a  SOS-   [        S U R                   5       5      -   5      $ )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]
)z*argsr!   )z**kwargsc              3  :   #    U  H  oS    S:w  d  M  Uv   M     g7f)r   returnNr!   ).0as     r'   	<genexpr>_getArgNames.<locals>.<genexpr>L   s     @+atx/?+s   	)setr   r   r   r   r#   r   )r&   s    r'   _getArgNamesr2   9   sb     		
//	:2	/ !JJ=B	0 @4++@
@		A r)   c                0   ^  [        T 5      U 4S j5       nU$ )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                   > T" U 40 UD6$ Nr!   )selfkwfs     r'   g_keywords_only.<locals>.g[   s    }}r)   r   )r8   r9   s   ` r'   _keywords_onlyr;   P   s"     1X  Hr)   T)frozenc                      \ rS rSr% Sr\" SS9rS\S'   \" 5       rS\S'   \" SS9r	S	\S
'   SS\
4         SS jjrSS jrSrg)MethodicalStateb   z%
A state for a L{MethodicalMachine}.
FreprMethodicalMachinemachineCallable[..., Any]methodbool
serializedNc                   Uc  U nUc  / n[        UR                  5      nU H  n[        UR                  5      nUR                  U5      (       a  M0  [        SR	                  UR
                  R                  UR
                  R                  [        UR
                  5      [        UR
                  5      S95      e   U R                  R                  XX#U5        g)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})inputoutputinputSignatureoutputSignature)
r2   argSpecissubset	TypeErrorformatrE   __name__r"   rC   _oneTransition)r6   rI   enteroutputs	collector	inputArgsrJ   
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                .    U R                   R                  $ r5   rE   rQ   r6   s    r'   _nameMethodicalState._name       {{###r)   r!   )
rI   MethodicalInputrS   zMethodicalState | NonerT   z!Iterable[MethodicalOutput] | NonerU   zCallable[[Iterable[T]], object]r,   Noner,   str)rQ   
__module____qualname____firstlineno____doc__r   rC   __annotations__rE   rG   listrX   r]   __static_attributes__r!   r)   r'   r>   r>   b   s     "'E!2G2!&F(%(J(
 )-5959.L.L &.L 3	.L
 3.L 
.L`$r)   r>   c                h    [        XS5      nUc"  [        UUR                  5      n[        XU5        U$ )z
Get a L{Transitioner}
N)getattrr   initialStatesetattr)oselfsymbol	automatontransitioners       r'   _transitionerFromInstancers      s>     5$/L#""
 	|,r)   c                     g r5   r!   r!   r)   r'   _emptyru      s    r)   c                     g)	docstringNr!   r!   r)   r'   
_docstringrx      s    r)   c                    U R                   R                  [        R                   R                  [        R                   R                  4;  a  [	        S5      eg )Nzfunction body must be empty)__code__co_coderu   rx   
ValueError)r8   s    r'   assertNoCoder}      sC     	zz&//"9"9:;N;N;V;V!WW677 Xr)   c                   [        [        UR                  SS U 5      5      nUR                  (       a  U nO'U VVs/ s H  u  pgXcR                  ;   d  M  UPM     nnn[        U5      nU H  u  pXU
4-  nM     [        UR                  SSS2   UR                  SSS2   5      nU VVs0 s H  u  pgXh;  d  M  Xg_M     nnnUR                  U5        UR                  (       a  UnX]4$ UR                  SS UR                  -   nUR                  5        VVs0 s H  u  pgXn;   d  M  Xg_M     nnnX]4$ s  snnf s  snnf s  snnf )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]
r   N)	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      sM    s9>>!"-t45J &0HZTQ13GqZH V}!5M) "9>>$B$'););DbD)ABH$,JHDA0I414HKJv# %% (__QR0:3H3HH(..0
0TQA4KDAD0 	 
 %%) I K
s#   D4D4+D::D:E (E TRF)eqc                      \ rS rSr% Sr\" SS9rS\S'   \" 5       rS\S'   \" SS9r	S	\S
'   \" \
SS9rS\S'   \" SSS9rS\S'   SS jrSSS jjrSS jrSrg)r`      z&
An input for a L{MethodicalMachine}.
Fr@   =Automaton[MethodicalState, MethodicalInput, MethodicalOutput]rq   rD   rE   rc   rp   )default_factoryrA   z1dict[MethodicalState, Callable[[Iterable[T]], R]]
collectors)initrA   r   rM   c                b    [        U R                  5      U l        [        U R                  5        g r5   )r(   rE   rM   r}   r\   s    r'   __post_init__MethodicalInput.__post_init__  s    "4;;/T[[!r)   Nc                   ^ ^^ [        TT R                  T R                  5      m[        T R                  5      [        T R                  5      SUU U4S jj5       5       nU$ )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                 H  > TR                   " T/U Q70 UD6  TR                  nTR                  T5      u  p4TR                  U   n/ nU HN  nUb  U" U5        [	        XTR
                  UR
                  5      u  pU" T/UQ70 U	D6n
UR                  U
5        MP     U" U5      $ r5   )rE   _state
transitionr   r   rM   append)r   r   previousStaterT   	outTracerrU   valuesrJ   r.   kr   ro   r6   rr   s              r'   doInput(MethodicalInput.__get__.<locals>.doInput  s     KK///(//M#/#:#:4#@ W6IF!(f%"4v~~Nu.q.A.e$ " V$$r)   )r   objectr   r   r,   r   )rs   rp   rq   r   rE   r   )r6   ro   typer   rr   s   ``  @r'   __get__MethodicalInput.__get__  sS     1T^^T	dkk	"	t{{		% 	% 
 
#	% r)   c                .    U R                   R                  $ r5   r[   r\   s    r'   r]   MethodicalInput._name&  r_   r)   )rM   r,   ra   r5   )ro   r   r   ra   r,   r   rb   )rQ   rd   re   rf   rg   r   rq   rh   rE   rp   dictr   rM   r   r   r]   rj   r!   r)   r'   r`   r`      sy     PUPIL  "'F(U#FC#DI5EJA  %e4GW4"4$r)   r`   c                  x    \ rS rSr% Sr\" SS9rS\S'   S\S'   \" SSSS	9rS
\S'   SS jr	SS jr
S rSS jrSrg)MethodicalOutputi*  z'
An output for a L{MethodicalMachine}.
Fr@   rB   rC   rD   rE   )r   rA   comparer   rM   c                H    [        U R                  5      U R                  S'   g )NrM   )r(   rE   __dict__r\   s    r'   r   MethodicalOutput.__post_init__4  s    #.t{{#;i r)   Nc                p    [        SR                  UR                  U R                  R                  S95      e)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.)clsrE   )AttributeErrorrP   rQ   rE   r6   ro   r   s      r'   r   MethodicalOutput.__get__7  s<     DDJFMM$++*>*> EK E
 	
r)   c                .    U R                   " U/UQ70 UD6$ )z
Call the underlying method.
)rE   )r6   ro   r   r   s       r'   __call__MethodicalOutput.__call__B  s     {{5242622r)   c                .    U R                   R                  $ r5   r[   r\   s    r'   r]   MethodicalOutput._nameH  r_   r)   r!   r   r5   rb   )rQ   rd   re   rf   rg   r   rC   rh   rM   r   r   r   r]   rj   r!   r)   r'   r   r   *  sF     "'E!2G2%eUCGWC<	
3$r)   r   z4Callable[[str, str, str], StringOutputTracer | None]r   StringTracerc                0   ^  T c  g         SU 4S jjnU$ )Nc                   >^ T" U R                  5       UR                  5       UR                  5       5      mTb  U4S j$ g )Nc                0   > T" U R                  5       5      $ r5   r]   )outresults    r'   <lambda>,wrapTracer.<locals>.tracer.<locals>.<lambda>]  s    vciik2r)   r   )staterI   rJ   r   wrappeds      @r'   tracerwrapTracer.<locals>.tracerV  s4    
 v||~F22r)   )r   r>   rI   r`   rJ   r>   r,   z%OutputTracer[MethodicalOutput] | Noner!   )r   r   s   ` r'   
wrapTracerr   P  s=        
/	 Mr)   c                  \    \ rS rSr% \" SS9rS\S'   \" SS9rS\S'    S     SS	 jjrS
r	g)MethodicalTraceric  Fr@   r   rq   rc   rp   Nc                X   ^ [        XR                  U R                  5      mSU4S jjnU$ )Nc                :   > TR                  [        U 5      5        g r5   )setTracer   )r   rr   s    r'   r   *MethodicalTracer.__get__.<locals>.setTraceo  s    !!*V"45r)   )r   StringTracer | Noner,   ra   )rs   rp   rq   )r6   ro   r   r   rr   s       @r'   r   MethodicalTracer.__get__j  s%     1T^^T	6 r)   r!   r5   )ro   r   r   r   r,   zCallable[[StringTracer], None])
rQ   rd   re   rf   r   rq   rh   rp   r   rj   r!   r)   r'   r   r   c  sP    OTPIL  U#FC# -1#)	' r)   r   c                 8    S[        [        [        5      5      -   $ )z$
Create a unique Python identifier.
_symbol_)rc   nextcounterr!   r)   r'   gensymr   x  s     DM***r)   c                      \ rS rSrSrS rSS jr\ S     SS jj5       r\S 5       r	\S 5       r
S	 r\S
 5       r\S 5       r\SS j5       rS rSrg)rB   i  zY
A L{MethodicalMachine} is an interface to an L{Automaton} that uses methods
on a class.
c                N    [        5       U l        0 U l        [        5       U l        g r5   )r   
_automaton	_reducersr   _symbolr\   s    r'   __init__MethodicalMachine.__init__  s    #+xr)   Nc                "    Ub  [        S5      eU $ )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                   ^ ^^ UU U4S jnU$ )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                N   > [        TU TS9nT(       a  UTR                  l        U$ )N)rC   rE   rG   )r>   r   rm   )stateMethodr   initialr6   rG   s     r'   	decorator*MethodicalMachine.state.<locals>.decorator  s*    #[ZE /4,Lr)   r!   )r6   r   terminalrG   r   s   `` ` r'   r   MethodicalMachine.state  s    .	 r)   c                   ^  U 4S jnU$ )z5
Declare an input.

This is a decorator for methods.
c                B   > [        TR                  U TR                  S9$ )N)rq   rE   rp   )r`   r   r   )inputMethodr6   s    r'   r   *MethodicalMachine.input.<locals>.decorator  s    "//+dll r)   r!   r6   r   s   ` r'   rI   MethodicalMachine.input  s    	
 r)   c                   ^  U 4S jnU$ )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                   > [        TU S9$ )N)rC   rE   )r   )outputMethodr6   s    r'   r   +MethodicalMachine.output.<locals>.decorator  s    #DFFr)   r!   r   s   ` r'   rJ   MethodicalMachine.output  s    	G r)   c                l    U R                   R                  XU[        U5      5        XRR                  U'   g)z
See L{MethodicalState.upon}.
N)r   addTransitionr#   r   )r6   
startState
inputTokenendStateoutputTokensrU   s         r'   rR    MethodicalMachine._oneTransition  s2    $ 	%%HeL.A	
 -6j)r)   c                   ^  U 4S jnU$ ) c                4   >^  [        T 5      U U4S j5       nU$ )Nc                ~   > [        U TR                  TR                  5      nT" XR                  R                  5      $ r5   )rs   r   r   r   rG   )ro   rr   	decorateer6   s     r'   	serializeBMethodicalMachine.serializer.<locals>.decorator.<locals>.serialize  s5    84<<  !(;(;(F(FGGr)   r   )r  r  r6   s   ` r'   r   /MethodicalMachine.serializer.<locals>.decorator  s$    9H H r)   r!   r   s   ` r'   
serializerMethodicalMachine.serializer  s    	 r)   c                   ^  U 4S jnU$ )r   c                4   >^  [        T 5      U U4S j5       nU$ )Nc                   > T" U /UQ70 UD6n0 nTR                   R                  5        H  nXTUR                  '   M     [        U TR                  TR                   5      nXC   Ul        g r5   )r   statesrG   rs   r   r   )	ro   r   r   r   mapping	eachStaterr   r  r6   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  r6   s   ` r'   r   1MethodicalMachine.unserializer.<locals>.decorator  s"    9	 	 r)   r!   r   s   ` r'   unserializerMethodicalMachine.unserializer  s    	 r)   c                B    [        U R                  U R                  5      $ r5   )r   r   r   r\   s    r'   	_setTraceMethodicalMachine._setTrace  s    >>r)   c                :    SSK Jn  U" U R                  S S S S9$ )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/>}

r   )makeDigraphc                .    U R                   R                  $ r5   r[   )r   s    r'   r   -MethodicalMachine.asDigraph.<locals>.<lambda>"      (=(=r)   c                .    U R                   R                  $ r5   r[   )rI   s    r'   r   r  #  r  r)   c                .    U R                   R                  $ r5   r[   )rJ   s    r'   r   r  $  s    &--*@*@r)   )stateAsStringinputAsStringoutputAsString)
_visualizer  r   )r6   r  s     r'   	asDigraphMethodicalMachine.asDigraph  s$     	,OO==@	
 	
r)   )r   r   r   r5   )FFN)r   rF   r   rF   rG   r   )r,   r   )rQ   rd   re   rf   rg   r   r   r;   r   rI   rJ   rR   r  r  propertyr  r   rj   r!   r)   r'   rB   rB     s    
 
 TX/3IQ @    6.    ( ? ?
r)   rB   )ro   r   rp   rc   rq   r   r,   z@Transitioner[MethodicalState, MethodicalInput, MethodicalOutput])r8   rD   r,   ra   )r   r   r,   zATracer[MethodicalState, MethodicalInput, MethodicalOutput] | None)7
__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(   r2   r;   r   r>   rs   ru   rx   r}   r   r   r   r`   r   rc   StringOutputTracerr   rh   r   r   r   r   rB   r!   r)   r'   <module>r1     s   "  
 (  1  = =g+  @ @ (

 
 ..$ $:$f :$ :$z M F	$	8 &&R CLCL e/$f /$ /$d $$v $ $B seTk* Pi P F& ev  " '+f
 f
r)   