U
    ad-x                     @   sR  d Z ddlZddlmZmZ ddlZddlZddlZddl	Z	ddl
Z
ddlZddgZejZejdd ZG dd deZi Zee
ZdZd	Zd
ZG dd dZed ddfed ddfddfZdd Zdd Zdd Zdd ZdZdadd Z dd Z!dd  Z"d!d" Z#ee#j$Z%d#d$ Z&d%d& Z'd'd( Z(d)d* Z)d+d, Z*d-d. Z+G d/d0 d0Z,dS )1aP  zipimport provides support for importing Python modules from Zip archives.

This module exports three objects:
- zipimporter: a class; its constructor takes a path to a Zip archive.
- ZipImportError: exception raised by zipimporter objects. It's a
  subclass of ImportError, so it can be caught as ImportError, too.
- _zip_directory_cache: a dict, mapping archive paths to zip directory
  info dicts, as used in zipimporter._files.

It is usually not needed to use the zipimport module explicitly; it is
used by the builtin import mechanism for sys.path items that are paths
to Zip archives.
    N)_unpack_uint16_unpack_uint32ZipImportErrorzipimporter   c                   @   s   e Zd ZdS )r   N)__name__
__module____qualname__ r
   r
   /usr/lib/python3.8/zipimport.pyr   !   s      s   PKi  c                   @   sl   e Zd ZdZdd ZdddZdddZd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd ZdS )r   a  zipimporter(archivepath) -> zipimporter object

    Create a new zipimporter instance. 'archivepath' must be a path to
    a zipfile, or to a specific path inside a zipfile. For example, it can be
    '/tmp/myimport.zip', or '/tmp/myimport.zip/mydirectory', if mydirectory is a
    valid directory inside the archive.

    'ZipImportError is raised if 'archivepath' doesn't point to a valid Zip
    archive.

    The 'archive' attribute of zipimporter objects contains the name of the
    zipfile targeted.
    c              	   C   s$  t |tsdd l}||}|s,td|dtr<|tt}g }zt	|}W nH t
tfk
r   t|\}}||krtd|d|}|| Y q@X |jd@ dkrtd|dqq@zt| }W n$ tk
r   t|}|t|< Y nX || _|| _tj|d d d  | _| jr |  jt7  _d S )Nr   zarchive path is emptypathznot a Zip filei   i   )
isinstancestrosfsdecoder   alt_path_sepreplacepath_sep_bootstrap_external
_path_statOSError
ValueError_path_splitappendst_mode_zip_directory_cacheKeyError_read_directory_filesarchive
_path_joinprefix)selfr   r   r$   stdirnamebasenamefilesr
   r
   r   __init__?   s:    

zzipimporter.__init__Nc                 C   sN   t | |}|dk	r| g fS t| |}t| |rFd| j t | gfS dg fS )a  find_loader(fullname, path=None) -> self, str or None.

        Search for a module specified by 'fullname'. 'fullname' must be the
        fully qualified (dotted) module name. It returns the zipimporter
        instance itself if the module was found, a string containing the
        full path name if it's possibly a portion of a namespace package,
        or None otherwise. The optional 'path' argument is ignored -- it's
        there for compatibility with the importer protocol.
        N)_get_module_info_get_module_path_is_dirr"   r   )r%   fullnamer   mimodpathr
   r
   r   find_loaderm   s    



zzipimporter.find_loaderc                 C   s   |  ||d S )a  find_module(fullname, path=None) -> self or None.

        Search for a module specified by 'fullname'. 'fullname' must be the
        fully qualified (dotted) module name. It returns the zipimporter
        instance itself if the module was found, or None if it wasn't.
        The optional 'path' argument is ignored -- it's there for compatibility
        with the importer protocol.
        r   )r1   )r%   r.   r   r
   r
   r   find_module   s    	zzipimporter.find_modulec                 C   s   t | |\}}}|S )zget_code(fullname) -> code object.

        Return the code object for the specified module. Raise ZipImportError
        if the module couldn't be found.
        _get_module_coder%   r.   code	ispackager0   r
   r
   r   get_code   s    zzipimporter.get_codec                 C   sv   t r|t t}|}|| jt r:|t| jt d }z| j| }W n  tk
