add-determinism 0.7.3

RPM buildroot helper to strip nondeterministic bits in files
Documentation
B

�/g^�Mc@s�dZddlZddlZddlZddlZddlTddlmZddddd	d
ddd
ddgeZ[ejej	ej
eee
fZedZdd�ZdPddd�dd�ZdQdd�dd�Zdddddddddd d!�
Zd"d#�Zd$d%�Zd&d�Zd'd(�Zdd�d)d�Ze�d*d+�Zd,ej_d-ej_d.ej_d/ej_d0ej_d1ej _d2ej!_d3ej"_d4Z#d5Z$Gd6d�de�Z%dd7�d8d
�Z&d9d:�Z'd;d<�Z(dRd=d>�Z)dSdd�d@d�Z*ddd�dAdB�Z+dTdddC�dDdE�Z,dFdG�Z-e*Z.dHdI�Z/dJd�Z0dKd
�Z1GdLd�d�Z2dMdN�Z3e4dOk�r�e3�dS)Uz0Disassembler of Python byte code into mnemonics.�N)Z*)�__all__�	code_info�dis�disassemble�distb�disco�findlinestarts�
findlabels�	show_code�get_instructions�Instruction�Bytecode�FORMAT_VALUEcCs6yt||d�}Wn tk
r0t||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
    Zeval�exec)�compileZSyntaxError)�source�nameZc�r�/usr/lib64/python3.7/dis.py�_try_compiles
r��file�depthcCsn|dkrt|d�dSt|d�r&|j}t|d�r8|j}n4t|d�rJ|j}n"t|d�r\|j}nt|d�rl|j}t|d��rt|j�	��}x�|D]p\}}t
|t�r�td	||d�yt
|||d
�Wn0tk
r�}ztd||d�Wdd}~XYnXt|d�q�Wnht|d��rt|||d
�nLt
|ttf��r<t||d�n.t
|t��rXt|||d
�ntd
t|�j��dS)a0Disassemble classes, methods, functions, and other compiled objects.

    With no argument, disassemble the last traceback.

    Compiled objects currently include generator objects, async generator
    objects, and coroutine objects, all of which store their code object
    in a special attribute.
    N�r�__func__�__code__�gi_code�ag_code�cr_code�__dict__zDisassembly of %s:rzSorry:�co_code�(don't know how to disassemble %s objects)r�hasattrrrrrrZsortedr�items�
isinstance�
_have_code�printr�	TypeError�_disassemble_recursiveZbytesZ	bytearray�_disassemble_bytes�str�_disassemble_str�type�__name__)�xrrr"rZx1Zmsgrrrr"s>	






 rcCs\|dkrDy
tj}Wntk
r0td�d�YnXx|jrB|j}q4Wt|jj|j|d�dS)z2Disassemble a traceback (default: last traceback).Nz no last traceback to disassembler)	�sysZlast_tracebackZAttributeErrorZRuntimeError�tb_nextr�tb_frame�f_code�tb_lasti)�tbrrrrrOs

Z	OPTIMIZEDZ	NEWLOCALSZVARARGSZVARKEYWORDSZNESTEDZ	GENERATORZNOFREEZ	COROUTINEZITERABLE_COROUTINEZASYNC_GENERATOR)
����i� i@��icCsbg}xRtd�D]8}d|>}||@r|�t�|t|���||N}|sPqW|�t|��d�|�S)z+Return pretty representation of code flags.r8r4�, )�range�append�COMPILER_FLAG_NAMES�getZhex�join)Zflags�names�iZflagrrr�pretty_flagsisrCcCs�t|d�r|j}t|d�r"|j}n4t|d�r4|j}n"t|d�rF|j}nt|d�rV|j}t|t�rjt|d�}t|d�rx|St	dt
|�j��d	S)
zDHelper to handle methods, compiled or raw code objects, and strings.rrrrrz
<disassembly>rr N)r!rrrrrr#r)rr&r+r,�r-rrr�_get_code_objectws 







