
    tf                         d dl Z d dlZd dlmZ d dlmZmZ d Zd Z G d de	          Z
 G d d	e
          Z G d
 de
          Zd Zd ZdS )    N)MethodicalMachine)PythonModule	getModulec                     t          j        |                                           }|dS | }t          |t                    s|j        }t          |t                    |j        |j        k    S )z
    Attempt to discover if this appearance of a PythonAttribute
    representing a class refers to the module where that class was
    defined.
    NF)inspect	getmoduleload
isinstancer   onObjectname__name__)attrsourceModulecurrentModules      P/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/automat/_discover.pyisOriginalLocationr      sm     $TYY[[11LuM55 /%. 55 / !666    c              #     K   t          j        | g          }t                      }|rG|                                }|                                }t          |t                    r%||vr!|                    |           |j        |fV  nt          j
        |          rPt          |          rA||vr=|                    |           |                    |                                           n|t          |t                    rg||vrc|                    |           |                    |                                           |                    |                                           |EdS dS )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   addr   r   isclassr   
extendleftiterAttributesr   iterModules)withinqueuevisitedr   values        r   findMachinesViaWrapperr"      sx     $ vh''EeeG
 1yy{{		e.// 
	1E4H4HKK)U"""""oe$$ 	1);D)A)A 	17""KKT00223333l++ 	1W0D0DKKT0022333T--//000  1 1 1 1 1r   c                       e Zd ZdZdS )InvalidFQPNzH
    The given FQPN was not a dot-separated list of Python objects.
    Nr   
__module____qualname____doc__ r   r   r$   r$   >              r   r$   c                       e Zd ZdZdS )NoModulezG
    A prefix of the FQPN was not an importable module or package.
    Nr%   r)   r   r   r,   r,   D   r*   r   r,   c                       e Zd ZdZdS )NoObjectz;
    A suffix of the FQPN was not an accessible object
    Nr%   r)   r   r   r.   r.   J   r*   r   r.   c                    | st          d          t          j        |                     d                    }d|v rt          d|           |                                	 t                    }n# t          $ r t                    w xY w|rY|                                	 |         }|                                 n%# t          $ r |	                               Y nw xY w|Y|S |}|D ]f	 t          fd|                                D                       }1# t          $ r) t          d                    |j                            w xY w|S )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   f   K   | ]+}|j                             d d          d         k    '|V  ,dS )r0      N)r   rsplit).0child	components     r   	<genexpr>zwrapFQPN.<locals>.<genexpr>y   sT       L Lu %
 1 1#q 9 9" = J J # J J J JL Lr   z{}.{})r$   r   r   splitpopleftr   KeyErrorr,   r	   
appendleftnextr   StopIterationr.   formatr   )fqpn
componentsmodule	attributer8   s       @r   wrapFQPNrE   P   s     ,*+++"4::c??33J	Zk%)T,- - 	- ""$$I"9%% " " "y!!!"  
&&((		I&F
 KKMMMM	  	 	 	!!),,,E		  
  I F F		F L L L L	0H0H0J0J L L L L LII 	F 	F 	F7>>).)DDEEE	F s*   %A5 5B)C C('C(6-D$$3Ec                 :    t          t          |                     S )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.

    @type within: an FQPN
    @param within: Where to start the search.

    @return: a generator which yields FQPN, L{MethodicalMachine} pairs.
    )r"   rE   )rA   s    r   findMachinesrG      s     "(4..111r   )r   r   automatr   twisted.python.modulesr   r   r   r"   	Exceptionr$   r,   r.   rE   rG   r)   r   r   <module>rK      s
        % % % % % % : : : : : : : :7 7 7"#1 #1 #1L    )       {       {   . . .b2 2 2 2 2r   