rh   tdd|Y nX t	| j|S )zget_data(pathname) -> string with file data.

        Return the data associated with 'pathname'. Raise OSError if
        the file wasn't found.
        Nr    )
r   r   r   
startswithr"   lenr!   r   r   	_get_data)r%   pathnamekey	toc_entryr
   r
   r   get_data   s    zzipimporter.get_datac                 C   s   t | |\}}}|S )zjget_filename(fullname) -> filename string.

        Return the filename for the specified module.
        r3   r5   r
   r
   r   get_filename   s    zzipimporter.get_filenamec                 C   s   t | |}|dkr$td||dt| |}|r@t|d}n
| d}z| j| }W n tk
rn   Y dS X t| j|	 S )zget_source(fullname) -> source string.

        Return the source code for the specified module. Raise ZipImportError
        if the module couldn't be found, return None if the archive does
        contain the module, but has no source for it.
        Ncan't find module name__init__.py.py)
r+   r   r,   r   r#   r!   r   r<   r"   decode)r%   r.   r/   r   fullpathr?   r
   r
   r   
get_source   s    


zzipimporter.get_sourcec                 C   s(   t | |}|dkr$td||d|S )zis_package(fullname) -> bool.

        Return True if the module specified by fullname is a package.
        Raise ZipImportError if the module couldn't be found.
        NrB   rC   )r+   r   )r%   r.   r/   r
   r
   r   
is_package   s    
zzipimporter.is_packagec                 C   s   t | |\}}}tj|}|dks.t|ts@t|}|tj|< | |_zT|rlt| |}t	| j
|}|g|_t|ds|t|_t|j|| t||j W n   tj|=  Y nX ztj| }W n$ tk
r   td|dY nX td|| |S )zload_module(fullname) -> module.

        Load the module specified by 'fullname'. 'fullname' must be the
        fully qualified (dotted) module name. It returns the imported
        module, or raises ZipImportError if it wasn't found.
        N__builtins__zLoaded module z not found in sys.moduleszimport {} # loaded from Zip {})r4   sysmodulesgetr   _module_type
__loader__r,   r   r#   r"   __path__hasattrrK   _fix_up_module__dict__execr   ImportError
_bootstrap_verbose_message)r%   r.   r6   r7   r0   modr   rH   r
   r
   r   load_module   s0    


zzipimporter.load_modulec                 C   sX   z|  |sW dS W n tk
r*   Y dS X tjsNddlm} |t dt_t| |S )zReturn the ResourceReader for a package in a zip file.

        If 'fullname' is a package within the zip file, return the
        'ResourceReader' object for the package.  Otherwise return None.
        Nr   )ResourceReaderT)rJ   r   _ZipImportResourceReader_registeredimportlib.abcr[   register)r%   r.   r[   r
   r
   r   get_resource_reader  s    


zzipimporter.get_resource_readerc                 C   s   d| j  t | j dS )Nz<zipimporter object "z">)r"   r   r$   )r%   r
   r
   r   __repr__"  s    zzipimporter.__repr__)N)N)r   r   r	   __doc__r*   r1   r2   r8   r@   rA   rI   rJ   rZ   r`   ra   r
   r
   r
   r   r   -   s   .
 

&z__init__.pycTrE   F)z.pycTF)rF   FFc                 C   s   | j |dd  S )N.   )r$   
rpartition)r%   r.   r
   r
   r   r,   4  s    r,   c                 C   s   |t  }|| jkS N)r   r!   )r%   r   dirpathr
   r
   r   r-   8  s    r-   c                 C   s8   t | |}tD ]$\}}}|| }|| jkr|  S qd S rf   )r,   _zip_searchorderr!   )r%   r.   r   suffix
isbytecoder7   rH   r
   r
   r   r+   A  s    