rEcCstt|��S)z1Formatted details of methods, functions, or code.)�_format_code_inforErDrrrr��cCs�g}|�d|j�|�d|j�|�d|j�|�d|j�|�d|j�|�d|j�|�dt|j��|j	r�|�d�x t
|j	�D]}|�d	|�q�W|jr�|�d
�x t
|j�D]}|�d|�q�W|j�r|�d�x t
|j�D]}|�d|�q�W|j
�rF|�d
�x"t
|j
�D]}|�d|��q.W|j�r||�d�x"t
|j�D]}|�d|��qdWd�|�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:Z
)r=Zco_nameZco_filenameZco_argcountZco_kwonlyargcountZ
co_nlocalsZco_stacksizerCZco_flags�	co_constsZ	enumerate�co_names�co_varnames�co_freevars�co_cellvarsr@)�coZlinesZi_cZi_nrrrrF�s:




rFcCstt|�|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)rMrrrrr	�s�_InstructionzBopname opcode arg argval argrepr offset starts_line is_jump_targetz!Human readable name for operationzNumeric code for operationz6Numeric argument to operation (if any), otherwise Nonez4Resolved arg value (if known), otherwise same as argz0Human readable description of operation argumentz1Start index of operation within bytecode sequencez4Line started by this opcode (if any), otherwise Nonez1True if other code jumps to here, otherwise Falseiic@seZdZdZddd�ZdS)	raKDetails 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
    �Fr6cCs�g}|r:|jdk	r,d|}|�||j�n|�d|�|rJ|�d�n
|�d�|jrf|�d�n
|�d�|�t|j��|��|�|j�t��|j	dk	r�|�t|j	��t
��|jr�|�d|jd	�d�|��
�S)
a%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
        *offset_width* sets the width of the instruction offset field
        Nz%%%ddz z-->z   z>>z  z(z))�starts_liner=�is_jump_target�repr�offsetZrjust�opnameZljust�
_OPNAME_WIDTH�arg�_OPARG_WIDTH�argreprr@Zrstrip)�self�lineno_widthZmark_as_current�offset_widthZfieldsZ
lineno_fmtrrr�_disassemble�s&



zInstruction._disassembleN)rOFr6)r,�
__module__�__qualname__�__doc__r\rrrrr�s)�
first_linecCsTt|�}|j|j}tt|��}|dk	r4||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)rErLrK�dictr�co_firstlineno�_get_instructions_bytesrrJrIrH)r-r`rM�
cell_names�
linestarts�line_offsetrrrr
�scCs |}|dk	r||}|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�rR)Zconst_indexZ
const_list�argvalrrr�_get_const_infosricCs*|}|dk	r||}|}nt|�}||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().
    Nrg)Z
name_indexZ	name_listrhrXrrr�_get_name_infosrjc
csxt|�}d}�xdt|�D�]V\}	}
}|dk	rH|�|	d�}|dk	rH||7}|	|k}d}
d}|dk	�rT|}
|
tkr~t||�\}
}n�|
tkr�t||�\}
}n�|
tkr�|	d|}
dt|
�}n�|
t	kr�t||�\}
}n�|
t
kr�t|}
|
}nn|
tkr�t||�\}
}nV|
t
k�rTdtttf|d@t|d@�f}
d|d@}|
d�rT|�rL|d	7}|d
7}tt|
|
||
||	||�VqWdS)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.

    N�r5zto rOr6)rkr)rR�asciir4r;zwith format)r�_unpack_opargsr?ZhasconstriZhasnamerj�hasjrelrRZhaslocalZ
hascompareZcmp_opZhasfreer
r)rlZboolrrT)�code�varnamesrA�	constants�cellsrerf�labelsrPrS�oprVrQrhrXrrrrc-sH


 

rc�����c
Cs<|j|j}tt|��}t|j||j|j|j|||d�dS)zDisassemble a code object.rN)	rLrKrarr(rrJrIrH)rM�lastirrdrerrrr`scCstt||d�|dks|dkrp|dk	r,|d}xB|jD]8}t|d�r4t|d�td|f|d�t|||d�q4WdS)Nrrr4rzDisassembly of %r:r)rrHr!r%r')rMrrr-rrrr'gs

