
    q&fK                         d Z ddlZddlZddlZddlmZ da G d dej                  j                        Z
 G d d	      Z e       ad
 Zd Zd Zd Zej$                  d        Zy)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.
    N   )tracingFc                   &     e Zd ZdZdZ fdZ xZS )_lazyloaderexzaThis is a LazyLoader except it also follows the _deactivated global and
    the ignore list.
    Tc                 :   t        j                  d|      5  t        s|j                  t        v rH| j
                  |j                  _        | j
                  |_        | j
                  j                  |       nt        | !  |       ddd       y# 1 sw Y   yxY w)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   z_lazyloaderex.exec_module*   sp    [[*F3 	,v'9)-&$(KK!''/#F+	, 	, 	,s   A0BB)r
   
__module____qualname____doc___HAS_DYNAMIC_ATTRIBUTESr   __classcell__)r   s   @r   r   r   #   s     #
, 
,    r   c                   D    e Zd ZdZdZd Zd Zd ZeZd Z	d Z
d Zdd
Zy	)
LazyFindera2  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    t         j                  | d|       y Nr   )object__setattr__)r   finders     r   __init__zLazyFinder.__init__H   s    4F3r   c                 4    dt         j                  | d      z  S )Nz<LazyFinder for %r>r   )r    __getattribute__r   s    r   __repr__zLazyFinder.__repr__K   s    $v'>'>tY'OOOr   c                 @    t        t        j                  | d            S r   )boolr    r%   r&   s    r   __nonzero__zLazyFinder.__nonzero__P   s    F++D)<==r   c                 v    |dv rt         j                  | |      S t        t         j                  | d      |      S )N)r   	find_specr   )r    r%   getattrr   names     r   r%   zLazyFinder.__getattribute__U   s8    ++**466v..tY?FFr   c                 B    t        t        j                  | d      |      S r   )delattrr    r%   r.   s     r   __delattr__zLazyFinder.__delattr__[   s    v..tY?FFr   c                 D    t        t        j                  | d      ||      S r   )setattrr    r%   )r   r/   values      r   r!   zLazyFinder.__setattr__^   s    v..tY?uMMr   Nc                 j   t         j                  | d      }	 |j                  } ||||      }|=|j                  1t        |j                  dd       rt        |j                        |_        |S # t        $ r: |j	                  ||      }|d }n t
        j                  j                  ||      }Y w xY w)Nr   r   )r    r%   r,   AttributeErrorfind_module	importlibutilspec_from_loaderr   r-   r   )r   fullnamepathtargetr"   r,   specr   s           r   r,   zLazyFinder.find_speca   s    ((y9		5((I XtV4D ']D9'4DK#  	I''$7F~ ~~66xH	Is   A/ /A B21B2N)r
   r   r   r   	__slots__r#   r'   r*   __bool__r%   r2   r!   r,    r   r   r   r   7   s<     I4P
> HGGNr   r   c                     | a y r@   )r   )	ignoresets    r   initrF   |   s    Gr   c                  T    t          xr  t        d t        j                  D              S )Nc              3   <   K   | ]  }t        |t                y wr@   )
isinstancer   ).0r"   s     r   	<genexpr>zisenabled.<locals>.<genexpr>   s      $+1
6:&$s   )r	   anysys	meta_pathrC   r   r   	isenabledrO      s*      $58]]$ ! r   c                      g } t         j                  D ]/  }| j                  t        |t              r|j
                  n|       1 | t         j                  d d  y r@   )rM   rN   appendrI   r   r   new_findersr"   s     r   disablerT      sJ    K-- 
(<FNN&	

 #CMM!r   c                      g } t         j                  D ].  }| j                  t        |t              st	        |      n|       0 | t         j                  d d  y r@   )rM   rN   rQ   rI   r   rR   s     r   enablerV      sK    K-- 
&0&DJv&	

 #CMM!r   c               #   P   K   t               } | rda	 d  | rday y # | rdaw w xY ww)NTF)rO   r	   )demandenableds    r   deactivatedrY      s9     $ KM! L = L s   & &#&)r   
contextlibimportlib.utilr9   rM    r   r	   r:   
LazyLoaderr   r   setr   rF   rO   rT   rV   contextmanagerrY   rC   r   r   <module>r`      su   $   
 ,INN-- ,(? ?D %
## ! !r   