Your IP : 18.191.68.112


Current Path : /opt/alt/python34/lib64/python3.4/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/__pycache__/dis.cpython-34.pyo

�
e fC�@s`dZddlZddlZddlZddlZddlTddlmZddddd	d
ddd
ddgeZ[ejej	ej
efZdd�Z
ddddd�Zddddd�Zidd6dd6dd6dd6dd6dd 6d!d"6Zd#d$�Zd%d&�Zd'd�Zd(d)�Zddd*d�Zejd+d,�ZGd-d�de�Zd.dd/d
�Zd0d1�Zd2d3�Zddddddd4d5�ZdBddd6d�ZdCdddddddd7dd8d9�Zddd:d;�ZeZ d<d�Z!d=d
�Z"Gd>d�d�Z#d?d@�Z$e%dAkr\e$�ndS)Dz0Disassembler of Python byte code into mnemonics.�N)�*)�__all__�	code_info�dis�disassemble�distb�disco�findlinestarts�
findlabels�	show_code�get_instructions�Instruction�BytecodecCsAyt||d�}Wn$tk
r<t||d�}YnX|S)z�Attempts to compile the given source, first as an expression and
       then as a statement if the first approach fails.

       Utility function to accept strings in functions that otherwise
       expect code objects
    �eval�exec)�compile�SyntaxError)�source�name�c�r�(/opt/alt/python34/lib64/python3.4/dis.py�_try_compiles

r�filecCs�|dkrtd|�dSt|d�r8|j}nt|d�rS|j}nt|d�rt|jj��}x|D]�\}}t|t�r~t	d|d|�yt
|d|�Wn8tk
r�}zt	d|d|�WYdd}~XnXt	d|�q~q~Wn�t|d�r5t|d|�nct|t
tf�r]t|d|�n;t|t�rt|d|�ntd	t|�j��dS)
znDisassemble classes, methods, functions, or code.

    With no argument, disassemble the last traceback.

    Nr�__func__�__code__�__dict__zDisassembly of %s:zSorry:�co_codez(don't know how to disassemble %s objects)r�hasattrrr�sortedr�items�
isinstance�
_have_code�printr�	TypeErrorr�bytes�	bytearray�_disassemble_bytes�str�_disassemble_str�type�__name__)�xrr rZx1�msgrrrrs2
&c
Csv|dkrVy
tj}Wntk
r9td��YnXx|jrR|j}q=Wnt|jj|jd|�dS)z2Disassemble a traceback (default: last traceback).Nz no last traceback to disassembler)	�sys�last_traceback�AttributeError�RuntimeError�tb_nextr�tb_frame�f_code�tb_lasti)�tbrrrrr@s

Z	OPTIMIZED�Z	NEWLOCALS�ZVARARGS�ZVARKEYWORDS�ZNESTED�Z	GENERATOR� ZNOFREE�@cCs�g}xqtd�D]P}d|>}||@r|jtj|t|���||N}|scPqcqqW|jt|��dj|�S)z+Return pretty representation of code flags.r<r7z, )�range�append�COMPILER_FLAG_NAMES�get�hex�join)�flags�names�iZflagrrr�pretty_flagsWs


rGcCs�t|d�r|j}nt|d�r6|j}nt|t�rWt|d�}nt|d�rj|Stdt|�j��dS)zAHelper to handle methods, functions, strings and raw code objectsrrz
<disassembly>rz(don't know how to disassemble %s objectsN)	rrrr!r(rr$r*r+)r,rrr�_get_code_objectesrHcCstt|��S)z1Formatted details of methods, functions, or code.)�_format_code_inforH)r,rrrrrscCs�g}|jd|j�|jd|j�|jd|j�|jd|j�|jd|j�|jd|j�|jdt|j��|j	r�|jd�x+t
|j	�D]}|jd	|�q�Wn|jr |jd
�x+t
|j�D]}|jd|�qWn|jrd|jd�x+t
|j�D]}|jd|�qFWn|j
r�|jd
�x+t
|j
�D]}|jd|�q�Wn|jr�|jd�x+t
|j�D]}|jd|�q�Wndj|�S)NzName:              %szFilename:          %szArgument count:    %szKw-only arguments: %szNumber of locals:  %szStack size:        %szFlags:             %sz
Constants:z%4d: %rzNames:z%4d: %szVariable names:zFree variables:zCell variables:�
)r?�co_name�co_filename�co_argcount�co_kwonlyargcount�
co_nlocals�co_stacksizerG�co_flags�	co_consts�	enumerate�co_names�co_varnames�co_freevars�co_cellvarsrC)�co�linesZi_cZi_nrrrrIvs:	
	
	
	
	
rIcCstt|�d|�dS)z}Print details of methods, functions, or code to *file*.

    If *file* is not provided, the output is printed on stdout.
    rN)r#r)rXrrrrr�s�_InstructionzBopname opcode arg argval argrepr offset starts_line is_jump_targetc@s(eZdZdZdddd�ZdS)r
aKDetails for a bytecode operation

       Defined fields:
         opname - human readable name for operation
         opcode - numeric code for operation
         arg - numeric argument to operation (if any), otherwise None
         argval - resolved arg value (if known), otherwise same as arg
         argrepr - human readable description of operation argument
         offset - start index of operation within bytecode sequence
         starts_line - line started by this opcode (if any), otherwise None
         is_jump_target - True if other code jumps to here, otherwise False
    �FcCs9g}|rP|jdk	r<d|}|j||j�qP|jd|�n|rf|jd�n
|jd�|jr�|jd�n
|jd�|jt|j�jd��|j|jjd	��|jdk	r&|jt|j�jd
��|j	r&|jd|j	d�q&ndj
|�j�S)
z�Format instruction details for inclusion in disassembly output

        *lineno_width* sets the width of the line number field (0 omits it)
        *mark_as_current* inserts a '-->' marker arrow as part of the line
        Nz%%%dd� z-->z   z>>z  r9���(�))�starts_liner?�is_jump_target�repr�offset�rjust�opname�ljust�arg�argreprrC�rstrip)�self�lineno_widthZmark_as_currentZfieldsZ
lineno_fmtrrr�_disassemble�s&

	
	zInstruction._disassembleN)r+�
__module__�__qualname__�__doc__rmrrrrr
�s�
first_linecCsxt|�}|j|j}tt|��}|dk	rJ||j}nd}t|j|j|j	|j
|||�S)a�Iterator for the opcodes in methods, functions or code

    Generates a series of Instruction named tuples giving the details of
    each operations in the supplied code.

    If *first_line* is not None, it indicates the line number that should
    be reported for the first source line in the disassembled code.
    Otherwise, the source line information (if any) is taken directly from
    the disassembled code object.
    Nr)rHrWrV�dictr	�co_firstlineno�_get_instructions_bytesrrUrTrR)r,rqrX�
cell_names�
linestarts�line_offsetrrrr�scCs/|}|dk	r||}n|t|�fS)z�Helper to get optional details about const references

       Returns the dereferenced constant and its repr if the constant
       list is defined.
       Otherwise returns the constant index and its repr().
    N)rc)Zconst_indexZ
const_list�argvalrrr�_get_const_info�s
rycCs;|}|dk	r%||}|}nt|�}||fS)z�Helper to get optional details about named references

       Returns the dereferenced name as both value and repr if the name
       list is defined.
       Otherwise returns the name index and its repr().
    N)rc)Z
name_indexZ	name_listrxrirrr�_get_name_info�s
	rzc	cs@t|�}d}d}	d}
t|�}d}x	||kr;||}
|}|dk	r�|j|d�}	|	dk	r�|	|7}	q�n||k}|d}d}d}d}|
tkr||||dd|}d}|d}|
tkr|d}n|}|
tkr.t||�\}}q|
tkrRt||�\}}q|
t	kr{||}dt
|�}q|
tkr�t||�\}}q|
tkr�t
|}|}q|
tkr�t||�\}}q|
tkrd	||d||df}qntt|
|
|||||	|�Vq3WdS)
a&Iterate over the instructions in a bytecode string.

    Generates a sequence of Instruction namedtuples giving the details of each
    opcode.  Additional information about the code's runtime environment
    (e.g. variable names, constants) can be specified using optional
    arguments.

    rNr7��r8izto z%d positional, %d keyword pair)r
�lenrA�
HAVE_ARGUMENTZEXTENDED_ARGZhasconstryZhasnamerz�hasjrelrcZhaslocalZ
hascompareZcmp_opZhasfreeZhasnargsr
rf)�code�varnamesrE�	constants�cellsrvrw�labelsZextended_argraZfree�nrF�oprdrbrhrxrirrrrtsX






	&
	rtc
CsT|j|j}tt|��}t|j||j|j|j||d|�dS)zDisassemble a code object.rN)	rWrVrrr	r'rrUrTrR)rX�lastirrurvrrrrAsrwc	Cs�|dk	}	|	rdnd}
x�t||||||d|�D]k}|	og|jdk	og|jdk}|r�td|�n|j|k}
t|j|
|
�d|�q@WdS)Nr[rrwr)rtrardr#rm)r�r�r�rEr�r�rvrrwZshow_linenorlZinstrZnew_source_lineZis_current_instrrrrr'Hs
r'cCstt|d�d|�dS)z<Compile the source string, then disassemble the code object.z<dis>rN)rr)rrrrrr)Zsr)cCs�g}t|�}d}x�||kr�||}|d}|tkr||||dd}|d}d}|tkr�||}n|tkr�|}n|dkr�||kr�|j|�q�q�qqW|S)z`Detect all offsets in a byte code which are jump targets.

    Return the list of offsets.

    rr7r|r8���)r}r~rZhasjabsr?)r�r�r�rFr�rhZlabelrrrr
