
    ik                        S r SSKrSSKrSSKrSSKrSSKrSSKJr	  SSK
Jr  SSKJr  SSKJr  SSKJr  \	R$                  " \5      r " S S	\5      rS
 rS r\\4\\4\S4\S4S \4\\4\\4S.r " S S5      r " S S5      rg)z-
Code related to processing of import hooks.
    N)log)format_binaries_and_datas)importlib_load_source)PostGraphAPI)ImportErrorWhenRunningHookc                   >   ^  \ rS rSrSrSr U 4S jrS rS rSr	U =r
$ )ModuleHookCache   a  
Cache of lazily loadable hook script objects.

This cache is implemented as a `dict` subclass mapping from the fully-qualified names of all modules with at
least one hook script to lists of `ModuleHook` instances encapsulating these scripts. As a `dict` subclass,
all cached module names and hook scripts are accessible via standard dictionary operations.

Attributes
----------
module_graph : ModuleGraph
    Current module graph.
_hook_module_name_prefix : str
    String prefixing the names of all in-memory modules lazily loaded from cached hook scripts. See also the
    `hook_module_name_prefix` parameter passed to the `ModuleHook.__init__()` method.
r   c                    > [         TU ]  5         [        R                  " U5      U l        SR                  [        R                  5      U l        [        =R                  S-  sl        U R                  U5        g)ai  
Cache all hook scripts in the passed directories.

**Order of caching is significant** with respect to hooks for the same module, as the values of this
dictionary are lists. Hooks for the same module will be run in the order in which they are cached. Previously
cached hooks are always preserved rather than overridden.

By default, official hooks are cached _before_ user-defined hooks. For modules with both official and
user-defined hooks, this implies that the former take priority over and hence will be loaded _before_ the
latter.

Parameters
----------
module_graph : ModuleGraph
    Current module graph.
hook_dirs : list
    List of the absolute or relative paths of all directories containing **hook scripts** (i.e.,
    Python scripts with filenames matching `hook-{module_name}.py`, where `{module_name}` is the module
    hooked by that script) to be cached.
z__PyInstaller_hooks_{}_   N)
super__init__weakrefproxymodule_graphformatr	   _cache_id_next_hook_module_name_prefix_cache_hook_dirs)selfr   	hook_dirs	__class__s      GC:\des-py\RoboSAPF\venv\Lib\site-packages\PyInstaller\depend\imphook.pyr   ModuleHookCache.__init__8   s`    * 	
 $MM,7 )B(H(HIgIg(h%&&!+& 	i(    c           
         U GH  u  p#[         R                  R                  U5      n[         R                  R                  U5      (       d  [	        SR                  U5      5      e[        R                  " [         R                  R                  US5      5      nU Hi  n[         R                  R                  U5      SS n[        U R                  UUU R                  US9nU R                  U/ 5      nUR                  U5        Mk     GM	     U R                  5        H2  nX   n	[        U	5      S:X  a	  U	S   X'   M  [!        U	S S	S
9n
U
S   X'   M4     g)z
Cache all hook scripts in the passed directories.

Parameters
----------
hook_dirs : list
    List of the absolute or relative paths of all directories containing hook scripts to be cached.
zHook directory "{}" not found.z	hook-*.py   )r   module_namehook_filenamehook_module_name_prefixdefault_priorityr   r   c                     U R                   $ N)priority)hooks    r   <lambda>2ModuleHookCache._cache_hook_dirs.<locals>.<lambda>   s    dmmr   T)keyreverseN)ospathabspathisdirFileNotFoundErrorr   globjoinbasename
ModuleHookr   r   
setdefaultappendkeyslensorted)r   r   hook_dirr"   hook_filenamesr    r   module_hookmodule_hookshookssorted_hookss              r   r    ModuleHookCache._cache_hook_dirs\   s*    +4&Hwwx0H77==**'(H(O(OPX(YZZ "YYrww||Hk'JKN!/ !gg..}=aC )!%!2!2 +"/,0,I,I%5  ${B?##K0! "0 +48  99;K%E5zQ$)!H!  &e1KUYZ$0O! 'r   c                     U HD  nU R                  US5      nUc  M  [        R                  R                  UR                  S5        MF     g)z
Remove the passed modules and all hook scripts cached for these modules from this cache.

Parameters
----------
module_names : list
    List of all fully-qualified module names to be removed.
N)popsysmoduleshook_module_name)r   module_namesr   r;   s       r   remove_modulesModuleHookCache.remove_modules   s>     (K ((;5K& < <dC (r   )r   r   )__name__
__module____qualname____firstlineno____doc__r   r   r   rF   __static_attributes____classcell__r   s   @r   r	   r	      s,      N")H-4^D Dr   r	   c                     [        U [        5      (       a  U $ [        U [        5      (       a  S U 0$ [        SU < 35      e)Nz.Invalid module collection mode setting value: )
isinstancedictstr
ValueErrorvalues    r   !_module_collection_mode_sanitizerrW      s>    %	E3		e}
EeYO
PPr   c                     [        U [        [        45      (       a  [        U 5      $ [        U [        5      (       a  [        U /5      $ [	        SU < 35      e)Nz1Invalid value for bindepend_symlink_suppression: )rQ   listsetrS   rT   rU   s    r   (_bindepend_symlink_suppression_sanitizerr[      sI    %$%%5z	E3		E7|
H	R
SSr   c                      g)NT r]   r   r   r'   r'      s    dr   )datasbinariesexcludedimportshiddenimportswarn_on_missing_hiddenimportsmodule_collection_modebindepend_symlink_suppressionc                   Z   ^  \ rS rSrSrS rS rU 4S jrS rSS jr	S r
S	 rS
 rSrU =r$ )r3      aI  
Cached object encapsulating a lazy loadable hook script.

This object exposes public attributes (e.g., `datas`) of the underlying hook script as attributes of the same
name of this object. On the first access of any such attribute, this hook script is lazily loaded into an
in-memory private module reused on subsequent accesses. These dynamic attributes are referred to as "magic." All
other static attributes of this object (e.g., `hook_module_name`) are referred to as "non-magic."

Attributes (Magic)
----------
datas : set
    Set of `TOC`-style 2-tuples `(target_file, source_file)` for all external non-executable files required by
    the module being hooked, converted from the `datas` list of hook-style 2-tuples `(source_dir_or_glob,
    target_dir)` defined by this hook script.
binaries : set
    Set of `TOC`-style 2-tuples `(target_file, source_file)` for all external executable files required by the
    module being hooked, converted from the `binaries` list of hook-style 2-tuples `(source_dir_or_glob,
    target_dir)` defined by this hook script.
excludedimports : set
    Set of the fully-qualified names of all modules imported by the module being hooked to be ignored rather than
    imported from that module, converted from the `excludedimports` list defined by this hook script. These
    modules will only be "locally" rather than "globally" ignored. These modules will remain importable from all
    modules other than the module being hooked.
hiddenimports : set
    Set of the fully-qualified names of all modules imported by the module being hooked that are _not_
    automatically detectable by PyInstaller (usually due to being dynamically imported in that module),
    converted from the `hiddenimports` list defined by this hook script.
warn_on_missing_hiddenimports : bool
    Boolean flag indicating whether missing hidden imports from the hook should generate warnings or not. This
    behavior is enabled by default, but individual hooks can opt out of it.
module_collection_mode : dict
    A dictionary of package/module names and their corresponding collection mode strings ('pyz', 'pyc', 'py',
    'pyz+py', 'py+pyz').
bindepend_symlink_suppression : set
    A set of paths or path patterns corresponding to shared libraries for which binary dependency analysis should
    not create symbolic links into top-level application directory.

Attributes (Non-magic)
----------
module_graph : ModuleGraph
    Current module graph.
module_name : str
    Name of the module hooked by this hook script.
hook_filename : str
    Absolute or relative path of this hook script.
hook_module_name : str
    Name of the in-memory module of this hook script's interpreted contents.
_hook_module : module
    In-memory module of this hook script's interpreted contents, lazily loaded on the first call to the
    `_load_hook_module()` method _or_ `None` if this method has yet to be accessed.
_default_priority : int
    Default (location-based) priority for this hook.
priority : int
    Actual priority for this hook. Might be different from `_default_priority` if hook file specifies the hook
    priority override.
c                     [        U[        R                  5      (       d   eXl        X l        X0l        XPl        X@R                  R                  SS5      -   U l        SU l	        SU l
        SU l        g)a  
Initialize this metadata.

Parameters
----------
module_graph : ModuleGraph
    Current module graph.
module_name : str
    Name of the module hooked by this hook script.
hook_filename : str
    Absolute or relative path of this hook script.
hook_module_name_prefix : str
    String prefixing the name of the in-memory module for this hook script. To avoid namespace clashes with
    similar modules created by other `ModuleHook` objects in other `ModuleHookCache` containers, this string
    _must_ be unique to the `ModuleHookCache` container containing this `ModuleHook` object. If this string
    is non-unique, an existing in-memory module will be erroneously reused when lazily loading this hook
    script, thus erroneously resanitizing previously sanitized hook script attributes (e.g., `datas`) with
    the `format_binaries_and_datas()` helper.
default_priority : int
    Default, location-based priority for this hook. Used to select active hook when multiple hooks are defined
    for the same module.
._FN)rQ   r   
ProxyTypesr   r   r    _default_priorityreplacerD   _loaded_has_hook_function_hook_module)r   r   r   r    r!   r"   s         r   r   ModuleHook.__init__  sr    2 ,(:(:;;;;(&* "2 !8:J:J:R:RSVX[:\ \ "' r   c                     US:X  a  U R                  5         [        X5      $ U[        ;   a,  U R                  (       d  U R	                  5         [        X5      $ [        U5      e)a  
Get the magic attribute with the passed name (e.g., `datas`) from this lazily loaded hook script if any _or_
raise `AttributeError` otherwise.

This special method is called only for attributes _not_ already defined by this object. This includes
undefined attributes and the first attempt to access magic attributes.

This special method is _not_ called for subsequent attempts to access magic attributes. The first attempt to
access magic attributes defines corresponding instance variables accessible via the `self.__dict__` instance
dictionary (e.g., as `self.datas`) without calling this method. This approach also allows magic attributes to
be deleted from this object _without_ defining the `__delattr__()` special method.

See Also
----------
Class docstring for supported magic attributes.
r%   )_load_hook_metadatagetattr_MAGIC_MODULE_HOOK_ATTRSrm   _load_hook_moduleAttributeError)r   	attr_names     r   __getattr__ModuleHook.__getattr__?  sV    $ 
"$$&4++00""$4++ !++r   c                 V   > U[         ;   a  U R                  5         [        TU ]  X5      $ )am  
Set the attribute with the passed name to the passed value.

If this is a magic attribute, this hook script will be lazily loaded before setting this attribute. Unlike
`__getattr__()`, this special method is called to set _any_ attribute -- including magic, non-magic,
and undefined attributes.

See Also
----------
Class docstring for supported magic attributes.
)rt   ru   r   __setattr__)r   rw   
attr_valuer   s      r   r{   ModuleHook.__setattr__]  s,     00""$ w"999r   c           	         U R                   U l        [        R                  " S5      n[	        U R
                  SSS9 nU HA  nUR                  U5      nUc  M   [        UR                  S5      5      U l          SSS5        g   SSS5        g! [         a'    [        R                  SUR                  S5      SS	9   NEf = f! , (       d  f       g= f)
z*
Load hook metadata from its source file.
z7^\s*#\s*\$PyInstaller-Hook-Priority:\s*(?P<value>[\S]+)rzutf-8)encodingNrV   z/Failed to parse hook priority value string: %r!Texc_info)rk   r%   recompileopenr    matchintgroup	Exceptionloggerwarning)r   priority_patternflinems        r   rr   ModuleHook._load_hook_metadatau  s     .. ::&`a$$$cG<$**40=(+AGGG,<(=  =< =< % MqwwW^O_jn '  =<s5   CB9CC.B?<C>B??C
Cc           
      V   U R                   (       a  U R                  c  U(       d  g[        R                  R	                  U R
                  5      u  p#[        R                  SX25         [        U R                  U R
                  5      U l        SU l         [        U R                  S5      U l        [        R!                  5        HA  u  nu  pV[#        U R                  US5      nUc  U" 5       nOUb  U" U5      n[%        XU5        MC     [%        U S[#        U S5      R!                  5        VV	s0 s H  u  pUb  UOU R&                  U	_M     sn	n5        U(       d  SU l        gg! [         a5    [        R                  SSS9  [        U R                  U R
                  5      ef = fs  sn	nf )am  
Lazily load this hook script into an in-memory private module.

This method (and, indeed, this class) preserves all attributes and functions defined by this hook script as
is, ensuring sane behaviour in hook functions _not_ expecting unplanned external modification. Instead,
this method copies public attributes defined by this hook script (e.g., `binaries`) into private attributes
of this object, which the special `__getattr__()` and `__setattr__()` methods safely expose to external
callers. For public attributes _not_ defined by this hook script, the corresponding private attributes will
be assigned sane defaults. For some public attributes defined by this hook script, the corresponding private
attributes will be transformed into objects more readily and safely consumed elsewhere by external callers.

See Also
----------
Class docstring for supported attributes.
Nz*Processing standard module hook %r from %rHook failed with:Tr   r&   rc   )rm   ro   r+   r,   splitr    r   infor   rD   ImportErrordebugr   hasattrrn   rt   itemsrs   setattrr   )
r   keep_module_ref	hook_pathhook_basenamerw   default_typesanitizer_funcr|   r)   rV   s
             r   ru   ModuleHook._load_hook_module  s   $ <<T..:/ $&77==1C1C#D 	@-[	X 5d6K6KTM_M_ `D  #*$*;*;V"D :R9W9W9Y5I5 !2!2ItDJ !)^
++J7
 DZ0 :Z  	*")$0H"I"O"O"Q-"QJC D,<,<eC"Q-	
  $D K  	XLL,tL<,T-B-BDDVDVWW	X:-s   )%E# -F%#?F"c                     U R                   (       a  U R                  (       a   U R                  SS9  U R                  U5        U R	                  5         g)a  
Call the **post-graph hook** (i.e., `hook()` function) defined by this hook script, if any.

Parameters
----------
analysis: build_main.Analysis
    Analysis that calls the hook

This method is intended to be called _after_ the module graph for this application is constructed.
T)r   N)rm   rn   ru   _process_hook_func_process_hidden_imports)r   analysiss     r   
post_graphModuleHook.post_graph  sB     ||t66""4"8 ##H- 	$$&r   c                 >   [        U R                  S5      (       d  g[        U R                  U R                  US9n U R                  R                  U5        U R                  R                  [        UR                  5      5        U R                   R                  [        UR"                  5      5        U R$                  R'                  UR(                  5        U R*                  R                  UR,                  5        U R.                  R                  UR0                  5        UR2                   H)  nU R                  R5                  UR6                  U5        M+     g! [         a5    [        R                  SSS9  [        U R                  U R                  5      ef = f)z
Call this hook's `hook()` function if defined.

