3
^G                 @   sx   d dl Z d dlZd dlZd dlmZmZmZ d dlmZm	Z	m
Z
 d dlmZ dd Zdd Zd	d
 Zdd Zdd ZdS )    N)MAGICPYTHON_MAGIC_INT	int2magic)PYTHON3PYTHON_VERSIONIS_PYPY)load_modulec             C   s   t rb| jt|d@ g | jt|d? d@ g | jt|d? d@ g | jt|d? d@ g nT| jt|d@  | jt|d? d@  | jt|d? d@  | jt|d? d@  dS )z>Internal; write a 32-bit int to a file in little-endian order.            N)r   writebyteschr)fx r   H/home/psgendb/BIRCHDEV/python/lib/python3.6/site-packages/xdis/verify.pywr_long   s    r   c             C   s   d|t |f }d}zy|t|d}tr>|jtddddg n
|jd t|| tj| | |j  |j	dd |j| |j
  tj|| W n: tk
r   ytj| W n tk
r   Y nX  Y nX W d|r|j
  X dS )zWrite code object as a byte-compiled file

    Arguments:
    codeobject: code object
    filefile: bytecode file to write
    timestamp: timestamp to put in file
    magic: Pyton bytecode magic
    z%s.%sNwbr   z    )idopenr   r   r   r   marshaldumpflushseekcloseosrenameOSErrorunlink)Z
codeobjectfilename	timestampmagicpath_tmpZfcr   r   r   dump_compile%   s,    



r%   c             C   s   | j |j ks td| j |j f | j|jks0t| j| jks@t| j|jksPt| j|jks`t| j|jkspt| j|jkst| j|jkst| j	|j	kst| j
|j
kst| j|jkst| j|jkstd S )Nzcode %s vs. %s)co_codeAssertionErrorco_argcount	co_constsco_filenameco_firstlinenoco_flags	co_lnotabco_nameco_names
co_nlocalsco_stacksizeco_varnames)c1Zc2r   r   r   compare_codeJ   s     r4   c             C   s   t | d}|j }|j t |d}|j }|j tdkrvtrv|dd  |dd  kstd|dd  |dd  f n||kstd||f d S )Nrbg	@   zbytecode:
%s
vs
%s)r   readr   r   r   r'   )Zbc_file1Zbc_file2r   Zbytes1Zbytes2r   r   r   compare_bytecode_files]   s    


r8   c             C   s@  t j }tjj|d}tjj| s&dS tdk r:t| d}n>tdkrFdS dt  koXdkn  rjt| d}nt| ddd	}|j }|j	  t
||d
}t|\}}}	}
}}}|	dkrd}	tt|	kstd|	ttj |f tjj|d}t|||t t|| d\}}}	}}}}tjj|d}t|||t|	 t|| dS )a  Compile *real_source_filename* using
    the running Python interpreter. Then
    write bytecode out to a new place again using
    Python's routines.

    Next load it in using two of our routines.
    Compare that the code objects there are equal.

    Next write out the bytecode (using the same Python
    bytecode writin routine as in step 1.

    Finally compare the bytecode files.
    z
testing.pyNg      @Ug@g333333@r5   backslashreplace)newlineerrorsexecil     0   zmagic_int %d vs %d in %s/%sztesting1.pyc)Z	fast_loadztesting2.pycis  )tempfile
gettempdirr   pathjoinexistsr   r   r7   r   compiler   r   r   r'   r   getcwdr%   r8   )Zreal_source_filenameZreal_bytecode_filenametempdirZsource_filenamer   Z
codestringZcodeobject1versionr"   Z	magic_intZcodeobject2Zis_pypysource_size_Zbytecode_filename1Zcodeobject3Zbytecode_filename2r   r   r   verify_filep   s<    


rK   )r   r   r@   Zxdis.magicsr   r   r   Zxdis.version_infor   r   r   Z	xdis.loadr   r   r%   r4   r8   rK   r   r   r   r   <module>   s   %