3
/*^C                 @   sz   d Z ddlmZ ddlZddlmZ ddlmZmZm	Z	 ddl
mZ ddd	Zd
d ZdddZdd Zedkrve  dS )a  
CPython magic- and version- independent disassembly routines

There are two reasons we can't use Python's built-in routines
from dis. First, the bytecode we are extracting may be from a different
version of Python (different magic number) than the version of Python
that is doing the extraction.

Second, we need structured instruction information for the
(de)-parsing step. Python 3.4 and up provides this, but we still do
want to run on earlier Python versions.
    )print_functionN)deque)check_object_pathiscodeload_module)get_scannerFc             C   sf   t |st|ptj}td|  |d |jr>td|j |d t| |d}t|g}t|j	|| dS )z:
    diassembles and deparses a given code block 'co'
    z# Python %s)filez# Embedded file name: %s)is_pypyN)
r   AssertionErrorsysstdoutprintco_filenamer   r   
disco_loopZingest)versioncooutr	   real_outscannerqueue r   M/home/psgendb/BIRCHDEV/python/lib/python3.6/site-packages/uncompyle6/disas.pydisco)   s    

r   c             C   s   xt |dkr|j }|jdkr<td|j|j|jf |d | |\}}xF|D ]>}t|jrj|j|j nt|j	r|j|j	 t||d qNW qW d S )Nr   z<module>z
# %s line %d of %s)r   )
lenpopleftco_namer   co_firstlinenor   r   Zpattrappendattr)Zdisasmr   r   r   tokensZ	customizetr   r   r   r   <   s     



r   c       
      C   s^   t | } t| \}}}}}}}t|tkrFx*|D ]}	t||	| q0W nt||||d d}dS )z
    disassemble Python byte-code file (.pyc)

    If given a Python source file (".py") file, we'll
    try to find the corresponding compiled object.
    )r	   N)r   r   typelistr   )
filenameZ	outstreamr   	timestampZ	magic_intr   r	   source_sizeZsip_hashZconr   r   r   disassemble_file^   s    
r&   c              C   sR   t tj} | dkr<| dkr t}qFtjjdt  tjd n
tjd }t| dS )z*Simple test program to disassemble a file.      z$usage: %s [-|CPython compiled file]
N)r   r   argv__file__stderrwriteexitr&   )Zargcfnr   r   r   _testq   s    

r/   __main__)NF)N)__doc__
__future__r   r   collectionsr   Zxdisr   r   r   Zuncompyle6.scannerr   r   r   r&   r/   __name__r   r   r   r   <module>   s   
"