Parameters
----------
analysis: build_main.Analysis
    Analysis that calls the hook
r&   N)r   r   r   r   Tr   )r   ro   r   r   r   r&   r   r   r   r   rD   r    r^   updaterZ   _added_datasr_   _added_binariesra   extend_added_importsrc   _module_collection_moderd   _bindepend_symlink_suppression_deleted_importsremoveReferencenode)r   r   hook_apideleted_module_names       r   r   ModuleHook._process_hook_func  sH    t((&11  D,<,<4K\K\gop	X""8, 	

#h3345S!9!9:;!!("9"9:##**8+K+KL**11(2Y2YZ $,#<#< --hmm=PQ $=!  	XLL,tL<,T-B-BDDVDVWW	Xs   E ?Fc                     U R                    HC  n U R                  R                  U R                  SS9nU R                  R	                  X5        ME     g! [
         a.    U R                  (       a  [        R                  SU5         M|   M  f = f)a	  
Add all imports listed in this hook script's `hiddenimports` attribute to the module graph as if directly
imported by this hooked module.

These imports are typically _not_ implicitly detectable by PyInstaller and hence must be explicitly defined
by hook scripts.
F)create_nspkgzHidden import "%s" not found!N)	ra   r   	find_noder   import_hookr   rb   r   r   )r   import_module_namecallers      r   r   "ModuleHook._process_hidden_imports  s     #'"4"4
X**44T5E5ETY4Z !!--.@I #5  X55NN#BDVW 6Xs   ?A1BB)	rk   rn   ro   rm   r    rD   r   r   r%   )F)rH   rI   rJ   rK   rL   r   rx   r{   rr   ru   r   r   r   rM   rN   rO   s   @r   r3   r3      s=    7v'!R,<:0.A%J'4%RNX Xr   r3   c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
AdditionalFilesCachei*  zi
Cache for storing what binaries and datas were pushed by what modules when import hooks were processed.
c                      0 U l         0 U l        g r$   	_binaries_datas)r   s    r   r   AdditionalFilesCache.__init__.  s    r   c                    U R                   R                  U/ 5        U R                   U   R                  U=(       d    / 5        U R                  R                  U/ 5        U R                  U   R                  U=(       d    / 5        g r$   )r   r4   r   r   )r   modnamer_   r^   s       r   addAdditionalFilesCache.add2  s`    !!'2.w&&x~26w+G##EKR0r   c                 H    XR                   ;   =(       d    XR                  ;   $ r$   r   )r   names     r   __contains__!AdditionalFilesCache.__contains__9  s    ~~%<)<<r   c                 :    U R                   R                  U/ 5      $ )z0
Return list of binaries for given module name.
)r   getr   r   s     r   r_   AdditionalFilesCache.binaries<  s     ~~!!'2..r   c                 :    U R                   R                  U/ 5      $ )z-
Return list of datas for given module name.
)r   r   r   s     r   r^   AdditionalFilesCache.datasB  s     {{w++r   r   N)rH   rI   rJ   rK   rL   r   r   r   r_   r^   rM   r]   r   r   r   r   *  s     1=/,r   r   )rL   r0   os.pathr+   rB   r   r   PyInstallerr   loggingPyInstaller.building.utilsr   PyInstaller.compatr   PyInstaller.depend.imphookapir   PyInstaller.exceptionsr   	getLoggerrH   r   rR   r	   rW   r[   rZ   rY   boolrt   r3   r   r]   r   r   <module>r      s      
  	 & @ 4 6 =			8	$}Dd }D@QT6 ,-/0T{ D\ '3D%9  $%FG '*+S%T1 8MX MX`
, ,r   