
                                  d dl Z d dlZd dlZd dlZd dlZej
                  j                  Zd ZdZ	dZ
dZ G d de      Z G d d      Zy)	    N         c                       e Zd Zy)ArchiveReadErrorN)__name__
__module____qualname__     pyimod01_archive.pyr   r   #   s    r   r   c                   4    e Zd ZdZdZddZed        ZddZy)	ZlibArchiveReaderz
    Reader for PyInstaller's PYZ (ZlibArchive) archive. The archive is used to store collected byte-compiled Python
    modules, as individually-compressed entries.
    s   PYZ Nc                    || _         || _        i | _        || j                  |      \  | _         | _        t	        | j                   d      5 }|j                  | j                  t        j                         |j                  t        | j                              }|| j                  k7  rt        d      |j                  t        t                    }|r|t        k7  rt        d      t        j                  d|j                  d            ^}}|j                  | j                  |z   t        j                         t        t!        j"                  |            | _        d d d        y # 1 sw Y   y xY w)NrbzPYZ magic pattern mismatch!zPython magic pattern mismatch!z!i   )	_filename_start_offsettoc_parse_offset_from_filenameopenseekosSEEK_SETreadlen_PYZ_MAGIC_PATTERNr   PYTHON_MAGIC_NUMBERstructunpackdictmarshalload)	selffilenamestart_offsetcheck_pymagicfpmagicpymagic
toc_offset_s	            r   __init__zZlibArchiveReader.__init__.   s,   !) 151Q1QRZ1[.DND.
 $..$' 	.2GGD&&4GGC 7 789E///&'DEE ggc"567G,?!?&'GHH $]]4<NJ GGD&&3R[[AGLL,-DH%	. 	. 	.s   DE))E2c                     d}| j                  d      }|dk(  r| |fS 	 t        | |dz   d       }| d| } | |fS # t        $ r Y | |fS w xY w)z\
        Parse the numeric offset from filename, stored as: `/path/to/file?offset`.
        r   ?r   N)rfindint
ValueError)r%   offsetidxs      r   r   z-ZlibArchiveReader._parse_offset_from_filenameO   sz    
 nnS!"9V##	#'(+,F~H
 	  			s   8 	AAc                 8   | j                   j                  |      }|t        d|d      |\  }}}|t        k(  ry	 t	        | j
                  d      5 }|j                  | j                  |z          |j                  |      }ddd       	 t        j                        }|t        t        fv r|st        j                   |      }|S # 1 sw Y   FxY w# t        $ r t        d| j
                   d      w xY w# t"        $ r}	t%        d|d      |	d}	~	ww xY w)	z
        Extract data from entry with the given name.

        If the entry belongs to a module or a package, the data is loaded (unmarshaled) into code object. To retrieve
        raw data, set `raw` flag to True.
        NzNo entry named z found in the archive!r   zERROR: z appears to have been moved or deleted since this application was launched. Continouation from this state is impossible. Exiting now.zFailed to unmarshal PYZ entry !)r   getKeyErrorPYZ_ITEM_NSPKGr   r   r   r   r   FileNotFoundError
SystemExitzlib
decompressPYZ_ITEM_MODULEPYZ_ITEM_PKGr"   loadsEOFErrorImportError)
r$   namerawentrytypecodeentry_offsetentry_lengthr(   objes
             r   extractzZlibArchiveReader.extractc   s1    T"=_TH4JKLL/4,, ~%	dnnd+ ,r**\9:ggl+,	Q//#&CO\::3mmC( 
+, , ! 		 $..) *L L 		  	Q >thaHIqP	Qs;   C 0C	C :C; 	CC #C8;	DDD)NF)F)	r   r	   r
   __doc__r   r-   staticmethodr   rL   r   r   r   r   r   '   s.     ".B    &)r   r   )r   r   r"   r=   _frozen_importlib_bootstrap_externalMAGIC_NUMBERr   r?   r@   PYZ_ITEM_DATAr:   RuntimeErrorr   r   r   r   r   <module>rT      sX   " 
    ';;HH  	| 	e er   