
    !hi             	          d Z ddlZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
 ddlZddlZddlZddlZej"                  dk\  rddlmZ nddlZ	  e       Zej.                  j1                  de      Z ej4                         xej.                  d<   Zd e_        ddlmZ ddlm Z  eeureej.                  d<   nej.                  d= 	 d	d
l!m"Z"  G d d      Z# G d d      Z$dZ%	 dZ&	 e&Z'	  G d de(      Z)d Z* G d d e	dg d            Z+ G d d      Z, G d de-      Z. G d de,      Z/ G d de,      Z0 G d de0      Z1 G d  d!e0      Z2 G d" d#e0      Z3 G d$ d%e,      Z4 G d& d'e,      Z5 G d( d)e5      Z6 G d* d+e5      Z7 G d, d-e7      Z8 G d. d/e5      Z9 G d0 d1e5      Z: G d2 d3e5      Z; G d4 d5e5      Z< G d6 d7e;e<      Z= G d8 d9e<      Z> G d: d;e5      Z? G d< d=e<      Z@ G d> d?e5      ZA G d@ dAe5      ZBdBaCdCaDdDaEdEaFdFaGdGaHdH ZIdI ZJdZ' G dJ dKej                        ZL G dL dMe      ZMy# eeureej.                  d<   w ej.                  d= w xY w)Na  
Find modules used by a script, using bytecode analysis.

Based on the stdlib modulefinder by Thomas Heller and Just van Rossum,
but uses a graph data structure and 2.3 features

XXX: Verify all calls to _import_hook (and variants) to ensure that
imports are done in the right way.
    N)deque
namedtupledefaultdict)   
   pkg_resourcesc                 .    t        j                  |       gS N)importlib_metadatadistribution)names    SC:\des-py\Monitor\venv\Lib\site-packages\PyInstaller/lib/modulegraph/modulegraph.py<lambda>r   ,   s    /A/N/Nt/T.U     )ObjectGraph)
GraphError   )utilc                       e Zd Zd Zy)BUILTIN_MODULEc                      yNF )fqnames    r   
is_packagezBUILTIN_MODULE.is_package:   s    r   N)__name__
__module____qualname__r   r   r   r   r   r   9   s    r   r   c                       e Zd Zd Zd Zy)NAMESPACE_PACKAGEc                     || _         y r
   )namespace_dirs)selfr"   s     r   __init__zNAMESPACE_PACKAGE.__init__?   s
    ,r   c                      yNTr   )r#   r   s     r   r   zNAMESPACE_PACKAGE.is_packageB   s    r   N)r   r   r   r$   r   r   r   r   r    r    >   s    -r   r    c                       e Zd Zy)InvalidRelativeImportErrorNr   r   r   r   r   r   r)   r)   c       r   r)   c                 j    t        j                  dt        |             }||j                  d      S |S )Nz^No module named (\S+)$r   )rematchstrgroup)excdefaultms      r   _path_from_importerrorr4   g   s1     	+SX6A}wwqzNr   c                       e Zd ZdZd Zy)DependencyInfor   c                    | j                   s| j                  s| j                  r$|j                   s?|j                  s3|j                  s't        ddd| j                  xr |j                        S t        | j                   xs |j                   | j                  xs |j                  | j                  xs |j                  | j                  xr |j                        S )NFconditionalfunction	tryexceptfromlist)r9   r:   r;   r6   r<   )r#   others     r   _mergedzDependencyInfo._mergedy   s      t~~$$U^^EOO!!95>>	; ; " $ 0 0 EE4E4E!]]<enn"nn?!]]=u~~	? ?r   N)r   r   r   	__slots__r>   r   r   r   r6   r6   u   s    I?r   r6   r8   c                       e Zd ZdZg dZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zy)Nodea  
    Abstract base class (ABC) of all objects added to a `ModuleGraph`.

    Attributes
    ----------
    code : codeobject
        Code object of the pure-Python module corresponding to this graph node
        if any _or_ `None` otherwise.
    graphident : str
        Synonym of `identifier` required by the `ObjectGraph` superclass of the
        `ModuleGraph` class. For readability, the `identifier` attribute should
        typically be used instead.
    filename : str
        Absolute path of this graph node's corresponding module, package, or C
        extension if any _or_ `None` otherwise.
    identifier : str
        Fully-qualified name of this graph node's corresponding module,
        package, or C extension.
    packagepath : str
        List of the absolute paths of all directories comprising this graph
        node's corresponding package. If this is a:
        * Non-namespace package, this list contains exactly one path.
        * Namespace package, this list contains one or more paths.
    _deferred_imports : list
        List of all target modules imported by the source module corresponding
        to this graph node whole importations have been deferred for subsequent
        processing in between calls to the `_ModuleGraph._scan_code()` and
        `_ModuleGraph._process_imports()` methods for this source module _or_
        `None` otherwise. Each element of this list is a 3-tuple
        `(have_star, _safe_import_hook_args, _safe_import_hook_kwargs)`
        collecting the importation of a target module from this source module
        for subsequent processing, where:
        * `have_star` is a boolean `True` only if this is a `from`-style star
          import (e.g., resembling `from {target_module_name} import *`).
        * `_safe_import_hook_args` is a (typically non-empty) sequence of all
          positional arguments to be passed to the `_safe_import_hook()` method
          to add this importation to the graph.
        * `_safe_import_hook_kwargs` is a (typically empty) dictionary of all
          keyword arguments to be passed to the `_safe_import_hook()` method
          to add this importation to the graph.
        Unlike functional languages, Python imposes a maximum depth on the
        interpreter stack (and hence recursion). On breaching this depth,
        Python raises a fatal `RuntimeError` exception. Since `ModuleGraph`
        parses imports recursively rather than iteratively, this depth _was_
        commonly breached before the introduction of this list. Python
        environments installing a large number of modules (e.g., Anaconda) were
        particularly susceptible. Why? Because `ModuleGraph` concurrently
        descended through both the abstract syntax trees (ASTs) of all source
        modules being parsed _and_ the graph of all target modules imported by
        these source modules being built. The stack thus consisted of
        alternating layers of AST and graph traversal. To unwind such
        alternation and effectively halve the stack depth, `ModuleGraph` now
        descends through the abstract syntax tree (AST) of each source module
        being parsed and adds all importations originating within this module
        to this list _before_ descending into the graph of these importations.
        See pyinstaller/pyinstaller/#1289 for further details.
    _global_attr_names : set
        Set of the unqualified names of all global attributes (e.g., classes,
        variables) defined in the pure-Python module corresponding to this
        graph node if any _or_ the empty set otherwise. This includes the names
        of all attributes imported via `from`-style star imports from other
        existing modules (e.g., `from {target_module_name} import *`). This
        set is principally used to differentiate the non-ignorable importation
        of non-existent submodules in a package from the ignorable importation
        of existing global attributes defined in that package's pure-Python
        `__init__` submodule in `from`-style imports (e.g., `bar` in
        `from foo import bar`, which may be either a submodule or attribute of
        `foo`), as such imports ambiguously allow both. This set is _not_ used
        to differentiate submodules from attributes in `import`-style imports
        (e.g., `bar` in `import foo.bar`, which _must_ be a submodule of
        `foo`), as such imports unambiguously allow only submodules.
    _starimported_ignored_module_names : set
        Set of the fully-qualified names of all existing unparsable modules
        that the existing parsable module corresponding to this graph node
        attempted to perform one or more "star imports" from. If this module
        either does _not_ exist or does but is unparsable, this is the empty
        set. Equivalently, this set contains each fully-qualified name
        `{trg_module_name}` for which:
        * This module contains an import statement of the form
          `from {trg_module_name} import *`.
        * The module whose name is `{trg_module_name}` exists but is _not_
          parsable by `ModuleGraph` (e.g., due to _not_ being pure-Python).
        **This set is currently defined but otherwise ignored.**
    _submodule_basename_to_node : dict
        Dictionary mapping from the unqualified name of each submodule
        contained by the parent module corresponding to this graph node to that
        submodule's graph node. If this dictionary is non-empty, this parent
        module is typically but _not_ always a package (e.g., the non-package
        `os` module containing the `os.path` submodule).
    )	codefilename