r')rrfc	Cs�|dk	}	|	r8t|���|}
|
dkr2tt|
��}q<d}nd}t|�d}|dkr^tt|��}
nd}
xdt|||||||d�D]J}|	o�|jdk	o�|jdk}|r�t|d�|j|k}t|�|||
�|d�qzWdS)	Ni�rOrr5i'r6�rfr)	ZmaxZvalues�lenr)rcrPrSr%r\)rorvrprArqrrrerrfZshow_linenoZ	maxlinenorZZ	maxoffsetr[ZinstrZnew_source_lineZis_current_instrrrrr(rs,




r(cKstt|d�f|�dS)z<Compile the source string, then disassemble the code object.z<dis>N)r'r)rZkwargsrrrr*�rGr*ccshd}x^tdt|�d�D]J}||}|tkrP||d|B}|tkrJ|d>nd}nd}|||fVqWdS)Nrr5r4r7)r<rxZ
HAVE_ARGUMENTZEXTENDED_ARG)roZextended_argrBrtrVrrrrm�srmcCs`g}xVt|�D]J\}}}|dk	r|tkr6|d|}n|tkr|}nq||kr|�|�qW|S)z`Detect all offsets in a byte code which are jump targets.

    Return the list of offsets.

    Nr5)rmrnZhasjabsr=)rorsrSrtrVZlabelrrrr�sccs�|jddd�}|jddd�}d}|j}d}xPt||�D]B\}}|rd||kr\||fV|}||7}|dkrt|d8}||7}q:W||kr�||fVdS)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.

    rNr5r4r9r:)Z	co_lnotabrbZzip)roZbyte_incrementsZline_incrementsZ
lastlinenoZlinenoZaddrZ	byte_incrZ	line_incrrrrr�s 
c@sLeZdZdZddd�dd�Zdd�Zdd	�Zed
d��Zdd
�Z	dd�Z
dS)raThe bytecode operations of a piece of code

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

    Iterating over this yields the bytecode operations as Instruction instances.
    N)r`�current_offsetcCsdt|�|_}|dkr&|j|_d|_n||_||j|_|j|j|_tt	|��|_
||_||_dS)Nr)
rE�codeobjrbr`�_line_offsetrLrK�_cell_namesrar�_linestarts�_original_objectry)rYr-r`ryrMrrr�__init__�szBytecode.__init__c	Cs*|j}t|j|j|j|j|j|j|jd�S)Nrw)	rzrcrrJrIrHr|r}r{)rYrMrrr�__iter__�s
zBytecode.__iter__cCsd�|jj|j�S)Nz{}({!r}))ZformatZ	__class__r,r~�rYrrr�__repr__�s
zBytecode.__repr__cCs$x|jr|j}qW||jj|jd�S)z/ Construct a Bytecode from the given traceback )ry)r/r0r1r2)Zclsr3rrr�from_traceback�s
zBytecode.from_tracebackcCs
t|j�S)z3Return formatted information about the code object.)rFrzr�rrr�info�rGz
Bytecode.infocCs`|j}|jdk	r|j}nd}t���2}t|j|j|j|j|j	|j
|j||d�	|��SQRXdS)z3Return a formatted view of the bytecode operations.Nru)rprArqrrrerfrrv)
rzry�ioZStringIOr(rrJrIrHr|r}r{Zgetvalue)rYrMrSZoutputrrrr�s


zBytecode.dis)r,r]r^r_rr�r��classmethodr�r�rrrrrr�s
c	Csdddl}|��}|jd|��ddd�|��}|j�}|��}WdQRXt||jjd�}t	|�dS)z*Simple test program to disassemble a file.rN�infilez?z-)r+ZnargsZdefaultr)
�argparseZArgumentParserZadd_argumentZFileTypeZ
parse_argsr�Zreadrrr)r�ZparserZargsr�rrorrr�_test
sr�Z__main__�Nr�)NNNNNr)ru)ruNNNNN)5r_r.ZtypesZcollectionsr�ZopcoderZ_opcodes_allZ
MethodTypeZFunctionTypeZCodeTyper�Zstaticmethodr+r$Zopmapr
rrrr>rCrErrFr	Z
namedtuplerNrTrVrhrXrSrPrQrUrWrr
rirjrcrr'r(r*rrmrrrr�r,rrrrZ<module>s~


-4
2=