o
    >hM                     @  s   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dZd ddZG dd deZG dd deZG dd deZd!ddZd"ddZdS )#    )annotationsN)AnyIterator)PythonAttributePythonModule	getModule)MethodicalMachine   )TypeMachineInputProtocolCoreattrPythonAttribute | PythonModulereturnboolc                 C  sD   t |  }|du rdS | }t|ts|j}t|tr|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currentModule r   q/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/automat/_discover.pyisOriginalLocation   s   

r   withinPythonModule | PythonAttributeJIterator[tuple[str, MethodicalMachine | TypeMachine[InputProtocol, Core]]]c                 c  s    t | g}t }|rh| }| }t|tst|tr.||vr.|| |j	|fV  n6t
|rHt|rH||vrH|| ||  nt|trd||vrd|| ||  ||  |sd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   valuer   r   r   findMachinesViaWrapper   s4   


r,   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.   O       r.   c                   @  r-   )NoModulezG
    A prefix of the FQPN was not an importable module or package.
    Nr/   r   r   r   r   r4   U   r3   r4   c                   @  r-   )NoObjectz;
    A suffix of the FQPN was not an accessible object
    Nr/   r   r   r   r   r5   [   r3   r5   fqpnstrc              	     s   | st dt| d}d|v rt d| f |  zt }W n ty.   t w |rP|  z|  }W n tyI   |  Y n	w |	  |s1|S |}|D ]! zt
 fdd| D }W qV tyw   td|j 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. zOname must be a string giving a '.'-separated list of Python identifiers, not %rc                 3  s*    | ]}|j d dd  kr|V  qdS )r8   r	   N)r   rsplit).0child	componentr   r   	<genexpr>   s    zwrapFQPN.<locals>.<genexpr>z{}.{})r.   r    r!   splitpopleftr   KeyErrorr4   
appendleftr   nextr'   StopIterationr5   formatr   )r6   
componentsmodule	attributer   r>   r   wrapFQPNa   sH   

rK   c                 C  s   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,   rK   )r6   r   r   r   findMachines   s   rL   )r   r   r   r   )r   r   r   r   )r6   r7   r   r   )r6   r7   r   r   )
__future__r   r    r   typingr   r   twisted.python.modulesr   r   r   automatr   _typedr
   r   r   r   r,   	Exceptionr.   r4   r5   rK   rL   r   r   r   r   <module>   s    

0
5