graphident
identifierpackagepath_deferred_imports_global_attr_names"_starimported_ignored_module_names_submodule_basename_to_nodec                     d| _         d| _        || _        || _        d| _        d| _        t               | _        t               | _        t               | _
        y)z
        Initialize this graph node.

        Parameters
        ----------
        identifier : str
            Fully-qualified name of this graph node's corresponding module,
            package, or C extension.
        N)rB   rC   rD   rE   rF   rG   setrH   rI   dictrJ   )r#   rE   s     r   r$   zNode.__init__   sN     	$$!%"%%25%/+/6(r   c                     || j                   v S )a  
        `True` only if the pure-Python module corresponding to this graph node
        defines a global attribute (e.g., class, variable) with the passed
        name.

        If this module is actually a package, this method instead returns
        `True` only if this package's pure-Python `__init__` submodule defines
        such a global attribute. In this case, note that this package may still
        contain an importable submodule of the same name. Callers should
        attempt to import this attribute as a submodule of this package
        _before_ assuming this attribute to be an ignorable global. See
        "Examples" below for further details.

        Parameters
        ----------
        attr_name : str
            Unqualified name of the attribute to be tested.

        Returns
        ----------
        bool
            `True` only if this module defines this global attribute.

        Examples
        ----------
        Consider a hypothetical module `foo` containing submodules `bar` and
        `__init__` where the latter assigns `bar` to be a global variable
        (possibly star-exported via the special `__all__` global variable):

        >>> # In "foo.__init__":
        >>> bar = 3.1415

        Python 2 and 3 both permissively permit this. This method returns
        `True` in this case (i.e., when called on the `foo` package's graph
        node, passed the attribute name `bar`) despite the importability of the
        `foo.bar` submodule.
        )rH   r#   	attr_names     r   is_global_attrzNode.is_global_attr  s    N D3333r   c                     || j                   v S )a#  
        `True` only if the parent module corresponding to this graph node
        contains the submodule with the passed name.

        If `True`, this parent module is typically but _not_ always a package
        (e.g., the non-package `os` module containing the `os.path` submodule).

        Parameters
        ----------
        submodule_basename : str
            Unqualified name of the submodule to be tested.

        Returns
        ----------
        bool
            `True` only if this parent module contains this submodule.
        rJ   r#   submodule_basenames     r   is_submodulezNode.is_submodule<  s    & "T%E%EEEr   c                 :    | j                   j                  |       y)a  
        Record the global attribute (e.g., class, variable) with the passed
        name to be defined by the pure-Python module corresponding to this
        graph node.

        If this module is actually a package, this method instead records this
        attribute to be defined by this package's pure-Python `__init__`
        submodule.

        Parameters
        ----------
        attr_name : str
            Unqualified name of the attribute to be added.
        N)rH   addrO   s     r   add_global_attrzNode.add_global_attrR  s      	##I.r   c                 N    | j                   j                  |j                          y)a&  
        Record all global attributes (e.g., classes, variables) defined by the
        target module corresponding to the passed graph node to also be defined
        by the source module corresponding to this graph node.

        If the source module is actually a package, this method instead records
        these attributes to be defined by this package's pure-Python `__init__`
        submodule.

        Parameters
        ----------
        target_module : Node
            Graph node of the target module to import attributes from.
        N)rH   update)r#   target_modules     r   add_global_attrs_from_modulez!Node.add_global_attrs_from_modulee  s      	&&}'G'GHr   c                 "    || j                   |<   y)a
  
        Add the submodule with the passed name and previously imported graph
        node to the parent module corresponding to this graph node.

        This parent module is typically but _not_ always a package (e.g., the
        non-package `os` module containing the `os.path` submodule).

        Parameters
        ----------
        submodule_basename : str
            Unqualified name of the submodule to add to this parent module.
        submodule_node : Node
            Graph node of this submodule.
        NrS   )r#   rU   submodule_nodes      r   add_submodulezNode.add_submodulex  s      @N(();<r   c                      | j                   |   S )aW  
        Graph node of the submodule with the passed name in the parent module
        corresponding to this graph node.

        If this parent module does _not_ contain this submodule, an exception
        is raised. Else, this parent module is typically but _not_ always a
        package (e.g., the non-package `os` module containing the `os.path`
        submodule).

        Parameters
        ----------
        module_basename : str
            Unqualified name of the submodule to retrieve.

        Returns
        ----------
        Node
            Graph node of this submodule.
        rS   rT   s     r   get_submodulezNode.get_submodule  s    * //0BCCr   c                 8    | j                   j                  |      S )a  
        Graph node of the submodule with the passed unqualified name in the
        parent module corresponding to this graph node if this module contains
        this submodule _or_ `None`.

        This parent module is typically but _not_ always a package (e.g., the
        non-package `os` module containing the `os.path` submodule).

        Parameters
        ----------
        submodule_basename : str
            Unqualified name of the submodule to retrieve.

        Returns
        ----------
        Node
            Graph node of this submodule if this parent module contains this
            submodule _or_ `None`.
        )rJ   getrT   s     r   get_submodule_or_nonezNode.get_submodule_or_none  s    * //334FGGr   c                 ^    | j                  |      r| j                  j                  |       yy)a  
        Record the global attribute (e.g., class, variable) with the passed
        name if previously recorded as defined by the pure-Python module
        corresponding to this graph node to be subsequently undefined by the
        same module.

        If this module is actually a package, this method instead records this
        attribute to be undefined by this package's pure-Python `__init__`
        submodule.

        This method is intended to be called on globals previously defined by
        this module that are subsequently undefined via the `del` built-in by
        this module, thus "forgetting" or "undoing" these globals.

        For safety, there exists no corresponding `remove_global_attr()`
        method. While defining this method is trivial, doing so would invite
        `KeyError` exceptions on scanning valid Python that lexically deletes a
        global in a scope under this module's top level (e.g., in a function)
        _before_ defining this global at this top level. Since `ModuleGraph`
        cannot and should not (re)implement a full-blown Python interpreter,
        ignoring out-of-order deletions is the only sane policy.

        Parameters
        ----------
        attr_name : str
            Unqualified name of the attribute to be removed.
        N)rQ   rH   removerO   s     r   remove_global_attr_if_foundz Node.remove_global_attr_if_found  s+    : y)##**95 *r   c                 X    	 t        |d      }| j                  |k(  S # t        $ r Y yw xY w)NrD   FgetattrAttributeErrorrD   r#   r=   
otherIdents      r   __eq__zNode.__eq__  s8    	 5J *,,  		    	))c                 X    	 t        |d      }| j                  |k7  S # t        $ r Y yw xY w)NrD   Trj   rm   s      r   __ne__zNode.__ne__  s8    	 5J *,,  		rp   c                 d    	 t        |d      }| j                  |k  S # t        $ r	 t        cY S w xY wNrD   rk   rl   NotImplementedrD   rm   s      r   __lt__zNode.__lt__  ;    	" 5J ++  	"!!	"    //c                 d    	 t        |d      }| j                  |k  S # t        $ r	 t        cY S w xY wrt   ru   rm   s      r   __le__zNode.__le__  ;    	" 5J *,,  	"!!	"ry   c                 d    	 t        |d      }| j                  |kD  S # t        $ r	 t        cY S w xY wrt   ru   rm   s      r   __gt__zNode.__gt__  rx   ry   c                 d    	 t        |d      }| j                  |k\  S # t        $ r	 t        cY S w xY wrt   ru   rm   s      r   __ge__zNode.__ge__  r|   ry   c                 ,    t        | j                        S r
   )hashrD   r#   s    r   __hash__zNode.__hash__  s    DOO$$r   c                     | j                   fS r
   )rE   r   s    r   	infoTuplezNode.infoTuple  s    !!r   c                 P    t        |       j                  | j                         S r
   )typer   r   r   s    r   __repr__zNode.__repr__  s    d,,dnn.>??r   N)r   r   r   __doc__r?   r$   rQ   rV   rY   r]   r`   rb   re   rh   ro   rr   rw   r{   r~   r   r   r   r   r   r   r   rA   rA      sr    Yv
I2,'4TF,/&I&N&D0H06@--,-,-%"@r   rA   c                       e Zd ZdZy)Aliasa  
    Placeholder aliasing an existing source module to a non-existent target
    module (i.e., the desired alias).

    For obscure reasons, this class subclasses `str`. Each instance of this
    class is the fully-qualified name of the existing source module being
    aliased. Unlike the related `AliasNode` class, instances of this class are
    _not_ actual nodes and hence _not_ added to the graph; they only facilitate
    communication between the `ModuleGraph.alias_module()` and
    `ModuleGraph.find_node()` methods.
    Nr   r   r   r   r   r   r   r   r     s    
r   r   c                   0     e Zd ZdZd fd	Zd Zd Z xZS )	AliasNodez
    Graph node representing the aliasing of an existing source module under a
    non-existent target module name (i.e., the desired alias).
    c                 N    t         t        |   |       | j                  |       y)a  
        Initialize this alias.

        Parameters
        ----------
        name : str
            Fully-qualified name of the non-existent target module to be
            created (as an alias of the existing source module).
        node : Node
            Graph node of the existing source module being aliased. Optional;
            if not provided here, the attributes from referred node should
            be copied later using `copyAttributesFromReferredNode` method.
        N)superr   r$   copyAttributesFromReferredNode)r#   r   node	__class__s      r   r$   zAliasNode.__init__)  s$     	i'- 	++D1r   c           	      Z    dD ]&  }t        ||      st        | |t        ||             ( y)zh
        Copy a subset of attributes from referred node (source module) into this target alias.
        )rE   rF   rH   rI   rJ   N)hasattrsetattrrk   )r#   r   rP   s      r   r   z(AliasNode.copyAttributesFromReferredNode<  s4    + 	CI tY'iy)AB	Cr   c                 2    | j                   | j                  fS r
   )rD   rE   r   s    r   r   zAliasNode.infoTupleJ  s    11r   r
   )r   r   r   r   r$   r   r   __classcell__r   s   @r   r   r   #  s    
2&C2r   r   c                       e Zd Zy)	BadModuleNr*   r   r   r   r   r   N  r+   r   r   c                       e Zd Zy)ExcludedModuleNr*   r   r   r   r   r   R  r+   r   r   c                       e Zd Zy)MissingModuleNr*   r   r   r   r   r   V  r+   r   r   c                   $     e Zd Z fdZd Z xZS )InvalidRelativeImportc                     |}|j                  d      r||z  }n|d|z   z  }t        t        |   |       || _        || _        y )N.)endswithr   r   r$   relative_path	from_name)r#   r   r   rE   r   s       r   r$   zInvalidRelativeImport.__init__[  sM    "
!!#&)#J#	/)J#T3J?*"r   c                 2    | j                   | j                  fS r
   )r   r   r   s    r   r   zInvalidRelativeImport.infoTuplee  s    ""DNN33r   r   r   r   r$   r   r   r   s   @r   r   r   Z  s    #4r   r   c                   $     e Zd Z fdZd Z xZS )Scriptc                 :    t         t        |   |       || _        y r
   )r   r   r$   rC   )r#   rC   r   s     r   r$   zScript.__init__j  s    fd$X. r   c                     | j                   fS r
   )rC   r   s    r   r   zScript.infoTuplen  s    r   r   r   s   @r   r   r   i  s    ! r   r   c                   &     e Zd Zd fd	Zd Z xZS )
BaseModulec                 H    t         t        |   |       || _        || _        y r
   )r   r   r$   rC   rF   )r#   r   rC   pathr   s       r   r$   zBaseModule.__init__s  s!    j$(. r   c                 n    t        t        d | j                  | j                  | j                  f            S r
   )tuplefilterrE   rC   rF   r   s    r   r   zBaseModule.infoTuplex  s)    VD4??DMM4CSCS"TUVVr   )NNr   r   s   @r   r   r   r  s     
Wr   r   c                       e Zd Zy)BuiltinModuleNr*   r   r   r   r   r   |  r+   r   r   c                       e Zd Zy)SourceModuleNr*   r   r   r   r   r     r+   r   r   c                       e Zd Zy)InvalidSourceModuleNr*   r   r   r   r   r     r+   r   r   c                       e Zd Zy)CompiledModuleNr*   r   r   r   r   r     r+   r   r   c                       e Zd Zy)InvalidCompiledModuleNr*   r   r   r   r   r     r+   r   r   c                       e Zd Zy)	ExtensionNr*   r   r   r   r   r     r+   r   r   c                       e Zd ZdZy)Packagez:
    Graph node representing a non-namespace package.
    Nr   r   r   r   r   r          	r   r   c                       e Zd ZdZy)ExtensionPackageza
    Graph node representing a package where the __init__ module is an extension
    module.
    Nr   r   r   r   r   r     s     	r   r   c                       e Zd ZdZy)NamespacePackagez6
    Graph node representing a namespace package.
    Nr   r   r   r   r   r     r   r   r   c                       e Zd ZdZy)RuntimeModulea<  
    Graph node representing a non-package Python module dynamically defined at
    runtime.

    Most modules are statically defined on-disk as standard Python files.
    Some modules, however, are dynamically defined in-memory at runtime
    (e.g., `gi.repository.Gst`, dynamically defined by the statically
    defined `gi.repository.__init__` module).

    This node represents such a runtime module. Since this is _not_ a package,
    all attempts to import submodules from this module in `from`-style import
    statements (e.g., the `queue` submodule in `from six.moves import queue`)
    will be silently ignored.

    To ensure that the parent package of this module if any is also imported
    and added to the graph, this node is typically added to the graph by
    calling the `ModuleGraph.add_module()` method.
    Nr   r   r   r   r   r         $ 	r   r   c                       e Zd ZdZy)RuntimePackageaQ  
    Graph node representing a non-namespace Python package dynamically defined
    at runtime.

    Most packages are statically defined on-disk as standard subdirectories
    containing `__init__.py` files. Some packages, however, are dynamically
    defined in-memory at runtime (e.g., `six.moves`, dynamically defined by
    the statically defined `six` module).

    This node represents such a runtime package. All attributes imported from
    this package in `from`-style import statements that are submodules of this
    package (e.g., the `queue` submodule in `from six.moves import queue`) will
    be imported rather than ignored.

    To ensure that the parent package of this package if any is also imported
    and added to the graph, this node is typically added to the graph by
    calling the `ModuleGraph.add_module()` method.
    Nr   r   r   r   r   r     r   r   r   c                        e Zd Z fdZ xZS )FlatPackagec                 `    t        j                  dt               t        t        g|i | y Nz=This class will be removed in a future version of modulegraphwarningswarnDeprecationWarningr   r   r#   argskwdsr   s      r   r$   zFlatPackage.__init__  )    K	  	k)D)D)r   r   r   r   r$   r   r   s   @r   r   r         * *r   r   c                        e Zd Z fdZ xZS )ArchiveModulec                 `    t        j                  dt               t        t        g|i | y r   r   r   s      r   r$   zArchiveModule.__init__  r   r   r   r   s   @r   r   r     r   r   r   a  <!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>%(TITLE)s</title>
    <style>
      .node { padding: 0.5em 0 0.5em; border-top: thin grey dotted; }
      .moduletype { font: smaller italic }
      .node a { text-decoration: none; color: #006699; }
      .node a:visited { text-decoration: none; color: #2f0099; }
    </style>
  </head>
  <body>
    <h1>%(TITLE)s</h1>zB
<div class="node">
  <a name="%(NAME)s"></a>
  %(CONTENT)s
</div>z:<tt>%(NAME)s</tt> <span class="moduletype">%(TYPE)s</span>zp<a target="code" href="%(URL)s" type="text/plain"><tt>%(NAME)s</tt></a>
<span class="moduletype">%(TYPE)s</span>z6  <div class="import">
%(HEAD)s:
  %(LINKS)s
  </div>
z
  </body>
</html>c                     g }| D ]I  }t        |t        j                        r|j                  |j                         9|j                  |       K |D cg c]
  }|dk7  s	| }}|S c c}w )N__main__)
