
     hiR                     `    d Z ddlmZ ddlmZmZ  G d d      Z G d d      Z G d d	      Zy
)a  
Classes facilitating communication between PyInstaller and import hooks.

PyInstaller passes instances of classes defined by this module to corresponding functions defined by external import
hooks, which commonly modify the contents of these instances before returning. PyInstaller then detects and converts
these modifications into appropriate operations on the current `PyiModuleGraph` instance, thus modifying which
modules will be frozen into the executable.
    )format_binaries_and_datas)RuntimeModuleRuntimePackagec                   N    e Zd ZdZd Zed        Zed        Zd Zd Z	d Z
d Zy	)
PreSafeImportModuleAPIa*	  
    Metadata communicating changes made by the current **pre-safe import module hook** (i.e., hook run immediately
    _before_ a call to `ModuleGraph._safe_import_module()` recursively adding the hooked module, package,
    or C extension and all transitive imports thereof to the module graph) back to PyInstaller.

    Pre-safe import module hooks _must_ define a `pre_safe_import_module()` function accepting an instance of this
    class, whose attributes describe the subsequent `ModuleGraph._safe_import_module()` call creating the hooked
    module's graph node.

    Each pre-safe import module hook is run _only_ on the first attempt to create the hooked module's graph node and
    then subsequently ignored. If this hook successfully creates that graph node, the subsequent
    `ModuleGraph._safe_import_module()` call will observe this fact and silently return without attempting to
    recreate that graph node.

    Pre-safe import module hooks are typically used to create graph nodes for **runtime modules** (i.e.,
    modules dynamically defined at runtime). Most modules are physically defined in external `.py`-suffixed scripts.
    Some modules, however, are dynamically defined at runtime (e.g., `six.moves`, dynamically defined by the
    physically defined `six.py` module). However, `ModuleGraph` only parses `import` statements residing in external
    scripts. `ModuleGraph` is _not_ a full-fledged, Turing-complete Python interpreter and hence has no means of
    parsing `import` statements performed by runtime modules existing only in-memory.

    'With great power comes great responsibility.'


    Attributes (Immutable)
    ----------------------------
    The following attributes are **immutable** (i.e., read-only). For safety, any attempts to change these attributes
    _will_ result in a raised exception:

    module_graph : PyiModuleGraph
        Current module graph.
    parent_package : Package
        Graph node for the package providing this module _or_ `None` if this module is a top-level module.

    Attributes (Mutable)
    -----------------------------
    The following attributes are editable.

    module_basename : 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`).
    c                 <    || _         || _        || _        || _        y N)_module_graphmodule_basenamemodule_name_parent_package)selfmodule_graphr   r   parent_packages        IC:\des-py\Monitor\venv\Lib\site-packages\PyInstaller/depend/imphookapi.py__init__zPreSafeImportModuleAPI.__init__D   s"    ).&-    c                     | j                   S z'
        Current module graph.
        r
   r   s    r   r   z#PreSafeImportModuleAPI.module_graphK       
 !!!r   c                     | j                   S )z.
        Parent Package of this node.
        )r   r   s    r   r   z%PreSafeImportModuleAPI.parent_packageR   s    
 ###r   c                 L    | j                   j                  t        |             y)as  
        Add a graph node representing a non-package Python module with the passed name 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 method adds a graph node representing such a runtime module. Since this module 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 circumvent this, simply call
        `add_runtime_package()` instead.

        Parameters
        ----------
        module_name : str
            Fully-qualified name of this module (e.g., `gi.repository.Gst`).

        Examples
        ----------
        This method is typically called by `pre_safe_import_module()` hooks, e.g.:

            def pre_safe_import_module(api):
                api.add_runtime_module(api.module_name)
        N)r
   
