
    hM                        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J	r	J
r
  S SKJr  SSKJrJrJr  SS jr    SS	 jr " S
 S\5      r " S S\5      r " S S\5      rSS jr    SS jrg)    )annotationsN)AnyIterator)PythonAttributePythonModule	getModule)MethodicalMachine   )TypeMachineInputProtocolCorec                    [         R                  " U R                  5       5      nUc  gU n[        U[        5      (       d#  UR
                  n[        U[        5      (       d  M#  UR                  UR                  :H  $ )z
Attempt to discover if this appearance of a PythonAttribute
representing a class refers to the module where that class was
defined.
F)inspect	getmoduleload
isinstancer   onObjectname__name__)attrsourceModulecurrentModules      X/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/automat/_discover.pyisOriginalLocationr      sh     $$TYY[1LM55%.. 55 !6!666    c              #    #    [         R                  " U /5      n[        5       nU(       GaF  UR                  5       nUR	                  5       n[        U[        5      (       d  [        U[        5      (       a'  XB;  a"  UR                  U5        UR                  U4v   O[        R                  " U5      (       aF  [        U5      (       a6  XB;  a1  UR                  U5        UR                  UR                  5       5        Oi[        U[        5      (       aT  XB;  aO  UR                  U5        UR                  UR                  5       5        UR                  UR!                  5       5        U(       a  GME  gg7f)a  
Recursively yield L{MethodicalMachine}s and their FQPNs within a
L{PythonModule} or a L{twisted.python.modules.PythonAttribute}
wrapper object.

Note that L{PythonModule}s may refer to packages, as well.

The discovery heuristic considers L{MethodicalMachine} instances
that are module-level attributes or class-level attributes
accessible from module scope.  Machines inside nested classes will
be discovered, but those returned from functions or methods will not be.

@type within: L{PythonModule} or L{twisted.python.modules.PythonAttribute}
@param within: Where to start the search.

@return: a generator which yields FQPN, L{MethodicalMachine} pairs.
N)collectionsdequesetpopr   r   r	   r   addr   r   isclassr   
extendleftiterAttributesr   iterModules)withinqueuevisitedr   values        r   findMachinesViaWrapperr*      s    ( vh'E 	  yy{		u/00Juk4R4R"KK))U""OOE""'9$'?'?EDXKKT0023l++0DKKT0023T--/0! %s   E,E31E3c                      \ rS rSrSrSrg)InvalidFQPNO   z@
The given FQPN was not a dot-separated list of Python objects.
 Nr   
__module____qualname____firstlineno____doc____static_attributes__r.   r   r   r,   r,   O       r   r,   c                      \ rS rSrSrSrg)NoModuleU   z?
A prefix of the FQPN was not an importable module or package.
r.   Nr/   r.   r   r   r7   r7   U   r5   r   r7   c                      \ rS rSrSrSrg)NoObject[   z3
A suffix of the FQPN was not an accessible object
r.   Nr/   r.   r   r   r:   r:   [   r5   r   r:   c                  ^ U (       d  [        S5      e[        R                  " U R                  S5      5      nSU;   a  [        SU < 35      eUR	                  5       m [        T5      nU(       a/  UR	                  5       m UT   nUR                  5         U(       a  M/  U$ ! [         a    [        T5      ef = f! [         a    UR                  T5         Of = fUnU HZ  m [        U4S jUR                  5        5       5      nM)  ! [         a&    [        SR                  UR                  T5      5      ef = f   U$ )z
Given an FQPN, retrieve the object via the global Python module
namespace and wrap it with a L{PythonModule} or a
L{twisted.python.modules.PythonAttribute}.
zFQPN was empty. zMname must be a string giving a '.'-separated list of Python identifiers, not c              3  r   >#    U  H,  nUR                   R                  S S5      S   T:X  d  M(  Uv   M.     g7f)r=   r
   N)r   rsplit).0child	components     r   	<genexpr>wrapFQPN.<locals>.<genexpr>   s8      7E::$$S!,R0I= 7s   '7	7z{}.{})r,   r   r   splitpopleftr   KeyErrorr7   r   
appendleftnextr$   StopIterationr:   formatr   )fqpn
componentsmodule	attributerD   s       @r   wrapFQPNrR   a   sL    *++""4::c?3J	Z%),
 	

 ""$I"9%
 &&(		I&F
 KKM *   "y!!"  	!!),	 I		F &557 I
  	F7>>)..)DEE	F   s*   B" B; "B8;CC$#D		0D9c                *    [        [        U 5      5      $ )a  
Recursively yield L{MethodicalMachine}s and their FQPNs in and under the a
Python object specified by an FQPN.

The discovery heuristic considers L{MethodicalMachine} instances that are
module-level attributes or class-level attributes accessible from module
scope.  Machines inside nested classes will be discovered, but those
returned from functions or methods will not be.

@param fqpn: a fully-qualified Python identifier (i.e. the dotted
    identifier of an object defined at module or class scope, including the
    package and modele names); where to start the search.

@return: a generator which yields (C{FQPN}, L{MethodicalMachine}) pairs.
)r*   rR   )rN   s    r   findMachinesrT      s    $ "(4.11r   )r   zPythonAttribute | PythonModulereturnbool)r&   PythonModule | PythonAttributerU   JIterator[tuple[str, MethodicalMachine | TypeMachine[InputProtocol, Core]]])rN   strrU   rW   )rN   rY   rU   rX   )
__future__r   r   r   typingr   r   twisted.python.modulesr   r   r   automatr	   _typedr   r   r   r   r*   	Exceptionr,   r7   r:   rR   rT   r.   r   r   <module>r`      sz    "     K K % 4 47"-1*-1O-1`) { { 2j2
2O2r   