isinstanceastaliasappendr   )namesresultnmrs       r   
_ast_namesr     se    F b#))$MM"''"MM"	  3A1
?a3F3M 4s   
A( A(c                 t    t               }|j                  }| D cg c]  }||v r ||      r| c}S c c}w )z/Remove duplicates from a list, preserving order)rL   rX   )seqseenseen_addxs       r   uniqr     s4     5DxxH=!19A===s   	555c                       e Zd Zd Zed        Zed        Zed        Zd Zd Z	d Z
d Zd	 ZeZd
 Zd Zd ZeZeZeZeZeZeZeZeZeZeZeZeZeZeZeZeZeZy)_Visitorc                 f    || _         || _        t        | _        dg| _        dg| _        dg| _        y r   )_graph_moduleDEFAULT_IMPORT_LEVEL_level_in_if_in_def_in_tryexcept)r#   graphmodules      r   r$   z_Visitor.__init__&  s3    *gw#Wr   c                      | j                   d   S Nr'   )r   r   s    r   in_ifz_Visitor.in_if.  s    {{2r   c                      | j                   d   S r   )r   r   s    r   in_defz_Visitor.in_def2  s    ||Br   c                      | j                   d   S r   )r   r   s    r   in_tryexceptz_Visitor.in_tryexcept6  s    !!"%%r   c                    d}|"t        |      }d|v r|j                  d       d}| j                  j                  j	                  ||| j                  ||fdt        | j                  | j                  | j                  d      if       y )NF*T	edge_attr)r9   r;   r:   r<   )	r   rg   r   rG   r   r6   r   r  r   )r#   r   r<   level	have_stars        r   _collect_importz_Visitor._collect_import;  s    	H~Hh$ 	 	&&--DLL(E2>!ZZ,,++	! "#	$r   c                 r    t        |j                        D ]  }| j                  |d | j                         ! y r
   )r   r   r  r   )r#   r   r   s      r   visit_Importz_Visitor.visit_ImportO  s0    TZZ( 	8B  T4;;7	8r   c                     |j                   dk7  r|j                   n| j                  }| j                  |j                  xs dt	        |j
                        |       y )Nr    )r  r   r  r   r   r   )r#   r   r  s      r   visit_ImportFromz_Visitor.visit_ImportFromS  s?    "jjAo

4;;T[[.B
4::0FNr   c                     | j                   j                  d       | j                  |       | j                   j                          y r&   )r   r   generic_visitpopr#   r   s     r   visit_Ifz_Visitor.visit_IfW  s0    4 4 r   c                     | j                   j                  d       | j                  |       | j                   j                          y r&   )r   r   r  r  r  s     r   visit_FunctionDefz_Visitor.visit_FunctionDef\  s2    D!4 r   c                     | j                   j                  d       | j                  |       | j                   j                          y r&   r   r   r  r  r  s     r   	visit_Tryz_Visitor.visit_Tryc  6    !!$'4  r   c                     | j                   j                  d       | j                  |       | j                   j                          y r&   r  r  s     r   visit_TryExceptz_Visitor.visit_TryExcepth  r  r   c                      y r
   r   r  s     r   visit_Expressionz_Visitor.visit_Expressionm  s     	r   N) r   r   r   r$   propertyr   r   r  r  r	  r  r  r  visit_AsyncFunctionDefr  r  r  visit_BoolOpvisit_BinOpvisit_UnaryOpvisit_Lambdavisit_IfExp
visit_Dict	visit_Setvisit_ListCompvisit_SetCompvisit_GeneratorExpvisit_Comparevisit_Yieldvisit_YieldFromvisit_Await
visit_Callr   r   r   r   r   %  s    %       & &$(8O

 /!
!
 $L"K$M#L"K!J I%N$M%N)$M"K&O"K!J"Kr   r   c                   H    e Zd ZdZ fdZd% fd	Zd Zd&dZd ZeZ	d'dZ
e
Zd	 Zd
 Zd Zd( fd	ZeZd' fd	ZeZej(                  Zd&dZddedfdZd ZefdZd Zd Zd Zd Zd Zd Z d Z!edfdZ"	 d&dZ#d Z$d Z%d Z&d&dZ'd Z(d&d Z)d)d!Z*d*d"Z+d# Z,d$ Z- xZ.S )+ModuleGraphzr
    Directed graph whose nodes represent modules and edges represent
    dependencies between these modules.
    c                 ^    | j                  |      }|t        t        |   ||g|i |}|S r
   )	find_noder   r.  
createNode)r#   clsr   r   kwr3   r   s         r   r1  zModuleGraph.createNode  s8    NN4 9k43CKKKAr   Nc                    t         t        |   ||       |t        j                  }|| _        i | _        | j
                  j                  t        |             |D ]  }d | j
                  |<    || _        i | _	        i | _
        y )N)r   debug)r   r.  r$   sysr   	lazynodesr[   rM   replace_paths_package_path_map_legacy_ns_packages)	r#   r   excludesr8  impliesr   r5  r3   r   s	           r   r$   zModuleGraph.__init__  s    k4)U)C<88D	d7m, 	%A $DNN1	%* "$ $& r   c                    t        d       }t        j                         D ]  }|j                  d      }||j	                         }t        |d      }|6|D ]X  }t        j                  j                  t        |j                        g|j                  d       }||   j                  |       Z  |j                         D ci c]  \  }}|t        |       c}}| _        yc c}}w )z
        Resolve extra package `__path__` entries for legacy setuptools-based
        namespace packages, by reading `namespace_packages.txt` from dist
        metadata.
        c                      t               S r
   )rL   r   r   r   r   z<ModuleGraph.scan_legacy_namespace_packages.<locals>.<lambda>  s     r   znamespace_packages.txtN_pathr   )r   r   distributions	read_text
splitlinesrk   osr   joinr/   parentsplitrX   itemslistr:  )r#   legacy_ns_packagesdistns_packages	dist_pathpackage_namer   pathss           r   scan_legacy_namespace_packagesz*ModuleGraph.scan_legacy_namespace_packages  s     )7&446 	;D..)ABK"%002Kg.I  + ;ww||	(()!'', #<044T:;	;& (:'?'?'A$
#e $u+%$
  $
s   	C)c                     t        |t              r| j                  |||       yt        |t              rt	        |      | j                  ||d      }|D ]  }| j                  |||        y)aU  
        Create a reference from the passed source node to the passed other node,
        implying the former to depend upon the latter.

        While the source node _must_ be an existing graph node, the target node
        may be either an existing graph node _or_ a fully-qualified module name.
        In the latter case, the module with that name and all parent packages of
        that module will be imported _without_ raising exceptions and for each
        newly imported module or package:

        * A new graph node will be created for that module or package.
        * A reference from the passed source node to that module or package will
          be created.

        This method allows dependencies between Python objects _not_ importable
        with standard techniques (e.g., module aliases, C extensions).

        Parameters
        ----------
        node : str
            Graph node for this reference's source module or package.
        other : {Node, str}
            Either a graph node _or_ fully-qualified name for this reference's
            target module or package.
        N)r   rA   _updateReferencer   
