
    	^c                         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dS )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 fdZ xZS )_lazyloaderexzaThis is a LazyLoader except it also follows the _deactivated global and
    the ignore list.
    c                    t          j        d|          5  t          s|j        t          v r| j                            |           n!t                                          |           ddd           dS # 1 swxY w Y   dS )zMake the module load lazily.zdemandimport %sN)r   log_deactivated__name__ignoresloaderexec_modulesuper)selfmodule	__class__s     @/usr/lib/python3/dist-packages/hgdemandimport/demandimportpy3.pyr   z_lazyloaderex.exec_module*   s    [*F33 	, 	, ,v'99''////##F+++		, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,s   AA66A:=A:)r
   
__module____qualname____doc__r   __classcell__)r   s   @r   r   r   %   sB         , , , , , , , , ,    r   c                   F    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d	S )
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                 >    t                               | d|           d S Nr   )object__setattr__)r   finders     r   __init__zLazyFinder.__init__D   s     4F33333r   c                 >    dt                               | d          z  S )Nz<LazyFinder for %r>r   )r   __getattribute__r   s    r   __repr__zLazyFinder.__repr__G   s    $v'>'>tY'O'OOOr   c                 R    t          t                              | d                    S r   )boolr   r"   r#   s    r   __nonzero__zLazyFinder.__nonzero__L   s     F++D)<<===r   c                     |dv rt                               | |          S t          t                               | d          |          S )N)r   	find_specr   )r   r"   getattrr   names     r   r"   zLazyFinder.__getattribute__Q   sD    +++**4666v..tY??FFFr   c                 T    t          t                              | d          |          S r   )delattrr   r"   r+   s     r   __delattr__zLazyFinder.__delattr__W   s"    v..tY??FFFr   c                 V    t          t                              | d          ||          S r   )setattrr   r"   )r   r,   values      r   r   zLazyFinder.__setattr__Z   s$    v..tY??uMMMr   Nc                 n   t                               | d          }	 |j        } ||||          }nK# t          $ r> |                    ||          }|d }n t
          j                            ||          }Y nw xY w|6|j        /t          |j        dd           rt          |j                  |_        |S )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_spec]   s    ((y99		5(I 9XtV44DD  	I 	I 	I''$77F~ ~66xHH	I ']D99 ( (44DKs   2 AA:9A:N)r
   r   r   r   	__slots__r    r$   r'   __bool__r"   r/   r   r)    r   r   r   r   3   s          I4 4 4P P P
> > > HG G GG G GN N N     r   r   c                 
    | a d S r=   )r   )	ignoresets    r   initrC   x   s    GGGr   c                  X    t            o"t          d t          j        D                       S )Nc              3   @   K   | ]}t          |t                    V  d S r=   )
isinstancer   ).0r   s     r   	<genexpr>zisenabled.<locals>.<genexpr>~   s=       $ $+1
6:&&$ $ $ $ $ $r   )r	   anysys	meta_pathr@   r   r   	isenabledrL   }   s<      $ $58]$ $ $ ! ! r   c                      g } t           j        D ]3}|                     t          |t                    r|j        n|           4| t           j        d d <   d S r=   )rJ   rK   appendrF   r   r   new_findersr   s     r   disablerQ      se    K- 
 
(<<HFNN&	
 	
 	
 	
 #CM!!!r   c                      g } t           j        D ];}|                     t          |t                    st	          |          n|           <| t           j        d d <   d S r=   )rJ   rK   rN   rF   r   rO   s     r   enablerS      sl    K- 
 
&0&D&DPJv&	
 	
 	
 	
 #CM!!!r   c               #   V   K   t                      } | rda	 d V  | rdad S d S # | rdaw xY w)NTF)rL   r	   )demandenableds    r   deactivatedrV      s`      $ KKM ! 	! LLL	! 	!= 	! L    s   " ()r   
contextlibimportlib.utilr6   rJ    r   r	   r7   
LazyLoaderr   r   setr   rC   rL   rQ   rS   contextmanagerrV   r@   r   r   <module>r]      s   (         



      , , , , ,IN- , , ,? ? ? ? ? ? ? ?D #%%  
  # # ## # # ! ! ! ! !r   