r+   c              	   C   s  zt | }W n& tk
r4   td| | dY nX | z$|t d | }|t}W n& tk
r   td| | dY nX t|tkrtd| | d|d d t	krz|dd | }W n& tk
r   td| | dY nX t
|t t d}z|| | }W n( tk
rJ   td| | dY nX |t	}|dk rrtd| | d|||t  }t|tkrtd| | d|t| | }t|d	d
 }t|d
d }	||k rtd| | d||	k r
td| | d||8 }||	 }
|
dk r6td| | di }d}z|| W n( tk
rt   td| | dY nX |d}t|dk rtd|d d dkrqt|dkrtdt|dd }t|dd	 }t|d	d }t|dd
 }t|d
d }t|dd }t|dd }t|dd }t|dd }t|dd }t|dd }|| | }||	krtd| | d||
7 }z||}W n( tk
r   td| | dY nX t||krtd| | dz2t||| || kr*td| | dW n( tk
rT   td| | dY nX |d@ rj| }n6z|d}W n& tk
r   |dt}Y nX |dt}t| |}||||||||f}|||< |d 7 }qvW 5 Q R X td!||  |S )"Nzcan't open Zip file: r   rd   can't read Zip file:    r   znot a Zip file: zcorrupt Zip file:          zbad central directory size: zbad central directory offset: z&bad central directory size or offset: .   EOF read where not expecteds   PK   
                   "   *   zbad local header offset: i   asciilatin1/r   z!zipimport: found {} names in {!r})_io	open_coder   r   seekEND_CENTRAL_DIR_SIZEtellreadr;   STRING_END_ARCHIVEmaxMAX_COMMENT_LENrfindr   EOFErrorr   rG   UnicodeDecodeError	translatecp437_tabler   r   r   r#   rW   rX   )r"   fpheader_positionbuffer	file_sizemax_comment_startdataposheader_sizeheader_offset