ValueError_safe_import_hook)r#   r   r=   	edge_dataotherss        r   implyNodeReferencezModuleGraph.implyNodeReference  sj    6 eT"!!$y9%' ''++E4>F >%%dE9=>r   c                 P    | j                  |      }| j                  |      \  }}|S )zt
        Yield all nodes that `fromnode` dependes on (that is,
        all modules that `fromnode` imports.
        )r0  	get_edges)r#   fromnoder   	out_edges_s        r   outgoingzModuleGraph.outgoing  s*     ~~h'~~d+	1r   c              #      K   | j                  |      }| j                  |      \  }}|r8|D ]2  }t        |t              r| j	                  |d      D ]  }|  /| 4 y |D ]  }|  y wr   )r0  rX  r   r   incoming)r#   tonodecollapse_missing_modulesr   r[  in_edgesns          r   r^  zModuleGraph.incoming  s~     ~~f%nnT*8# a/!]]1e4    G  s   A,A.c                     | j                  |      }| j                  |      }| j                  j                  ||      duS )z> Return True iff there is an edge from 'fromnode' to 'tonode' N)r0  r   edge_by_node)r#   rY  r_  s      r   hasEdgezModuleGraph.hasEdge  s:    >>(+'zz&&x8DDr   c                 \   | j                  |      }| j                         D ]  }|j                  j                  |j                  dz         s-| j	                  |      \  }}|D ]Q  }|j                  j                  |j                  dz         r,| j                  ||      r?| j                  ||d       S |D ]Q  }|j                  j                  |j                  dz         r,| j                  ||      r?| j                  ||d       S | j                  j                  |       
 y)z
        Create edges to/from `packagenode` based on the edges to/from all
        submodules of that package _and_ then hide the graph nodes
        corresponding to those submodules.
        r   zpkg-internal-importz
pkg-importN)	r0  nodesrE   
startswithrX  re  rQ  r   	hide_node)r#   packagenodepkgrb  iter_outiter_incr=   s          r   foldReferenceszModuleGraph.foldReferences  s    nn[) 	$A<<**3>>C+?@!%!2Hh! M##..s~~/CD||C/))#u6KLM " D##..s~~/CD||E3/))%lCD JJ  #+	$r   c                 &   	 | j                  ||      }t	        |t
              rt	        |t
              s| j                  |||       y | j                  |||j                  |             y # t        t        f$ r | j                  |||      cY S w xY wr
   )edgeDataKeyErrorr   add_edger   r6   updateEdgeDatar>   )r#   rY  r_  rT  eds        r   rQ  zModuleGraph._updateReference8  s    	>x0B 2~.:i3X&)<&"**Y2GH *% 	>==69==	>s   A+ +"BBc                 0    t         t        |   |||      S )z<
        Create a reference from fromnode to tonode
        rT  )r   r.  createReference)r#   rY  r_  rT  r   s       r   rr  zModuleGraph.add_edgeC  s     [$7&T]7^^r   c                 
   t         t        |   |      }||S || j                  v r| j                  j	                  |      }|| j                  t        |      }|S t        |t              r\| j                  t        |      }| j                  |dd      j	                         }|j                  |       | j                  ||       |S | j                  |dd      j	                         }|D ]  }| j                  ||        |S y)a7  
        Graph node uniquely identified by the passed fully-qualified module
        name if this module has been added to the graph _or_ `None` otherwise.

        If (in order):

        . A namespace package with this identifier exists _and_ the passed
          `create_nspkg` parameter is `True`, this package will be
          instantiated and returned.
        . A lazy node with this identifier and:
          * No dependencies exists, this node will be instantiated and
            returned.
          * Dependencies exists, this node and all transitive dependencies of
            this node be instantiated and this node returned.
        . A non-lazy node with this identifier exists, this node will be
          returned as is.

        Parameters
        ----------
        name : str
            Fully-qualified name of the module whose graph node is to be found.
        create_nspkg : bool
            Ignored.

        Returns
        ----------
        Node
            Graph node of this module if added to the graph _or_ `None`
            otherwise.
        N)r   r.  findNoder7  r  r1  r   r   r   r   rS  r   rV  )	r#   r   create_nspkgdatadepsr3   r=   depr   s	           r   r0  zModuleGraph.find_nodeK  s
   @ [$06K4>>!>>%%d+D|OOND92 H1 D%( OOIt4 ..tT4@DDF
 007''51 H	 **4t<@@B 4C++As34 Hr   c                    | j                  dd|       t        j                  j                  |      }| j	                  |      }||S t        |d      5 }|j                         }ddd       t        j                  j                        }t        ||dt        j                  d      }t        ||ddd      }| j                  t        |      }| j                  ||d       | j!                  |||      }| j#                  |       ||_        | j&                  r | j)                  |j$                        |_        |S # 1 sw Y   xY w)z
        Create a node by path (not module name).  It is expected to be a Python
        source file, and will be scanned for dependencies.
           
run_scriptNrbexecTr   )msgrC  r   realpathr0  openread	importlibr   decode_sourcecompiler   PyCF_ONLY_ASTr1  r   rQ  
_scan_code_process_importsrB   r8  _replace_paths_in_code)	r#   pathnamecallerr3   fpcontentsco_astcorb  s	            r   
add_scriptzModuleGraph.add_script  s   
 	L(+77##H-NN8$=H(D! 	!RwwyH	!>>//98VS5F5FMVXvq$7OOFH-fa.OOAr6*a 008AF	! 	!s   D::Ec                    | j                  dd||||       | j                  |      }| j                  |||      \  }}| j                  dd||       |}|r|j	                  d      }	|	dk  rt        |      }	|d|	 ||	dz   d }}
|j                  d|
}| j                  |
||      }|*| j                  dd	|       t        d
t        |      z         |r| j                  dd|       |}|g}|rCt        |t        t        f      r-| j                  ||      D ]  }||vs|j                  |        |D ]  }| j!                  |||        |S )a	  
        Import the module with the passed name, all parent packages of this
        module, _and_ all submodules and attributes in this module with the
        passed names from the previously imported caller module signified by
        the passed graph node.

        Unlike most import methods (e.g., `_safe_import_hook()`), this method
        is designed to be publicly called by both external and internal
        callers and hence is public.

        Parameters
        ----------
        target_module_partname : str
            Partially-qualified name of the target module to be imported. See
            `_safe_import_hook()` for further details.
        source_module : Node
            Graph node for the previously imported **source module** (i.e.,
            module containing the `import` statement triggering the call to
            this method) _or_ `None` if this module is to be imported in a
            "disconnected" manner. **Passing `None` is _not_ recommended.**
            Doing so produces a disconnected graph in which the graph node
            created for the module to be imported will be disconnected and
            hence unreachable from all other nodes -- which frequently causes
            subtle issues in external callers (namely PyInstaller, which
            silently ignores unreachable nodes).
        target_attr_names : list
            List of the unqualified names of all submodules and attributes to
            be imported from the module to be imported if this is a "from"-
            style import (e.g., `[encode_base64, encode_noop]` for the import
            `from email.encoders import encode_base64, encode_noop`) _or_
            `None` otherwise.
        level : int
            Whether to perform an absolute or relative import. See
            `_safe_import_hook()` for further details.

        Returns
        ----------
        list
            List of the graph nodes created for all modules explicitly imported
            by this call, including the passed module and all submodules listed
            in `target_attr_names` _but_ excluding all parent packages
            implicitly imported by this call. If `target_attr_names` is `None`
            or the empty list, this is guaranteed to be a list of one element:
            the graph node created for the passed module.

        Raises
        ----------
        ImportError
            If the target module to be imported is unimportable.
        r   _import_hook   	load_tailr   r   Nr   "raise ImportError: No module namedNo module named zload_tail ->rv  )r  _determine_parent_find_head_packagemsginfindlenrE   _safe_import_modulemsgoutImportErrorreprr   r   r   %_import_importable_package_submodulesr   rQ  )r#   target_module_partnamesource_moduletarget_attr_namesr  r  source_packagetarget_package	submoduleiheadmnamer\   target_modulestarget_submodules                  r   import_hookzModuleGraph.import_hook  s   t 	N$:M=Z_`//>151H1H2E2;.. 	

1k>3IJ"	$&++C0A1u./+A,+AaCD1 )D(33T:E00uiHI  ACUK!"4tE{"BCC % 	A~y1!' M-4i,@"B$($N$N0%2 < #>9"))*:;< , 	CM!!}	 " C	C r   c                 &   | j                  dd|       d}|rf|j                  }t        |t              r|}nGd|v r&|d|j	                  d       }| j                  |      }n|j                  r| j                  |      }| j                  dd|       |S )z:
        Determine the package containing a node.
        r  determine_parentNr   zdetermine_parent ->)r  rE   r   r   rfindr0  rF   r  )r#   r  rE  pnames       r   r  zModuleGraph._determine_parent&  s     	

1(&1%%E&'*/u{{3/0.## .A,f5r   c           
         | j                  dd|||       d|v r|j                  dd      \  }}n|}d}|t        k(  r|r|j                  dz   |z   }n|}n|t        k(  r|}d}n|'| j                  dd       t        d	|d
|d|d      t        |dz
        D ]  }d|j                  vr'| j                  dd       t        d	|d
|d|d      |j                  j                  dd      d   }| j                  |      }	|	'| j                  dd       t        d	|d
|d|d      |	|us	J |	|f       |	} |r|j                  dz   |z   }n|j                  }| j                  |||      }
|
"| |t        k  r|}d}| j                  |||      }
|
| j                  dd|
|f       |
|fS | j                  dd|       t        d|z         )a&  
        Import the target package providing the target module with the passed
        name to be subsequently imported from the previously imported source
        package corresponding to the passed graph node.

        Parameters
        ----------
        source_package : Package
            Graph node for the previously imported **source package** (i.e.,
            package containing the module containing the `import` statement
            triggering the call to this method) _or_ `None` if this module is
            to be imported in a "disconnected" manner. **Passing `None` is
            _not_ recommended.** See the `_import_hook()` method for further
            details.
        target_module_partname : str
            Partially-qualified name of the target module to be imported. See
            `_safe_import_hook()` for further details.
        level : int
            Whether to perform absolute or relative imports. See the
            `_safe_import_hook()` method for further details.

        Returns
        ----------
        (target_package, target_module_tailname)
            2-tuple describing the imported target package, where:
            * `target_package` is the graph node created for this package.
            * `target_module_tailname` is the unqualified name of the target
              module to be subsequently imported (e.g., `text` when passed a
              `target_module_partname` of `email.mime.text`).

        Raises
        ----------
        ImportError
            If the package to be imported is unimportable.
        r  find_head_packager   r   r  Nr  z"Relative import outside of packagez)Relative import outside of package (name=z	, parent=, level=)r   zfind_head_package ->r  r  )r  rF  !ABSOLUTE_OR_RELATIVE_IMPORT_LEVELrE   ABSOLUTE_IMPORT_LEVELr  r)   rangersplitr0  r  r  r  )r#   r  r  r  target_module_headnametarget_module_tailnametarget_package_namer  p_fqdn