add_moduler   )r   r   s     r   add_runtime_modulez)PreSafeImportModuleAPI.add_runtime_moduleY   s    4 	%%mK&@Ar   c                 L    | j                   j                  t        |             y)a:  
        Add a graph node representing a non-namespace Python package with the passed name 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 method adds a graph node representing 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.

        Parameters
        ----------
        package_name : str
            Fully-qualified name of this package (e.g., `six.moves`).

        Examples
        ----------
        This method is typically called by `pre_safe_import_module()` hooks, e.g.:

            def pre_safe_import_module(api):
                api.add_runtime_package(api.module_name)
        N)r
   r   r   )r   package_names     r   add_runtime_packagez*PreSafeImportModuleAPI.add_runtime_packageu   s    4 	%%n\&BCr   c                 <    | j                   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 the source module.

        Parameters
        ----------
        real_module_name : str
            Fully-qualified name of the **existing module** (i.e., the module being aliased).
        alias_module_name : str
            Fully-qualified name of the **non-existent module** (i.e., the alias to be created).
        N)r
   alias_module)r   real_module_namealias_module_names      r   add_alias_modulez'PreSafeImportModuleAPI.add_alias_module   s      	''(8:KLr   c                 P    | j                   j                  | j                  |       y)a  
        Modulegraph does a good job at simulating Python's, but it cannot 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.

        Parameters
        ----------
        directory : str
            Absolute or relative path of the directory to be appended to this package's `__path__` attribute.
        N)r
   append_package_pathr   )r   	directorys     r   r&   z*PreSafeImportModuleAPI.append_package_path   s      	..t/?/?Kr   N)__name__
__module____qualname____doc__r   propertyr   r   r   r   r$   r&    r   r   r   r      sM    *V. " " $ $B8D8M$Lr   r   c                   6    e Zd ZdZd Zed        Zed        Zy)PreFindModulePathAPIa  
    Metadata communicating changes made by the current **pre-find module path hook** (i.e., hook run immediately
    _before_ a call to `ModuleGraph._find_module_path()` finding the hooked module's absolute path) back to PyInstaller.

    Pre-find module path hooks _must_ define a `pre_find_module_path()` function accepting an instance of this class,
    whose attributes describe the subsequent `ModuleGraph._find_module_path()` call to be performed.

    Pre-find module path hooks are typically used to change the absolute path from which a module will be
    subsequently imported and thus frozen into the executable. To do so, hooks may overwrite the default
    `search_dirs` list of the absolute paths of all directories to be searched for that module: e.g.,

        def pre_find_module_path(api):
            api.search_dirs = ['/the/one/true/package/providing/this/module']

    Each pre-find module path hook is run _only_ on the first call to `ModuleGraph._find_module_path()` for the
    corresponding module.

    Attributes
    ----------
    The following attributes are **mutable** (i.e., modifiable). All changes to these attributes will be immediately
    respected by PyInstaller:

    search_dirs : list
        List of the absolute paths of all directories to be searched for this module (in order). Searching will halt
        at the first directory containing this module.

    Attributes (Immutable)
    ----------
    The following attributes are **immutable** (i.e., read-only). For safety, any attempts to change these attributes
    _will_ result in a raised exception:

    module_name : str
        Fully-qualified name of this module.
    module_graph : PyiModuleGraph
        Current module graph. For efficiency, this attribute is technically mutable. To preserve graph integrity,
        this attribute should nonetheless _never_ be modified. While read-only `PyiModuleGraph` methods (e.g.,
        `findNode()`) are safely callable from within pre-find module path hooks, methods modifying the graph are
        _not_. If graph modifications are required, consider an alternative type of hook (e.g., pre-import module
        hooks).
    c                 .    || _         || _        || _        y r	   )search_dirsr
   _module_name)r   r   r   r1   s       r   r   zPreFindModulePathAPI.__init__   s     ' *'r   c                     | j                   S r   r   r   s    r   r   z!PreFindModulePathAPI.module_graph   r   r   c                     | j                   S )z6
        Fully-qualified name of this module.
        )r2   r   s    r   r   z PreFindModulePathAPI.module_name   s    
    r   N)r(   r)   r*   r+   r   r,   r   r   r-   r   r   r/   r/      s5    'P( " " ! !r   r/   c                       e Zd ZdZd Zed        Zed        Zed        Z ed        Zed        Z	ed        Z