arc_offsetr)   countflagscompresstimedatecrc	data_size	name_size
extra_sizecomment_sizefile_offsetrD   r   tr
   r
   r   r    `  s    













r    u   	
 !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñÑªº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■ c                  C   sl   t rtd tdda z<zddlm}  W n& tk
rR   td tdY nX W 5 da X td | S )Nzzipimport: zlib UNAVAILABLE)can't decompress data; zlib not availableTFr   
decompresszzipimport: zlib available)_importing_zlibrW   rX   r   zlibr   	Exceptionr   r
   r
   r   _get_decompress_func  s    


r   c              	   C   s  |\}}}}}}}}	|dk r$t dt| }
z|
| W n& tk
rf   t d| | dY nX |
d}t|dkrtd|d d dkrt d	| | dt|d
d }t|dd }d| | }||7 }z|
| W n( tk
r   t d| | dY nX |
|}t||kr4tdW 5 Q R X |dkrL|S z
t	 }W n t
k
rt   t dY nX ||dS )Nr   znegative data sizerk   r   rw   rq   rl   s   PKzbad local file header:    rv   zzipimport: can't read datar   i)r   r~   r   r   r   r   r;   r   r   r   r   )r"   r?   datapathr   r   r   r   r   r   r   r   r   r   r   r   raw_datar   r
   r
   r   r<     s>    



r<   c                 C   s   t | | dkS )Nr   )abs)t1t2r
   r
   r   	_eq_mtimeA  s    r   c                 C   s<  ||d}zt |||}W n tk
r2   Y d S X |d@ dk}|r|d@ dk}tjdkr|shtjdkrt| |}	|	d k	rtt j|	}
zt ||
|| W n tk
r   Y d S X nTt	| |\}}|r
t
t|dd |rt|dd	 |kr
td
| d S t|d	d  }t|ts8td|d|S )N)rD   r   r   r   rd   neveralwaysrr   rm   rn   zbytecode is stale for zcompiled module z is not a code object)r   _classify_pycrV   _impcheck_hash_based_pycs_get_pyc_sourcesource_hash_RAW_MAGIC_NUMBER_validate_hash_pyc_get_mtime_and_size_of_sourcer   r   rW   rX   marshalloadsr   
_code_type	TypeError)r%   r=   rH   r.   r   exc_detailsr   
hash_basedcheck_sourcesource_bytesr   source_mtimesource_sizer6   r
   r
   r   _unmarshal_codeK  sX    

   
r   c                 C   s   |  dd} |  dd} | S )Ns   
   
   )r   )sourcer
   r
   r   _normalize_line_endings~  s    r   c                 C   s   t |}t|| dddS )NrU   T)dont_inherit)r   compile)r=   r   r
   r
   r   _compile_source  s    r   c                 C   sD   t | d? d | d? d@ | d@ |d? |d? d@ |d@ d d	d	d	f	S )
N	   i              ?   rd   r   )r   mktime)dr   r
   r
   r   _parse_dostime  s    



  r   c              
   C   st   zR|dd  dkst |d d }| j| }|d }|d }|d }t|||fW S  tttfk
rn   Y dS X d S )Nr   cor         )r   r   )AssertionErrorr!   r   r   
IndexErrorr   )r%   r   r?   r   r   uncompressed_sizer
   r
   r   r     s    
r   c                 C   sV   |dd  dkst |d d }z| j| }W n tk
rD   Y d S X t| j|S d S )Nr   r   )r   r!   r   r<   r"   )r%   r   r?   r
   r
   r   r     s    r   c              	   C   s   t | |}tD ]\}}}|| }tjd| jt|dd z| j| }W n tk
rX   Y qX |d }t| j|}	|rt	| ||||	}
n
t
||	}
|
d krq|d }|
||f  S qtd||dd S )Nztrying {}{}{}rd   )	verbosityr   rB   rC   )r,   rh   rW   rX   r"   r   r!   r   r<   r   r   r   )r%   r.   r   ri   rj   r7   rH   r?   r0   r   r6   r
   r
   r   r4     s$    

r4   c                   @   s<   e Zd ZdZdZdd Zdd Zdd Zd	d
 Zdd Z	dS )r\   zPrivate class used to support ZipImport.get_resource_reader().

    This class is allowed to reference all the innards and private parts of
    the zipimporter.
    Fc                 C   s   || _ || _d S rf   )r   r.   )r%   r   r.   r
   r
   r   r*     s    z!_ZipImportResourceReader.__init__c                 C   s\   | j dd}| d| }ddlm} z|| j|W S  tk
rV   t|Y nX d S )Nrc   r}   r   )BytesIO)r.   r   ior   r   r@   r   FileNotFoundError)r%   resourcefullname_as_pathr   r   r
   r
   r   open_resource  s    z&_ZipImportResourceReader.open_resourcec                 C   s   t d S rf   )r   )r%   r   r
   r
   r   resource_path  s    z&_ZipImportResourceReader.resource_pathc                 C   sH   | j dd}| d| }z| j| W n tk
rB   Y dS X dS )Nrc   r}   FT)r.   r   r   r@   r   )r%   rD   r   r   r
   r
   r   is_resource  s    z$_ZipImportResourceReader.is_resourcec           	   	   c   s   ddl m} || j| j}|| jj}|jdks:t|j	}t
 }| jjD ]f}z|||}W n tk
r|   Y qNY nX |j	j}t|dkr|jV  qN||krN|| |V  qNd S )Nr   )PathrE   )pathlibr   r   rA   r.   relative_tor"   rD   r   parentsetr!   r   r;   add)	r%   r   fullname_pathrelative_pathpackage_pathsubdirs_seenfilenamerelativeparent_namer
   r
   r   contents  s"    


z!_ZipImportResourceReader.contentsN)
r   r   r	   rb   r]   r*   r   r   r   r   r
   r
   r
   r   r\     s   	r\   )-rb   _frozen_importlib_externalr   r   r   _frozen_importlibrW   r   r~   r   rL   r   __all__r   path_separatorsr   rV   r   r   typerO   r   r   r   r   rh   r,   r-   r+   r    r   r   r   r<   r   r   __code__r   r   r   r   r   r   r4   r\   r
   r
   r
   r   <module>   sX     		~.
.