`s$



	ccs�t|jddd��}t|jddd��}d}|j}d}xZt||�D]I\}}|r�||kr�||fV|}n||7}n||7}q]W||kr�||fVndS)z�Find the offsets in a byte code which are start of lines in the source.

    Generate pairs (offset, lineno) as described in Python/compile.c.

    rNr8r7)�list�	co_lnotabrs�zip)r�Zbyte_incrementsZline_incrementsZ
lastlineno�linenoZaddrZ	byte_incrZ	line_incrrrrr	{s		
c@speZdZdZdddddd�Zdd�Zd	d
�Zedd��Zd
d�Z	dd�Z
dS)rz�The bytecode operations of a piece of code

    Instantiate this with a function, method, string of code, or a code object
    (as returned by compile()).

    Iterating over this yields the bytecode operations as Instruction instances.
    rqN�current_offsetcCs�t|�|_}|dkr7|j|_d|_n||_||j|_|j|j|_tt	|��|_
||_||_dS)Nr)
rH�codeobjrsrq�_line_offsetrWrV�_cell_namesrrr	�_linestarts�_original_objectr�)rkr,rqr�rXrrr�__init__�s		zBytecode.__init__c	Cs=|j}t|j|j|j|j|j|jd|j�S)Nrw)	r�rtrrUrTrRr�r�r�)rkrXrrr�__iter__�s
		zBytecode.__iter__cCsdj|jj|j�S)Nz{}({!r}))�format�	__class__r+r�)rkrrr�__repr__�szBytecode.__repr__cCs2x|jr|j}qW||jjd|j�S)z/ Construct a Bytecode from the given traceback r�)r2r3r4r5)�clsr6rrr�from_traceback�s
zBytecode.from_tracebackcCs
t|j�S)z3Return formatted information about the code object.)rIr�)rkrrr�info�sz
Bytecode.infocCs�|j}|jdk	r$|j}nd}tj��`}t|jd|jd|jd|jd|j	d|j
d|jd	|d
|�|j�SWdQXdS)z3Return a formatted view of the bytecode operations.Nr7r�rEr�r�rvrwrr�r�)
r�r��io�StringIOr'rrUrTrRr�r�r��getvalue)rkrXrd�outputrrrr�s				zBytecode.dis)r+rnrorpr�r�r��classmethodr�r�rrrrrr�s
c
Cs�ddl}|j�}|jdd|j�dddd�|j�}|j�}|j�}WdQXt||jjd	�}t	|�dS)
z*Simple test program to disassemble a file.rN�infiler*�nargs�?�default�-r)
�argparse�ArgumentParser�add_argumentZFileType�
parse_argsr��readrrr)r��parser�argsr�rr�rrr�_test�s%r��__main__r�r�)&rpr.�types�collectionsr�ZopcoderZ_opcodes_all�
MethodType�FunctionType�CodeTyper*r"rrrr@rGrHrrIr�
namedtuplerZr
rryrzrtrr'r)rr
r	rr�r+rrrr�<module>s^
	
!


		3	<	=

?>