
    dhM                        d dl mZ d dlZd dlZd dlmZmZ d dlmZm	Z	m
Z
 d dlmZ ddlmZmZmZ ddZddZ G d de          Z G d de          Z G d de          ZddZddZdS )    )annotationsN)AnyIterator)PythonAttributePythonModule	getModule)MethodicalMachine   )TypeMachineInputProtocolCoreattrPythonAttribute | PythonModulereturnboolc                    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__)r   sourceModulecurrentModules      a/home/jenkins/workspace/simtester-sanitize/venv/lib/python3.11/site-packages/automat/_discover.pyisOriginalLocationr      sm     $TYY[[11LuM55 /%. 55 / !666    withinPythonModule | PythonAttributeJIterator[tuple[str, MethodicalMachine | TypeMachine[InputProtocol, Core]]]c              #    K   t          j        | g          }t                      }|r\|                                }|                                }t          |t                    st          |t                    r%||vr!|                    |           |j	        |fV  nt          j        |          rPt          |          rA||vr=|                    |           |                    |                                           n|t          |t                    rg||vrc|                    |           |                    |                                           |                    |                                           |Zd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	   r   addr   r   isclassr   
extendleftiterAttributesr   iterModules)r   queuevisitedr   values        r   findMachinesViaWrapperr/      s     ( vh''E 	   1yy{{		u/00	14>uk4R4R	17""KK)U"""""OE""	1'9$'?'?	1DIQXDXDX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   r1   r1   O              r   r1   c                      e Zd ZdZdS )NoModulezG
    A prefix of the FQPN was not an importable module or package.
    Nr2   r6   r   r   r9   r9   U   r7   r   r9   c                      e Zd ZdZdS )NoObjectz;
    A suffix of the FQPN was not an accessible object
    Nr2   r6   r   r   r;   r;   [   r7   r   r;   fqpnstrc                   | 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 )r?   r
   N)r   rsplit).0child	components     r   	<genexpr>zwrapFQPN.<locals>.<genexpr>   sQ        :$$S!,,R0I== ==== r   z{}.{})r1   r#   r$   splitpopleftr   KeyErrorr9   r   
appendleftnextr*   StopIterationr;   formatr   )r<   
componentsmodule	attributerF   s       @r   wrapFQPNrR   a   s     ,*+++"4::c??33J	Zk%)T,
 
 	

 ""$$I"9%% " " "y!!!"  
&&((		I&F
 KKMMMM	  	 	 	!!),,,E		  
  I F F		F    &5577    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.

    @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   )r<   s    r   findMachinesrT      s    $ "(4..111r   )r   r   r   r   )r   r    r   r!   )r<   r=   r   r    )r<   r=   r   r!   )
__future__r   r#   r   typingr   r   twisted.python.modulesr   r   r   automatr	   _typedr   r   r   r   r/   	Exceptionr1   r9   r;   rR   rT   r6   r   r   <module>r[      sl   " " " " " "                      K K K K K K K K K K % % % % % % 4 4 4 4 4 4 4 4 4 47 7 7 7"-1 -1 -1 -1`    )       {       {   2 2 2 2j2 2 2 2 2 2r   