ed	        Zed
        Zed        Zd Zd Zd Zd Zd Zd Zy)PostGraphAPIai  
    Metadata communicating changes made by the current **post-graph hook** (i.e., hook run for a specific module
    transitively imported by the current application _after_ the module graph of all `import` statements performed by
    this application has been constructed) back to PyInstaller.

    Post-graph hooks may optionally define a `post_graph()` function accepting an instance of this class,
    whose attributes describe the current state of the module graph and the hooked module's graph node.

    Attributes (Mutable)
    ----------
    The following attributes are **mutable** (i.e., modifiable). All changes to these attributes will be immediately
    respected by PyInstaller:

    module_graph : PyiModuleGraph
        Current module graph.
    module : Node
        Graph node for the currently hooked module.

    'With great power comes great responsibility.'

    Attributes (Immutable)
    ----------
    The following attributes are **immutable** (i.e., read-only). For safety, any attempts to change these attributes
    _will_ result in a raised exception:

    __name__ : str
        Fully-qualified name of this module (e.g., `six.moves.tkinter`).
    __file__ : str
        Absolute path of this module. If this module is:
        * A standard (rather than namespace) package, this is the absolute path of this package's directory.
        * A namespace (rather than standard) package, this is the abstract placeholder `-`. (Don't ask. Don't tell.)
        * A non-package module or C extension, this is the absolute path of the corresponding file.
    __path__ : list
        List of the absolute paths of all directories comprising this package if this module is a package _or_ `None`
        otherwise. If this module is a standard (rather than namespace) package, this list contains only the absolute
        path of this package's directory.
    co : code
        Code object compiled from the contents of `__file__` (e.g., via the `compile()` builtin).
    analysis: build_main.Analysis
        The Analysis that load the hook.

    Attributes (Private)
    ----------
    The following attributes are technically mutable but private, and hence should _never_ be externally accessed or
    modified by hooks. Call the corresponding public methods instead:

    _added_datas : list
        List of the `(name, path)` 2-tuples or TOC objects of all external data files required by the current hook,
        defaulting to the empty list. This is equivalent to the global `datas` hook attribute.
    _added_imports : list
        List of the fully-qualified names of all modules imported by the current hook, defaulting to the empty list.
        This is equivalent to the global `hiddenimports` hook attribute.
    _added_binaries : list
        List of the `(name, path)` 2-tuples or TOC objects of all external C extensions imported by the current hook,
        defaulting to the empty list. This is equivalent to the global `binaries` hook attribute.
    _module_collection_mode : dict
        Dictionary of package/module names and their corresponding collection mode strings. This is equivalent to the
        global `module_collection_mode` hook attribute.
    _bindepend_symlink_suppression : set
        A set of paths or path patterns corresponding to shared libraries for which binary dependency analysis should
        not generate symbolic links into top-level application directory.
    c                    || _         |j                  |      | _        | j                  J || _        | j                  j                  | _        | j                  j                  | _        || _        | j                  j                  t        | j                  j                        nd | _        g | _        g | _        g | _        g | _        i | _        t#               | _        y r	   )r   	find_nodemodule	___name__filename	___file__code_co	_analysispackagepathtuple	___path___added_binaries_added_datas_added_imports_deleted_imports_module_collection_modeset_bindepend_symlink_suppression)r   r   r   analysiss       r   r   zPostGraphAPI.__init__9  s    (",,[9{{&&& %--;;##! {{&&2 t{{6678< 	  "  "')$.1e+r   c                     | j                   S )z6
        Absolute path of this module's file.
        )r<   r   s    r   __file__zPostGraphAPI.__file__U      
 ~~r   c                     | j                   S )a  
        List of the absolute paths of all directories comprising this package if this module is a package _or_ `None`
        otherwise. If this module is a standard (rather than namespace) package, this list contains only the absolute
        path of this package's directory.
        )rB   r   s    r   __path__zPostGraphAPI.__path__\       ~~r   c                     | j                   S )zR
        Fully-qualified name of this module (e.g., `six.moves.tkinter`).
        r:   r   s    r   r(   zPostGraphAPI.__name__e  rM   r   c                     | j                   S )zk
        Code object compiled from the contents of `__file__` (e.g., via the `compile()` builtin).
        )r>   r   s    r   cozPostGraphAPI.col  s    
 xxr   c                     | j                   S )z:
        build_main.Analysis that calls the hook.
        )r?   r   s    r   rJ   zPostGraphAPI.analysiss  rM   r   c                     | j                   S )z
        Fully-qualified name of this module (e.g., `six.moves.tkinter`).

        **This property has been deprecated by the `__name__` property.**
        rR   r   s    r   namezPostGraphAPI.name{  rP   r   c                     | j                   S )zv
        Current module graph.

        **This property has been deprecated by the `module_graph` property.**
        )r   r   s    r   graphzPostGraphAPI.graph  s        r   c                     | j                   S )z
        Graph node for the currently hooked module.

        **This property has been deprecated by the `module` property.**
        )r9   r   s    r   nodezPostGraphAPI.node  s     {{r   c                 N    | j                   j                  | j                        S )zZ
        List of the graph nodes of all modules directly imported by this module.
        )start)r   