new_parentr  s              r   r  zModuleGraph._find_head_package@  sn   P 	

1)>;QSXY ((&,,S!4 ;"$: &<"%'" 55&4&?&?#&EH^&^#&<#++"8 "N %@A0.GH H 519% ,n777HHQ DE42NEKL L (2299#qA!D!^^F3
%HHQ DE42NEKL L "7 0:0 07!+%,( &"--36LL $ '5&?&?# 11"$7I !n&@UNcEc"8!N "55&(;^MN %KK1NDZ3[\!#999 	A;=PQ,/BBCCr   c              #     K   t        |      }| j                  dd||       d|v r1|j                  | j                  |             |j	                  d       |D ]~  }|j                  |      }|e|j                  dz   |z   }| j                  |||      }|>|j                  |      r| j                  dd|j                  |       mt        d|z         |  | j                  dd       yw)	a  
        Generator importing and yielding each importable submodule (of the
        previously imported package corresponding to the passed graph node)
        whose unqualified name is in the passed list.

        Elements of this list that are _not_ importable submodules of this
        package are either:

        * Ignorable attributes (e.g., classes, globals) defined at the top
          level of this package's `__init__` submodule, which will be ignored.
        * Else, unignorable unimportable submodules, in which case an
          exception is raised.

        Parameters
        ----------
        package : Package
            Graph node of the previously imported package containing the
            modules to be imported and yielded.

        attr_names : list
            List of the unqualified names of all attributes of this package to
            attempt to import as submodules. This list will be internally
            converted into a set, safely ignoring any duplicates in this list
            (e.g., reducing the "from"-style import
            `from foo import bar, car, far, bar, car, far` to merely
            `from foo import bar, car, far`).

        Yields
        ----------
        Node
            Graph node created for the currently imported submodule.

        Raises
        ----------
        ImportError
            If any attribute whose name is in `attr_names` is neither:
            * An importable submodule of this package.
            * An ignorable global attribute (e.g., class, variable) defined at
              the top level of this package's `__init__` submodule.
            In this case, this attribute _must_ be an unimportable submodule of
            this package.
        r  r  r  Nr   zD_import_importable_package_submodules: ignoring from-imported globalr  z(_import_importable_package_submodules ->)rL   r  r[   _find_all_submodulesrg   re   rE   r  rQ   r  r  )r#   package
attr_namesrP   r  submodule_names         r   r  z1ModuleGraph._import_importable_package_submodules  s    Z _


1=w
S
 *d77@Ac"
 $ Z	I
  55i@I  !(!3!3c!9I!E !44~w8	 $~ --i8$jlsl~l~  AJ  K  **<~*MNN OuZ	x 	

1@As   C+C-c              #     K   |j                   sy |j                   D ]  }	 t        j                  |      }|D ]o  }t        j                  j                         D ]A  }|j                  |      st        j                  j                  |      d t        |        } n f|dk7  sl| q  y # t        j                  t        f$ r | j                  dd|       Y w xY ww)Nr  zcan't list directoryr$   )rF   rC  listdirerrorIOErrorr  r  	machineryall_suffixesr   r   basenamer  )r#   r3   r   r   r   suffixs         r   r  z ModuleGraph._find_all_submodulesc  s     }} MM 	D

4(  '11>>@ F}}V,!ww//5mF|D
 :%J	 HHg& 2D9s3   CB,7C-5C#	C,,CCCCc                 z   | j                  dd|d|d       t        |t              sJ dt        |      z         t        |t              sJ dt        |      z         | j                  |      }|1t        |t              r|j
                  |k(  st        d|d|d	      t        |      | j                  |<   y)
a  
        Alias the source module to the target module with the passed names.

        This method ensures that the next call to findNode() given the target
        module name will resolve this alias. This includes importing and adding
        a graph node for the source module if needed as well as adding a
        reference from the target to source module.

        Parameters
        ----------
        src_module_name : str
            Fully-qualified name of the existing **source module** (i.e., the
            module being aliased).
        trg_module_name : str
            Fully-qualified name of the non-existent **target module** (i.e.,
            the alias to be created).
        r   zalias_module "z" -> ""z"%s" not a module name.NzTarget module "z" already imported as "z".)	r  r   r/   r0  r   rE   rR  r   r7  )r#   src_module_nametrg_module_name
trg_modules       r   alias_modulezModuleGraph.alias_modulez  s    $ 	?OTU/3/a1JSQ`Ma1aa//3/a1JSQ`Ma1aa/ ^^O4
!j),  O3#Z12 2
 +0*@'r   c                    | j                  dd|       | j                  |j                        }|| j                  |       n||k(  sJ d|d|d       |j                  j	                  d      \  }}}|rL| j                  |      }|| j                  dd|       y| j                  ||       |j                  ||       yy)	a  
        Add the passed module node to the graph if not already added.

        If that module has a parent module or package with a previously added
        node, this method also adds a reference from this module node to its
        parent node and adds this module node to its parent node's namespace.

        This high-level method wraps the low-level `addNode()` method, but is
        typically _only_ called by graph hooks adding runtime module nodes. For
        all other node types, the `import_module()` method should be called.

        Parameters
        ----------
        module : BaseModule
            Graph node of the module to be added.
        r   
add_moduleNzNew module z != previous r   r  zadd_module parent not found:)r  r0  rE   addNode
rpartitionrr  r`   )r#   r   module_addedparent_namer[  module_basenamerE  s          r   r  zModuleGraph.add_module  s    " 	L&) ~~f&7&78LL \)cfVb+cc) +1*;*;*F*Fs*K'Q^^K0F~:KHff-$$_f= r   c                 ^    | j                   j                  |g       }|j                  |       y)ax  
        Modulegraph does a good job at simulating Python's, but it can not
        handle packagepath '__path__' modifications packages make at runtime.

        Therefore there is a mechanism whereby you can register extra paths
        in this map for a package, and it will be honored.

        NOTE: This method has to be called before a package is resolved by
              modulegraph.

        Parameters
        ----------
        module : str
            Fully-qualified module name.
        directory : str
            Absolute or relative path of the directory to append to the
            '__path__' attribute.
        N)r9  
setdefaultr   )r#   rM  	directoryrN  s       r   append_package_pathzModuleGraph.append_package_path  s(    ( &&11,CYr   c           
         | j                  dd|||       | j                  |      }|d}|,|j                  |j                  }n| j                  dd       y	 | j	                  |||      \  }}| j                  |||      \  }}	|	w	 t        |	t        j                        r|	}
t        |
|ddd      }	nd}
| j                  ||	|
      }| j                  |       | j                  r| j                  |	      }	|	|_        |H| j#                  dd|d|       | j)                  ||t+        dddd             |j-                  ||       | j                  dd|       |S # t
        $ r}| j                  dd|z         Y d}~yd}~ww xY w# t         $ r. | j#                  d	d
|       t$        }| j'                  ||      }Y w xY w)a  
        Create a new graph node for the module with the passed name under the
        parent package signified by the passed graph node _without_ raising
        `ImportError` exceptions.

        If this module has already been imported, this module's existing graph
        node will be returned; else if this module is importable, a new graph
        node will be added for this module and returned; else this module is
        unimportable, in which case `None` will be returned. Like the
        `_safe_import_hook()` method, this method does _not_ raise
        `ImportError` exceptions when this module is unimportable.

        Parameters
        ----------
        module_partname : str
            Unqualified name of the module to be imported (e.g., `text`).
        module_name : str
            Fully-qualified name of this module (e.g., `email.mime.text`).
        parent_module : Package
            Graph node of the previously imported parent module containing this
            submodule _or_ `None` if this is a top-level module (i.e.,
            `module_name` contains no `.` delimiters). This parent module is
            typically but _not_ always a package (e.g., the `os.path` submodule
            contained by the `os` module).

        Returns
        ----------
        Node
            Graph node created for this module _or_ `None` if this module is
            unimportable.
        r   safe_import_moduleNz>safe_import_module -> None (parent_parent.packagepath is None)zsafe_import_module -> None (%r)r  r   Tr   z#safe_import_module: SyntaxError in r  z#safe_import_module create referencez->F)r9   r<   r:   r;   rv  zsafe_import_module ->)r  r0  rF   r  _find_moduler  _load_moduler   r   ASTr  r  r  r8  r  rB   SyntaxErrorr  r   r1  rQ  r6   r`   )r#   module_partnamemodule_nameparent_moduler   search_dirsr  loaderr1   r  r  rb  r2  s                r   r  zModuleGraph._safe_import_module  s   B 	

