projet crepp_git/crepp-projects/feutrage-de-laine · branche main
pyimod01_archive.pyc Voir sur GitLab
o

�@s�ddlZddlZddlZddlZddlZdZdZdZdZ	dZ
Gdd�d�ZGdd	�d	�ZGd
d�de
�ZGdd
�d
�ZGdd�d�ZGdd�de�ZdS)�N����c@seZdZdZdd�ZdS)�FilePosz`
    This class keeps track of the file object representing and current position in a file.
    cCsd|_d|_dS)Nr)�file�pos��self�r�&PyInstaller/loader/pyimod01_archive.py�__init__-s
zFilePos.__init__N)�__name__�
__module__�__qualname__�__doc__r
rrrrr)src@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�ArchiveFilez~
    File class support auto open when access member from file object This class is use to avoid file locking on windows.
    cOs||_||_i|_dS)N)�args�kwargs�_filePos)r
rrrrrr
8s
zArchiveFile.__init__cCs(t��}||jvrt�|j|<|j|S)z�
        Return an instance of FilePos for the current thread. This is a crude # re-implementation of threading.local,
        which isn't a built-in module # and therefore isn't available.
        )�thread�	get_identrr)r
�tirrr�local=s

zArchiveFile.localcCs|��j}|s	J�t||�S)zj
        Make this class act like a file, by invoking most methods on its underlying file object.
        )rr�getattr)r
�namerrrr�__getattr__Gs

zArchiveFile.__getattr__cCs8|��}|jr	J�t|ji|j��|_|j�|j�dS)zC
        Open file and seek to pos record from last close.
        N)rr�openrr�seekr)r
�fprrr�	__enter__Os
zArchiveFile.__enter__cCs2|��}|js	J�|j��|_|j��d|_dS)z,
        Close file and record pos.
        N)rr�tellr�close)r
�type�value�	tracebackrrrr�__exit__Zs



zArchiveFile.__exit__N)	rrrrr
rrr r&rrrrr4s
rc@seZdZdS)�ArchiveReadErrorN)rrrrrrrr'hsr'c@sVeZdZdZdZdZdZdZdZddd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�ZdS)�
ArchiveReadera
    A base class for a repository of python code objects. The extract method is used by imputil.ArchiveImporter to
    get code objects by name (fully qualified name), so an end-user "import a.b" becomes:
        extract('a.__init__')
        extract('a.b')
    sPYL��NrcCszd|_||_||_ddl}|jj|_|dur;t|jd�|_|j�|�	�|�
�Wd�dS1s4wYdSdS)zY
        Initialize an Archive. If path is omitted, it will be an empty Archive.
        Nr�rb)�toc�path�start�_frozen_importlib�_bootstrap_external�MAGIC_NUMBER�pymagicr�lib�
checkmagic�loadtoc)r
r-r.r/rrrr
ys

"��zArchiveReader.__init__cCsV|j�|j|j�t�d|j�d��\}|j�|j|�tt�	|j����|_
dS)z�
        Overridable. Default: After magic comes an int (4 byte native) giving the position of the TOC within
        self.lib. Default: The TOC is a marshal-able string.
        z!i�N)r3rr.�TOCPOS�struct�unpack�read�dict�marshal�loadsr,)r
�offsetrrrr5�szArchiveReader.loadtoccCs&|j�|d�\}}|durdSt|�S)N�rN)r,�get�bool)r
r�ispkgrrrr�
is_package�szArchiveReader.is_packagecCst|j�|d�\}}|durdS|j�|j�|j|�t�|j���}Wd�||fS1s1wY||fS)a+
        Get the object corresponding to name, or None. For use with imputil ArchiveImporter, object is a python code
        object. 'name' is the name as specified in an 'import name'. 'import a.b' becomes:
             extract('a') (return None because 'a' is not a code object)
             extract('a.__init__') (return a code object)
             extract('a.b') (return a code object)
        Default implementation:
            self.toc is a dict
            self.toc[name] is pos
            self.lib has the code object marshal-ed at pos
        r?N)r,r@r3rr.r<r=r:)r
rrBr�objrrr�extract�s
��zArchiveReader.extractcCst|j���S)z�
        Return a list of the contents Default implementation assumes self.toc is a dict like object. Not required by
        ArchiveImporter.
        )�listr,�keysr	rrr�contents�szArchiveReader.contentscCsr|j�|j�|j�t|j��|jkrtd|j|jj	f��|j�t|j
��|j
kr1td|j��|j�d�dS)zj
        Overridable. Check to see if the file object self.lib actually has a file we understand.
        z!%s is not a valid %s archive filez%s has version mismatch to dllr6N)r3rr.r:�len�MAGICr'r-�	__class__rr2r	rrrr4�szArchiveReader.checkmagic)Nr)rrrrrJ�HDRLENr7�os�	_bincacher
r5rCrErHr4rrrrr(ls

r(c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�Cipherz<
    This class is used only to decrypt Python modules.
    cCsrddl}|j}t|�tusJ�t|�tkr|dt�|_n|�t�|_t|j�tks,J�ddl}||_t	j
d=dS)Nr�tinyaes)�pyimod00_crypto_key�keyr#�strrI�CRYPT_BLOCK_SIZE�zfillrP�_aesmod�sys�modules)r
rQrRrPrrrr
�szCipher.__init__cCs|j�|j��|�S)N)rV�AESrR�encode)r
�ivrrr�__create_cipher�szCipher.__create_ciphercCs$|�|dt��}|�|td��S)N)�_Cipher__create_cipherrT�CTR_xcrypt_buffer)r
�data�cipherrrr�decrypt�szCipher.decryptN)rrrrr
r]rarrrrrO�s
rOcsLeZdZdZdZdZejdZd�fdd�	Zdd	�Z	d
d�Z
dd
�Z�ZS)�ZlibArchiveReadera1
    ZlibArchive - an archive with compressed entries. Archive is read from the executable created by PyInstaller.

    This archive is used for bundling python modules inside the executable.

    NOTE: The whole ZlibArchive (PYZ) is compressed, so it is not necessary to compress individual modules.
    sPYZr*�Nc	s�|durd}n7|dur>tt|�ddd�D]&}||dkr;zt||dd��}Wn	ty2Yqw|d|�}nqd}t��||�zddl}t�|_WdSt	y]d|_YdSw)Nrr����?)
�rangerI�int�
ValueError�superr
rQrOr`�ImportError)r
r-r>�irQ�rKrrr
�s*��	�zZlibArchiveReader.__init__cCs,|j�|d�\}}}|durdS|ttfvS)N�rNr)r,r@�PYZ_TYPE_PKG�PYZ_TYPE_NSPKG�r
r�typr�lengthrrrrCszZlibArchiveReader.is_packagecCs(|j�|d�\}}}|durdS|tkS)Nrm)r,r@rorprrr�is_pep420_namespace_packagesz-ZlibArchiveReader.is_pep420_namespace_packagec
Cs�|j�|d�\}}}|durdSz$|j�|j�|j|�|j�|�}Wd�n1s.wYWntyCt|j�d���wz$|j	rN|j	�
|�}t�|�}|t
ttfvrdt�|�}W||fSW||fSty{}ztd|�|�d}~ww)Nrmz� appears to have been moved or deleted since this application was launched. Continouation from this state is impossible. Exiting now.z"PYZ entry '%s' failed to unmarshal)r,r@r3rr.r:�FileNotFoundError�
SystemExitr-r`ra�zlib�
decompress�PYZ_TYPE_MODULErnror<r=�EOFErrorrj)r
rrqrrrrD�errrrEs6��
��
����zZlibArchiveReader.extract)NN)
rrrrrJr7r(rLr
rCrsrE�
__classcell__rrrlrrb�s
rb)�_threadrr<r8rWrvrTrxrn�
PYZ_TYPE_DATArorr�RuntimeErrorr'r(rOrbrrrr�<module>s 4`!