
    6ho                        S r SSKJr  SSKrSSKrSSKrSSKJr  Sq	 " S S\R                  R                  5      r " S	 S
5      r\" 5       qS rS rS rS r\R(                  S 5       rg)a  Lazy loading for Python 3.6 and above.

This uses the new importlib finder/loader functionality available in Python 3.5
and up. The code reuses most of the mechanics implemented inside importlib.util,
but with a few additions:

* Allow excluding certain modules from lazy imports.
* Expose an interface that's substantially the same as demandimport for
  Python 2.

This also has some limitations compared to the Python 2 implementation:

* Much of the logic is per-package, not per-module, so any packages loaded
  before demandimport is enabled will not be lazily imported in the future. In
  practice, we only expect builtins to be loaded before demandimport is
  enabled.
    )annotationsN   )tracingFc                  0   ^  \ rS rSrSrSrU 4S jrSrU =r$ )_lazyloaderex%   zYThis is a LazyLoader except it also follows the _deactivated global and
the ignore list.
Tc                T  > [         R                  " SU5         [        (       d  UR                  [        ;   aH  U R
                  UR                  l        U R
                  Ul        U R
                  R                  U5        O[        TU ]!  U5        SSS5        g! , (       d  f       g= f)zMake the module load lazily.zdemandimport %sN)
r   log_deactivated__name__ignoresloader__spec__
__loader__exec_modulesuper)selfmodule	__class__s     @/usr/lib/python3/dist-packages/hgdemandimport/demandimportpy3.pyr   _lazyloaderex.exec_module,   si    [[*F3|v'9)-&$(KK!''/#F+ 433s   A7B
B' )	r   
__module____qualname____firstlineno____doc___HAS_DYNAMIC_ATTRIBUTESr   __static_attributes____classcell__)r   s   @r   r   r   %   s     #
, 
,    r   c                  N    \ rS rSrSrSrS rS rS r\r	S r
S rS	 rSS jrSrg
)
LazyFinder9   a  A wrapper around a ``MetaPathFinder`` that makes loaders lazy.

``sys.meta_path`` finders have their ``find_spec()`` called to locate a
module. This returns a ``ModuleSpec`` if found or ``None``. The
``ModuleSpec`` has a ``loader`` attribute, which is called to actually
load a module.

Our class wraps an existing finder and overloads its ``find_spec()`` to
replace the ``loader`` with our lazy loader proxy.

We have to use __getattribute__ to proxy the instance because some meta
path finders don't support monkeypatching.
)_finderc                2    [         R                  U SU5        g Nr$   )object__setattr__)r   finders     r   __init__LazyFinder.__init__J   s    4F3r    c                4    S[         R                  U S5      -  $ )Nz<LazyFinder for %r>r$   )r'   __getattribute__r   s    r   __repr__LazyFinder.__repr__M   s    $v'>'>tY'OOOr    c                @    [        [        R                  U S5      5      $ r&   )boolr'   r-   r.   s    r   __nonzero__LazyFinder.__nonzero__R   s    F++D)<==r    c                x    US;   a  [         R                  X5      $ [        [         R                  U S5      U5      $ )N)r$   	find_specr$   )r'   r-   getattrr   names     r   r-   LazyFinder.__getattribute__W   s6    ++**466v..tY?FFr    c                B    [        [        R                  U S5      U5      $ r&   )delattrr'   r-   r8   s     r   __delattr__LazyFinder.__delattr__]   s    v..tY?FFr    c                B    [        [        R                  U S5      X5      $ r&   )setattrr'   r-   )r   r9   values      r   r(   LazyFinder.__setattr__`   s    v..tY?MMr    Nc                x   [         R                  U S5      n UR                  nU" XU5      nUbC  UR                  b6  [        UR                  SS 5      (       a  [        UR                  5      Ul        U$ ! [         a:    UR	                  X5      nUc  S n Nj[
        R                  R                  X5      n Nf = f)Nr$   r   )r'   r-   r6   AttributeErrorfind_module	importlibutilspec_from_loaderr   r7   r   )r   fullnamepathtargetr)   r6   specr   s           r   r6   LazyFinder.find_specc   s    ((y9		5((I XV4D ']D99'4DK#  	I''7F~ ~~66xH	Is   A5 5 B9B98B9r   N)r   r   r   r   r   	__slots__r*   r/   r3   __bool__r-   r=   r(   r6   r   r   r    r   r"   r"   9   s<     I4P
> HGGNr    r"   c                    U q g rN   )r   )	ignoresets    r   initrS   ~   s    Gr    c                 f    [         (       + =(       a     [        S [        R                   5       5      $ )Nc              3  B   #    U  H  n[        U[        5      v   M     g 7frN   )
isinstancer"   ).0r)   s     r   	<genexpr>isenabled.<locals>.<genexpr>   s      $5B6
6:&&]s   )r   anysys	meta_pathr   r    r   	isenabledr]      s*      $58]]$ ! r    c                     / n [         R                   H5  nU R                  [        U[        5      (       a  UR
                  OU5        M7     U [         R                  S S & g rN   )r[   r\   appendrV   r"   r$   new_findersr)   s     r   disablerb      sH    K--(<<FNN&	
   #CMM!r    c                     / n [         R                   H4  nU R                  [        U[        5      (       d  [	        U5      OU5        M6     U [         R                  S S & g rN   )r[   r\   r_   rV   r"   r`   s     r   enablerd      sI    K--&0&D&DJv&	
   #CMM!r    c               #  n   #    [        5       n U (       a  Sq S v   U (       a  Sqg g ! U (       a  Sqf f = f7f)NTF)r]   r   )demandenableds    r   deactivatedrg      s8     $ KM! L = L s   5& 525)r   
__future__r   
contextlibimportlib.utilrF   r[    r   r   rG   
LazyLoaderr   r"   setr   rS   r]   rb   rd   contextmanagerrg   r   r    r   <module>ro      sx   $ #   
 ,INN-- ,(? ?D %
## ! !r    