1*O[-X ,> K ( !,,8"/";";K KK#cd#'#4#4#[-$A &  ,,[(FKLVR~?!"cgg.!#$VXvq$G!%F;A))!,))!88<"$FK $HHQ=vt][ !! %""#	2 "  ''@ 	A.7W  A@3FG$ # ?HH@( .C!__S+>F?s+   E 	A6F	 	F'FF	4G ?G c           	      v   ddl m} | j                  dd|||j                  j                         |j                  d      d   }|j                  |      r8t        |t              r2| j                  t        |      }d|_        |j                  d d  |_        n| j                  j                  |g       }t        ||      r| j                  t         |      }n| j                  t"        |      }||_        t$        j&                  j)                  |      j+                  d      sJ t$        j&                  j-                  |      g|z   |_        |j                  | j.                  j                  |g       z   |_        t        |t              r|d fS d }|t0        u rt2        }	nwt        ||      rt4        }	d	 }
 |
|      }nY	 |j7                  |      }|%	 tE        ||dtF        jH                  d      }tJ        }	n 	 |jQ                  |      }|tR        ntT        }	| j                  |	|      }||_        | jW                  dd|       ||fS # t8        t:        f$ rp}t        |t:              rt        |j<                  t8              s | j?                  dd
| d| d       |jA                  |      }|jC                  |      }Y d }~d }~ww xY w# t:        $ r d }tL        }	Y tN        $ r$}tL        }	| j?                  dd||       Y d }~d }~ww xY w# tN        $ r%}| j?                  dd||       tT        }	Y d }~d }~ww xY w)Nr   )ExtensionFileLoaderr  load_moduler   r'   -z	__init__.c                    t         j                  j                  |       }t         j                  j                  |       j	                  d      d   }dD ]  }t         j                  j                  |||z         }t         j                  j                  |      sF	 t        |d      5 }|j                         }d d d        t        |dt        j                  d      }|c S  y # 1 sw Y   ,xY w# t        $ r
}Y d }~d }~ww xY w)Nr   r   >   .py.pyir  r  T)rC  r   dirnamer  rF  rD  isfiler  r  r  r   r  	Exception)	extension_filenamer   r  extsrc_filenamer  srcr  es	            r   _co_from_accompanying_sourcez>ModuleGraph._load_module.<locals>._co_from_accompanying_sources  s    ww'9:77++,>?EEcJ1M* C#%77<<hn#EL77>>,7 !,5 ,"$'')C,$S,@Q@QSWX!	, , % s*   C.&C"7&C."C+	'C..	D<Dz)load_module: failed to obtain source for z: z&! Falling back to reading as raw data!r  Tz load_module: InvalidSourceModulez4load_module: InvalidCompiledModule, Cannot load codezload_module ->),importlib._bootstrap_externalr  r  r   r   r  r   r   r    r1  r   rC   r"   rF   r:  rd   r   r   rC  r   r  rh  r  r9  r   r   r   
get_sourceUnicodeDecodeErrorr  __context__r  get_filenameget_datar  r   r  r   r   r  get_coder   r   r  )r#   r   r  r  r  partnamer3   ns_pkgpathsr  r2  r  r  r  r   r1   s                  r   r  zModuleGraph._load_moduleB  s   E

1mVX##,,	.$$S)"-X&&"34OO$4f= 
 & 5 5a 8 #66::62Ff&9:(8&AA8A%
 ww''1<<[III!#!: ;k I MMD,B,B,F,F- AM !-.4y ^#C 34C" .h7B,''1> 	" h8I8I4PB&C02B-/^> 5  OOC(
A'+2wq '4 ,& a-%amm5GHG$:Rs +%% & **84ood+9,D # .B-C  "-CHHQ BH " "" ! 0HHQ !0193@/C0sO   >I #K 7L
 KA&K  KLL#LL
	L8L33L8c                      j                  dd       fd} fd}d}d}		  j                  d|      }t        |      dk(  sJ dj                  |             |d   }t        |t              r:|	8 |       r1 |      r) j                  |        j!                  dd|      }|S t        |t"              r|j%                  d      }rt        |t&        t(        f      rD ]  }|j+                  |      r=|j-                  |      }|*||vr% j                  ||       |j                  |       R|j.                  d
z   |z   } j1                  |      }|	  j                  |g|        j1                  |      }|R|j3                  |      s!J dj                  ||j.                                j                  ddd|j.                  |       |	rJ j1                  |      r j                  dd|d|d       n j                  dd |d!|       ||_        |j5                  ||       |V j                  |||        j                  ||       ||vs|j                  |        |S # t        $ ri  j                  dd       g }
xs d	D ]D  } j	                  t
        d
z  z   |      } j                  ||       |
j                  |       F |
cY S t        $ r} |       r j                  ddddd        |      }	|	rmgdd j                  ddddd       	  j                  d|      }n2# t        $ r&} j                  ddt        |             Y d}~nd}~ww xY w|S j                  ddt                      j	                  t        t        |            } j                  ||       |g}Y d}~d}~ww xY w# t        $ r=} j                  ddt        |              j	                  t        |      }Y d}~d}~ww xY w)"a  
        Import the module with the passed name and all parent packages of this
        module from the previously imported caller module signified by the
        passed graph node _without_ raising `ImportError` exceptions.

        This method wraps the lowel-level `_import_hook()` method. On catching
        an `ImportError` exception raised by that method, this method creates
        and adds a `MissingNode` instance describing the unimportable module to
        the graph instead.

        Parameters
        ----------
        target_module_partname : str
            Partially-qualified name of the module to be imported. If `level`
            is:
            * `ABSOLUTE_OR_RELATIVE_IMPORT_LEVEL` (e.g., the Python 2 default)
              or a positive integer (e.g., an explicit relative import), the
              fully-qualified name of this module is the concatenation of the
              fully-qualified name of the caller module's package and this
              parameter.
            * `ABSOLUTE_IMPORT_LEVEL` (e.g., the Python 3 default), this name
              is already fully-qualified.
            * A non-negative integer (e.g., `1`), this name is typically the
              empty string. In this case, this is a "from"-style relative
              import (e.g., "from . import bar") and the fully-qualified name
              of this module is dynamically resolved by import machinery.
        source_module : Node
            Graph node for the previously imported **caller module** (i.e.,
            module containing the `import` statement triggering the call to
            this method) _or_ `None` if this module is to be imported in a
            "disconnected" manner. **Passing `None` is _not_ recommended.**
            Doing so produces a disconnected graph in which the graph node
            created for the module to be imported will be disconnected and
            hence unreachable from all other nodes -- which frequently causes
            subtle issues in external callers (e.g., PyInstaller, which
            silently ignores unreachable nodes).
        target_attr_names : list
            List of the unqualified names of all submodules and attributes to
            be imported via a `from`-style import statement from this target
            module if any (e.g., the list `[encode_base64, encode_noop]` for
            the import `from email.encoders import encode_base64, encode_noop`)
            _or_ `None` otherwise. Ignored unless `source_module` is the graph
            node of a package (i.e., is an instance of the `Package` class).
            Why? Because:
            * Consistency. The `_import_importable_package_submodules()`
              method accepts a similar list applicable only to packages.
            * Efficiency. Unlike packages, modules cannot physically contain
              submodules. Hence, any target module imported via a `from`-style
              import statement as an attribute from another target parent
              module must itself have been imported in that target parent
              module. The import statement responsible for that import must
              already have been previously parsed by `ModuleGraph`, in which
              case that target module will already be frozen by PyInstaller.
              These imports are safely ignorable here.
        level : int
            Whether to perform an absolute or relative import. This parameter
            corresponds exactly to the parameter of the same name accepted by
            the `__import__()` built-in: "The default is -1 which indicates
            both absolute and relative imports will be attempted. 0 means only
            perform absolute imports. Positive values for level indicate the
            number of parent directories to search relative to the directory of
            the module calling `__import__()`." Defaults to -1 under Python 2
            and 0 under Python 3. Since this default depends on the major
            version of the current Python interpreter, depending on this
            default can result in unpredictable and non-portable behaviour.
            Callers are strongly recommended to explicitly pass this parameter
            rather than implicitly accept this default.

        Returns
        ----------
        list
            List of the graph nodes created for all modules explicitly imported
            by this call, including the passed module and all submodules listed
            in `target_attr_names` _but_ excluding all parent packages
            implicitly imported by this call. If `target_attr_names` is either
            `None` or the empty list, this is guaranteed to be a list of one
            element: the graph node created for the passed module. As above,
            `MissingNode` instances are created for all unimportable modules.
        r   rS  c                      d uxrH d u xrB  t         k(  xr7 t              t        u xr$ dj                  j	                  d      d   z   k(  S )Nr[  r   r  )r  r   r   rE   r  )r  r  r  r  s   r   is_swig_candidatez8ModuleGraph._safe_import_hook.<locals>.is_swig_candidate  sr    !- H%-H22H '<7H +M44??DQGGH	Ir   c                    t        | j                  d      5 }|j                         }d d d        t        j                  j                        }|r|j                         d   nd}j                  dd|z         d|v S # 1 sw Y   XxY w)Nr  r   r     z%SWIG wrapper candidate first line: %rzautomatically generated by SWIG)r  rC   r  r  r   r  rB  r  )r  r  r  
first_liner#   s       r   is_swig_wrapperz6ModuleGraph._safe_import_hook.<locals>.is_swig_wrapper  s    m,,d3 %r779% ~~33H=H5=,,.q12JHHQ?:NO4
BB% %s   B  B	N)r  r  r  r  zInvalid relative importr  r   rv  r  zSWIG import candidate (name=z	, caller=r  r  r  r   zSWIG import (caller=z, fromlist=zSWIG ImportError:zImportError:z@Expected import_hook() toreturn only one module but received: {}r   T)r<   z!No global named {} in {}.__init__z#ignoring imported non-module globalzSWIG import error: z
 basename z already existszSWIG import renamed from z to )r  r  r)   r  r1  r   rQ  r   r  r/   r   r4   r  formatr   