iter_graphr9   r   s    r   importszPostGraphAPI.imports  s"    
   ++$+++>>r   c                 :    | j                   j                  |       y)a  
        Add all Python modules whose fully-qualified names are in the passed list as "hidden imports" upon which the
        current module depends.

        This is equivalent to appending such names to the hook-specific `hiddenimports` attribute.
        N)rE   extendr   module_namess     r   add_importszPostGraphAPI.add_imports  s     	""<0r   c                 :    | j                   j                  |       y)a  
        Remove the named fully-qualified modules from the set of imports (either hidden or visible) upon which the
        current module depends.

        This is equivalent to appending such names to the hook-specific `excludedimports` attribute.
        N)rF   ra   rb   s     r   del_importszPostGraphAPI.del_imports  s     	$$\2r   c                     |r4t        |d         dk(  r#| j                  j                  d |D               y| j                  j                  t        |             y)aU  
        Add all external dynamic libraries in the passed list of `(src_name, dest_name)` 2-tuples as dependencies of the
        current module. This is equivalent to adding to the global `binaries` hook attribute.

        For convenience, the `binaries` may also be a list of TOC-style 3-tuples `(dest_name, src_name, typecode)`.
        r      c              3   &   K   | ]	  }|d d   y wN   r-   .0entrys     r   	<genexpr>z,PostGraphAPI.add_binaries.<locals>.<genexpr>  s     'Hebq	'H   N)lenrC   ra   r   )r   binariess     r   add_binarieszPostGraphAPI.add_binaries  sM     HQK(A-  '''Hx'HH   ''(A((KLr   c                     |r4t        |d         dk(  r#| j                  j                  d |D               y| j                  j                  t        |             y)aH  
        Add all external data files in the passed list of `(src_name, dest_name)` 2-tuples as dependencies of the
        current module. This is equivalent to adding to the global `datas` hook attribute.

        For convenience, the `datas` may also be a list of TOC-style 3-tuples `(dest_name, src_name, typecode)`.
        r   rh   c              3   &   K   | ]	  }|d d   y wrj   r-   rl   s     r   ro   z)PostGraphAPI.add_datas.<locals>.<genexpr>  s     $B5U2AY$Brp   N)rq   rD   ra   r   )r   datass     r   	add_dataszPostGraphAPI.add_datas  sL     Sq]a'$$$BE$BB $$%>u%EFr   c                 z    || j                   }|| j                  j                  |       y|| j                  |<   y)ac  "
        Set the package/module collection mode for the specified module name. If `name` is `None`, the hooked
        module/package name is used. `mode` can be one of valid mode strings (`'pyz'`, `'pyc'`, `'py'`, `'pyz+py'`,
        `'py+pyz'`) or `None`, which clears the setting for the module/package - but only  within this hook's context!
        N)r(   rG   pop)r   rW   modes      r   set_module_collection_modez'PostGraphAPI.set_module_collection_mode  s;     <==D<((,,T215D((.r   c                 :    | j                   j                  |       y)z
        Add the given path or path pattern to the set of patterns that prevent binary dependency analysis from creating
        a symbolic link to the top-level application directory.
        N)rI   add)r   patterns     r   )add_bindepend_symlink_suppression_patternz6PostGraphAPI.add_bindepend_symlink_suppression_pattern  s    
 	++//8r   N)r(   r)   r*   r+   r   r,   rL   rO   rT   rJ   rW   rY   r[   r_   rd   rf   rs   rw   r{   r   r-   r   r   r6   r6      s    =|48             ! !   ? ?13M G 69r   r6   N)	r+   PyInstaller.building.utilsr   'PyInstaller.lib.modulegraph.modulegraphr   r   r   r/   r6   r-   r   r   <module>r      s;    A SYL YLxC! C!Ll9 l9r   