removeNoderS  r6   _replacer   r   rV   rb   rE   r0  rQ   r`   )r#   r  r  r  r  r  r  r
  r  is_swig_importr   subr3   r  r\   target_submodule_partnamer  target_submodule_names   `````             r   rS  zModuleGraph._safe_import_hook  sP   d 	')?Pachi	I	C  
 Z	1!--&"&ey . JNx >"a' 	N66<f^6L	N'
 'q)m]3%*;*=}-$ OOM*!33&"&a9 4 FN
 "!i0!**D*9I M-4i,@"B .? A@) !--.GH'4'B'B1(3$
 (3 ,>A 11 - 0*3 2 5 +112BC  ",,s25NN & $(>>2G#H  $+KB( ((2M/H.I"'&/	 ) 1 ,0>>:O+P(
 ,3#0#?#? 9$; ? C J J$=$1$<$<!>? $; !HHQ(;=bdqd|d|  X  Y$ *  $~~.GH $$% )>(A%C!D !%$%(=(A%C!D %> !1 ; ++-/?A#/))%'79 * N))%'79 * N (~=&--.>?CA@H e * 		KK4e.0ACF(/C !OO$9$'%K2H$H#O%%mQ)%La 	!
 M J	1D !".uFG "1!?! *@(@%-/*EHHQ -/@%IJC)-)9)92M.2"'&/	 *: *1
 ' C$7SBBC %NCH5 !%!*30FG!I %%!=I & G #0UJ	1l ' BNCH=+/??)+@,B(Bsj   J -A;P)APA/P PAO=M0/O=0	N9NO=NAO==P	Q2QQc                     g |_         |(| j                  ||       | j                  ||d       |S | j                  ||d       |S )a  
        Parse and add all import statements from the passed code object of the
        passed source module to this graph, recursively.

        **This method is at the root of all `ModuleGraph` recursion.**
        Recursion begins here and ends when all import statements in all code
        objects of all modules transitively imported by the source module
        passed to the first call to this method have been added to the graph.
        Specifically, this method:

        1. If the passed `module_code_object_ast` parameter is non-`None`,
           parses all import statements from this object.
        2. Else, parses all import statements from the passed
           `module_code_object` parameter.
        1. For each such import statement:
           1. Adds to this `ModuleGraph` instance:
              1. Nodes for all target modules of these imports.
              1. Directed edges from this source module to these target
                 modules.
           2. Recursively calls this method with these target modules.

        Parameters
        ----------
        module : Node
            Graph node of the module to be parsed.
        module_code_object : PyCodeObject
            Code object providing this module's disassembled Python bytecode.
            Ignored unless `module_code_object_ast` is `None`.
        module_code_object_ast : optional[ast.AST]
            Optional abstract syntax tree (AST) of this module if any or `None`
            otherwise. Defaults to `None`, in which case the passed
            `module_code_object` is parsed instead.
        Returns
        ----------
        module : Node
            Graph node of the module to be parsed.
        F)is_scanning_importsT)rG   	_scan_ast_scan_bytecode)r#   r   module_code_objectmodule_code_object_asts       r   r  zModuleGraph._scan_codeQ	  sn    Z $& 
 "-NN6#9: *   G  *   F r   c                 >    t        | |      }|j                  |       y)a  
        Parse and add all import statements from the passed abstract syntax
        tree (AST) of the passed source module to this graph, non-recursively.

        Parameters
        ----------
        module : Node
            Graph node of the module to be parsed.
        module_code_object_ast : ast.AST
            Abstract syntax tree (AST) of this module to be parsed.
        N)r   visit)r#   r   r  visitors       r   r  zModuleGraph._scan_ast	  s     4(,-r   c                 (   d}d}t        d      }t        j                  |      D ]i  }|s|j                  dk(  r|st        j
                  dk\  r&|d   j                  dv sJ |d   j                  d	v s*J |d   j                  d
k(  sJ |d   j                  d
k(  sJ |d   j                  }|d   j                  }|t        |      t        u sJ |j                  }d}	|"t        |      }d|v r|j                  d       d}	|j                  j                  |	||||fi f       nW|j                  dv r|j                  }
|j                  |
       n+|j                  dv r|j                  }
|j                  |
       |j                  |       l y)a  
        Parse and add all import statements from the passed code object of the
        passed source module to this graph, non-recursively.

        This method parses all reasonably parsable operations (i.e., operations
        that are both syntactically and semantically parsable _without_
        requiring Turing-complete interpretation) directly or indirectly
        involving module importation from this code object. This includes:

        * `IMPORT_NAME`, denoting an import statement. Ignored unless
          the passed `is_scanning_imports` parameter is `True`.
        * `STORE_NAME` and `STORE_GLOBAL`, denoting the
          declaration of a global attribute (e.g., class, variable) in this
          module. This method stores each such declaration for subsequent
          lookup. While global attributes are usually irrelevant to import
          parsing, they remain the only means of distinguishing erroneous
          non-ignorable attempts to import non-existent submodules of a package
          from successful ignorable attempts to import existing global
          attributes of a package's `__init__` submodule (e.g., the `bar` in
          `from foo import bar`, which is either a non-ignorable submodule of
          `foo` or an ignorable global attribute of `foo.__init__`).
        * `DELETE_NAME` and `DELETE_GLOBAL`, denoting the
          undeclaration of a previously declared global attribute in this
          module.

        Since `ModuleGraph` is _not_ intended to replicate the behaviour of a
        full-featured Turing-complete Python interpreter, this method ignores
        operations that are _not_ reasonably parsable from this code object --
        even those directly or indirectly involving module importation. This
        includes:

        * `STORE_ATTR(namei)`, implementing `TOS.name = TOS1`. If `TOS` is the
          name of a target module currently imported into the namespace of the
          passed source module, this opcode would ideally be parsed to add that
          global attribute to that target module. Since this addition only
          conditionally occurs on the importation of this source module and
          execution of the code branch in this module performing this addition,
          however, that global _cannot_ be unconditionally added to that target
          module. In short, only Turing-complete behaviour suffices.
        * `DELETE_ATTR(namei)`, implementing `del TOS.name`. If `TOS` is the
          name of a target module currently imported into the namespace of the
          passed source module, this opcode would ideally be parsed to remove
          that global attribute from that target module. Again, however, only
          Turing-complete behaviour suffices.

        Parameters
        ----------
        module : Node
            Graph node of the module to be parsed.
        module_code_object : PyCodeObject
            Code object of the module to be parsed.
        is_scanning_imports : bool
            `True` only if this method is parsing import statements from
            `IMPORT_NAME` opcodes. If `False`, no import statements will be
            parsed. This parameter is typically:
            * `True` when parsing this module's code object for such imports.
            * `False` when parsing this module's abstract syntax tree (AST)
              (rather than code object) for such imports. In this case, that
              parsing will have already parsed import statements, which this
              parsing must avoid repeating.
        Nr  )maxlenIMPORT_NAME)r      >   
LOAD_CONSTLOAD_SMALL_INTLOAD_CONST_IMMORTALr'   >   r   r"  r   Fr  T)
STORE_NAMESTORE_GLOBAL)DELETE_NAMEDELETE_GLOBAL)r   r   iterate_instructionsopnamer6  version_infoargvalr   r   r   rg   rG   r   rY   rh   )r#   r   r  r  r  r<   
prev_instsinstr  r  r   s              r   r  zModuleGraph._scan_bytecode	  s   ~  !_
--.@A T	$D {{m+ + ##w.%b>004kkkk%b>004YYYY%b>00L@@@%b>00L@@@"2--%b>00'4>U+BBB)-& "	'#H~Hh ,$(	 ((//+VXuE1   >> {{&&t, @@
 {{2248d#iT	$r   c                 V   |j                   sy|j                   D ]  \  }}} | j                  |i |}|s|d   }|s$|j                  |       |j                  j	                  |j                         |j
                  g|d   }|j                  j                  |        d|_         y)a  
        Graph all target modules whose importations were previously parsed from
        the passed source module by a prior call to the `_scan_code()` method
        and methods call by that method (e.g., `_scan_ast()`,
        `_scan_bytecode()`, `_scan_bytecode_stores()`).

        Parameters
        ----------
        source_module : Node
            Graph node of the source module to graph target imports for.
        Nr   )rG   rS  r]   rI   r[   rB   rX   )r#   r  r  import_infokwargsr  r\   target_module_names           r   r  zModuleGraph._process_importsH
  s     .. /<.M.M (	,*I{F 4T33[KFKN! *1-M  ::=I@@GG!DDF
 !%%-)4Q&!DDHH*,O(	,V +/'r   c                    ||j                   dz   |z   }n|}| j                  |      }|| j                  dd|       t        |      |&|t        j
                  v rdt        fS | j                  }| j                  |||      S )a  
        3-tuple describing the physical location of the module with the passed
        name if this module is physically findable _or_ raise `ImportError`.

        This high-level method wraps the low-level `modulegraph.find_module()`
        function with additional support for graph-based module caching.

        Parameters
        ----------
        name : str
            Fully-qualified name of the Python module to be found.
        path : list
            List of the absolute paths of all directories to search for this
            module _or_ `None` if the default path list `self.path` is to be
            searched.
        parent : Node
            Package containing this module if this module is a submodule of a
            package _or_ `None` if this is a top-level module.

        Returns
        ----------
        (filename, loader)
            See `modulegraph._find_module()` for details.

        Raises
        ----------
        ImportError
            If this module is _not_ found.
        Nr   r   zfind_module: already included?)	rE   r0  r  r  r6  builtin_module_namesr   r   _find_module_path)r#   r   r   rE  fullnamer   s         r   r  zModuleGraph._find_module
  s    > ((3.5HH~~h'HHQ8$?d##<s///n--99D%%hd;;r   c                    | j                  dd||       d}g }	 |D ]3  }t        j                  |      }|t        |d      rAd}|j	                  |      }	|	|	j
                  }|j                  |	j                  xs g        nbt        |d      r&|j                  |      \  }}
|j                  |
       n0t        |d      r|j                  |      }nt        d|d|d	      |d}t        |d
      r|j                  |      }n+t        |d      r|j                  }nt        d|d|d      || j                  dd|       0||f} n |r|d   t        |      f}| j!                  dd|       |t        dt%        |      z         |S # t        $ r}| j!                  dd|       Y d}~Od}~wt"        $ r}| j!                  dd|        d}~ww xY w)a  
        3-tuple describing the physical location of the module with the passed
        name if this module is physically findable _or_ raise `ImportError`.

        This low-level function is a variant on the standard `imp.find_module()`
        function with additional support for:

        * Multiple search paths. The passed list of absolute paths will be
          iteratively searched for the first directory containing a file
          corresponding to this module.
        * Compressed (e.g., zipped) packages.

        For efficiency, the higher level `ModuleGraph._find_module()` method
        wraps this function with support for module caching.

        Parameters
        ----------
        module_name : str
            Fully-qualified name of the module to be found.
        search_dirs : list
            List of the absolute paths of all directories to search for this
            module (in order). Searching will halt at the first directory
            containing this module.

        Returns
        ----------
        (filename, loader)
            2-tuple describing the physical location of this module, where:
            * `filename` is the absolute path of this file.
            * `loader` is the import loader.
              In case of a namespace package, this is a NAMESPACE_PACKAGE
              instance

        Raises
        ----------
        ImportError
            If this module is _not_ found.
        r  z_find_module_path <-N	find_specfind_loaderfind_modulezModule z
 importer z loader unobtainabler  r   z loader z path unobtainablez _find_module_path path not foundr   r   z"_find_module_path -> unicode errorz_find_module_path -> exceptionz_find_module_path ->r  )r  pkgutilget_importerr   r6  r  extendsubmodule_search_locationsr7  r8  r  r  r   r  r    r  r  r  r  )r#   r4  r  r  	path_datar"   
search_dirimporterr  specloader_namespace_dirsr  r1   s                r   r3  zModuleGraph._find_module_path
  s-   N 	

1,hD 	 Q	) ID
"//
; # 8[1!F#--k:D'!%&--d.M.M.SQST X}54<4H4H#5%1F1"))*?@ X}5%11+>F &GRT\]_ _ >  
 6>2%22;?HVV,%{{H &CNPVWY Y
 #HHQ BHM &v.	IIDN "!/!2!2>!B!DI 	A-y9043DDEE " 	FKK?EE  	KK;SA	s$   EF 	GF44G GGc           	         |t         j                  }g }g }| j                         D ]b  }t        j                  j                  |j                        }t        |t              r|j                  ||f       P|j                  ||f       d |j                          |j                          |D cg c]  \  }}|	 }}}|j                  |       |}ddj                  |      z   }	t        t        d|	iz  |       d }
|D ]X  \  }}d}t        |t              rt         |ddz  }nxt        |t"              rt         |d	|j$                  z  dz  }nNt&        j(                  j+                  |j$                  xs d      }t,        |||j.                  j0                  d
z  }t3        |
| j5                  |            \  }}|rAg }|D ]  }|j                  d|d|d        dj                  |      }|t6        d|dz  z  }|rAg }|D ]  }|j                  d|d|d        dj                  |      }|t6        d|dz  z  }t        t8        ||dz  |       [ t        t:        |       y c c}}w )Nz modulegraph cross reference for z, TITLE)filec                     | D cg c].  }|st         j                  j                  |j                        0 }}|j	                          |S c c}w r
   )rC  r   r  rD   sort)modsmodlsts      r   sorted_namelistz0ModuleGraph.create_xref.<locals>.sorted_namelist[  s>    ?CKs277##CNN3KCKHHJJ Ls
   A+Ar  z<i>(builtin module)</i>)NAMETYPEz<tt>%s</tt>)rK  URLrL  z  <a href="#z">z</a>
z	 &#8226; imports)HEADLINKSzimported by)rK  CONTENT)r6  stdout
iter_graphrC  r   r  rD   r   r   r   rF  r;  rD  printheaderr   contplr   rC   urllibrequestpathname2urlcontpl_linkedr   r   maprX  rN  entryfooter)r#   outscriptsrG  rH  r   snr3   scriptnamestitlerJ  contenturlouteincelinksrb  s                    r   create_xrefzModuleGraph.create_xrefF  s`   ;**C??$ 	)C77##CNN3D#v&c{+T3K(	) 			'./eb!r//t2TYY{5KKf''c2	  	HGD!G!]+ D,E$G GAy) D,9AJJ,F$H H nn11!**2BC'434;;3G3G+I I_dnnQ.?@JD$ JALL1a!HIJ
 $((/7i%%HHH JALL1a!HIJ
 $((/7me%LLL%4G<<3G?	H@ 	f3W 0s   1I0c              #      !"K   t        t        | j                  j                  | j                  j	                  |                   }| j                  j
                  !t               }t               }i }i }i }t               }	t        |      }d }
d "d|d t        dd      }d |j                         D ]  }d	 |z  d
  |D ]W  \  }}}}t        |dd       ||<   t        |t              s)|||j                  <   t        |g      ||<   |j                  |       Y |D ]  \  }}}}!fd|D        D ]  }|j                  |        d|ddj!                   |
||||      j                         D cg c]  } |z  	 c}      d |j#                  |      }|t               x}||<   ||   }||j#                  |d |j%                  d             }||j                  |        g }i }|D ]  }g ||<   	 |r!|j'                         \  }}}}||f|	v r|	j                  ||f       ||   }||   |z  }|sT|rRt)        |      }t+        |      dk7  s|d   |k7  r1|j                  ||||d   f       |j                  |d|d   |f       |rt|j-                         }||k(  r|j                  ||||f       n^||k(  r||   j                  |d||f       n@|j                  ||||f       |j                  ||||f       n|j                  ||||f       |r! "fd}|j                         D ].  \  }}d|d d||   d  ||d      D ]  }|  d 0  ||d	      D ]  }|  d y c c}w w)Nc                     t        |t              sdt        |       iS dt        |      j                  z   }t        |j                         d d d      D ]  \  }}|d||fz  z  } |ddS )Nlabelz<f0> r   z
| <f%d> %srecord)rk  shape)r   rA   r/   r   r   	enumerater   )r   r{  r\  r^  sr  vs          r   nodevisitorz0ModuleGraph.itergraphreport.<locals>.nodevisitor  sw    dD)T++ $t*---A!$.."22A"6: +1\QF**+22r   c                 *    |dk(  rddiS |dk(  rddiS i S )Norphanstyledashedpkgrefdottedr   )edger{  r  tails       r   edgevisitorz0ModuleGraph.itergraphreport.<locals>.edgevisitor  s/     x**!**Ir   zdigraph z {
charset="UTF-8";
LRtrue)rankdirconcentratez%s="%s"	z;
rD   c              3   .   K   | ]  } |        y wr
   r   ).0r  describe_edges     r   	<genexpr>z.ModuleGraph.itergraphreport.<locals>.<genexpr>  s     <aq)<s   z	"z" [,z];
r   r   r   rv  r'   c              3      K   |dz   }| D ]J  \  }}}} 
||||      }|||dj                  |j                         D cg c]  }	|z  	 c}      fz   L y c c}w w)Nz"%s" -> "%s" [%s];
r  )rD  rG  )edgestabsedgestrrx  r{  r  ry  attribsitemcpattrz  s            r   do_graphz-ModuleGraph.itergraphreport.<locals>.do_graph  sy     33G,1 (tT4%dD$=HHIut|IJ!  
 Js   ;AA
Az	subgraph "cluster_z" {
z			label="z";
z		z	}
z}
)rH  r[  r   describe_nodeiterdfsr  r   rL   rM   rG  rk   r   r   rD   rX   r   rD  rd   r  popleftsortedr  r  )#r#   r   flatpackagesrg  r  packagenodespackageidentsnodetoident
inpackages	mainedgesrq  attrr  r   r{  r\  r^  rx  insideidentpkgnoder   	subgraphskeyr  ry  tailpkgscommonusepkgsr  gro  r  r  rz  s#                                   @@@r   itergraphreportzModuleGraph.itergraphreport  s    S114::3E3Ed3KLM

00u
E	 L)	3	 59::Df5JJL 	.D$t|--	. 16 	',T48 'lD AK$(15doo.#&v;
4   &	' 16 	$,T48<8< #T"#
 dHh?EEG'+UT\    ^^D)F~,/E1D)%E}#''.?u{{3/?(@AG"

7#-	$0 	 	 CIcN	  %*]]_"D$dt*MM4,'!$'H%0Fh *w<1$
d(:LL$dGAJ!?@LL$'"+t!DE6>LL$dD!9:V^f%,,dHdD-IJLL$fd!;<LL$fd!;< dD$561 4		 ") 	HAu3466)4Q99eV, M	 %& 	AG	 Is(   C/N5BN;NAN#EN*A#Nc                 j    |t         j                  }|j                  | j                  |             y )N)r  )r6  rR  
writelinesr  )r#   fileobjr  s      r   graphreportzModuleGraph.graphreport   s,    ?jjG4//\/JKr   c           	         t                t        ddz         t        ddz         t        | j                         d       D ]  }t        |t              r=t        t        |      j                  dd|j                  dd|j                         Pt        t        |      j                  dd|j                  dd|j                  xs d	        y
)zPrint a report to stdout, listing the found modules with their
        paths, as well as modules that are missing, or seem to be missing.
        z%-15s %-25s %s)ClassNameFile)z---------r  c                     | j                   S r
   )rD   )rb  s    r   r   z$ModuleGraph.report.<locals>.<lambda>  s
     r   )r  15 25r  N)
rT  r  rS  r   r   r   r   rD   rE   rC   )r#   r3   s     r   reportzModuleGraph.report  s     	!::;!::;)/EF 	]A!Y'$q'*:*:ALL!,,WX$q'*:*:ALL!**JZXZJZ[\		]r   c                 @   t         j                  j                  |j                        x}}| j                  D ]i  \  }}t         j                  j                  |d      }t         j                  j                  |d      }|j                  |      sX||t        |      d  z   } n |S t        |j                        }t        t        |            D ]2  }t        ||   t        |            s| j                  ||         ||<   4 |j                  t        |      |      S )Nr  )	co_constsco_filename)rC  r   normpathr  r8  rD  rh  r  rH  r  r  r   r   r  replacer   )r#   r  new_filenameoriginal_filenamefr   constsr  s           r   r  z"ModuleGraph._replace_paths_in_code  s    +-77+;+;BNN+KK(&& 	DAqQ#AQ#A ++A. #4SVW#==	 Ibll#s6{# 	CA&)T"X. 77q	Bq		C zzE&M|zLLr   )Nr   r   r   Nr   r
   )T)direct)Gr   )Nr   )/r   r   r   r   r1  r$   rO  rV  r\  getReferencesr^  getReferersre  rn  rQ  rr  rw  r0  ry  r   flattenrS  r  r   r  r  r  r  r  r  r  r  r  r  rS  r  r  r  r  r  r3  rh  r  r  r  r  r   r   s   @r   r.  r.    s   &&
<">H M" KE$J	I_ OEN H$$JF "nb< #	DTVBr."AJ#>L 0cJ~D #dLf  $	?B.4Y$x=/@0<fHV9 v}~L
]Mr   r.  )Nr   r   rC  r9  r6  typesr-   collectionsr   r   r   urllib.requestrW  r   importlib.utilr  importlib.machineryr)  importlib.metadatametadatar   object_pkg_resources_not_importedmodulesrd   _old_pkg_resourcesSimpleNamespacefake_pkg_resourcesrequirealtgraph.ObjectGraphr   altgraphr   r  r   r   r    r  r  r   r  r)   r4   r6   rA   r/   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rU  r\  rV  rZ  rN  r]  r   r   NodeVisitorr   r.  r   r   r   <module>r     s    	  
  	 6 6     w3)"((:UV8M8M8M8OOCKK #5!U0#!<<'9O$KK(  
  %' !   - 	+ 	?j!1JL ?>~@ ~@BC (2 (2V	 		Y 		I 	4Y 4 T  W W	J 		: 		, 		Z 		J 		
 		j 		y' 		w 		J 	,	W 	0** **J *
	

 
J,

	>  _#s _#D\"M+ \"Mm !<<'9O$KK(s   AH5 5#I