B
    u9aÂ  ã            j   @   sÒ  d dl mZ d dlmZ d dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
dd„ Zeƒ jjZG dd„ dƒZdejjjd	 f Zd
Zdejjjd f Zdejjjd f Zdejjeejjeejjef Zdd„ Zdejjd	 ejjd f ZdZdd„ Zdejjd	 ejjd ejjd f Zg fdd„Z de jjd	 e!e jjd	 e jjd e jjd f Z"dZ#dZ$dZ%dZ&dZ'dZ(d Z)d!Z*d"Z+d#Z,d$Z-d%ejd	 ejd ejd ejd& ejd' f Z.d(d)„ Z/d*e/jjd	 f Z0d+d,„ Z1d-d.„ Z2d/d0„ Z3d1d2„ Z4d3e4jjd	 e!e4jjd	 e4jjd& f Z5d4e5e!e4jjd	 e4jjd e!e4jjd f Z6d5e6e!e4jjd e4jjd f Z7G d6d7„ d7ej8ƒZ9G d8d9„ d9e9ƒZ:d:ej;j<dk r¤d;nd< Z=e>d"g d>œd?d@„ƒZ?dAZ@e?jAjjBd	 ZCdBZDdCZEdDZFdEZGdFdG„ ZHdHZIG dIdJ„ dJej8ƒZJd#dKdL„ZKdMdN„ ZLd	ZMeKjjd	 ZNeKjjBd ZOeOjeN ZPeOjBd ZQeQjeN ZRd	ZSejTZTeTdOdPdQdRdSd ddTdUeTdVdWd dXdXdddTdUeTdVdWd	dYdYd&ddTdUeTdZd[ddd\d]ddTdUeTdOdPdeOeUeOƒdQddTdUeTdOdPd&d^d_d`ddTdUeTdadbdcdcd\ddddTdUeTdedfddgdgdhddTdUeTdidjd dkdkdldmdTdUeTdndod dXdXdpddTdUeTdndod	dYdYdqddTdUeTdOdPd'd\drdsddTdUeTdOdPd]d	dtduddTdUeTdvdwd d d\dxddTdUeTdydzd d d\d{ddTdUeTdOdPdmd|d}d~ddTdUeTdd€dmdmd\dddTdUeTd‚d	ddd\dƒddTdUeTd„d…ddgdgd†dQdTdUeTd‡dˆddd\d‰ddTdUgZVeTdOdPd'dŠd‹d ddTdUeTdVdWddXdXdddTdUeTdVdWddYdYd&ddTdUeTdVdWd dŒdŒd]ddTdUeTdVdWd	dddQddTdUeTdZd[d&d&d\d`ddTdUeTdOdPdeQeUeQƒddddTdUeTdOdPd&dŽddhddTdUeTdadbdcdcd\dlddTdUeTdedfddddpddTdUeTdidjd dkdkdqd'dTdUeTdndoddXdXdsddTdUeTdndoddYdYduddTdUeTdndod dŒdŒdxddTdUeTdndod	ddd{ddTdUeTdd€d&d&d\d~ddTdUeTd‚d	ddd\dddTdUeTd„d…ddddƒd]dTdUeTd‡dˆddd\d†ddTdUgZWeTdidjd dkdkd d&dTdUeTdndod dXdXdddTdUeTdndod	dYdYd&ddTdUeTdndoddŒdŒd]ddTdUeTdndoddddQddTdUeTd„d…d d‘d‘d`ddTdUeTd„d…d	dgdgddddTdUeTdd€d]d]d\dhddTdUeTd‚d	ddd\dlddTdUeTdOdPd dd’dpddTdUeTd‡dˆddd\dqddTdUgZXeTd“d”d•d–d—d ddTdUeTdidjd d˜d˜dddTdUeTdOdPd	d`d™d&ddTdUeTdd€d	d	d\d]ddTdUeTdšd›ddd\dQddTdUeTdœdddždŸd`dd=dUeTdedfd d d ddddTdUeTdidjd	dkdkdhd&dTdUeTd„d…d d d dlddTdUeTdd€d	d	d\dpddTdUeTd‚d	ddd\dqddTdUeTd„d…d d d dsd'dTdUeTdOdPdd&d¡duddTdUeTd¢d£d d¤d¤dxddTdUeTd¥d¦ddd\d{ddTdUeTd§d¨d`d`d\d~d]dTdUeTd„d…d d d ddmd=dUeTdOdPdd]d©dƒddTdUeTd¢d£d&dªdªd†ddTdUeTd¥d¦d`d`d\d‰ddTdUeTd«d¬ddd\d­dQdTdUeTd§d¨d`d`d\d®ddTdUeTd¯d°ddd\dždd=dUeTdidjd	dkdkd±d`dTdUeTdOdPd&d²d³d´ddTdUeTdd€d	d	d\dµddTdUeTd‚d	ddd\d•ddTdUeTd“d”d•d¶d·d–d¸d=dUeTd„d…d d d d¹dd=dUeTd¥d¦dºdºd\d»ddTdUeTdidjd	dkdkd¼dddTdUeTd„d…d d d d½ddTdUeTdd€d	d	d\d¾ddTdUeTd‚d	ddd\d¿ddTdUeTd„d…d d d d›dÀdTdUeTdOdPd'd	dtdÁddTdUeTdÂd¹ddd\dÃddTdUeTdedfd d d dÄddTdUeTd„d…d d d dÅdhdTdUeTdOdPdd]d©dÆddTdUeTd¢d£d&dªdªd¬ddTdUeTd¥d¦dÇdÇd\dÈddTdUeTd§d¨d¹d¹d\dÉdÊdTdUeTd„d…d d d dÇdld=dUeTdOdPdd&d¡dËddTdUeTd¢d£d d¤d¤dÌddTdUeTd¥d¦d¹d¹d\dÍddTdUeTd«d¬ddd\dÎdÏdTdUeTd§d¨d¹d¹d\dÐddTdUeTd¯d°ddd\dºdd=dUeTdidjd	dkdkdPdÑdTdUeTdOdPd]dÒdÓd[ddTdUeTdd€d	d	d\dÔddTdUeTd‚d	ddd\dÕddTdUeTdÖd×dÁdØdÙd¶dqd=dUeTdÚdÛddd…dÜdÝddTdUeTdOdPd'd	dtdÞdßdTdUeTdOdPdmd dàd¦ddTdUeTdádâddd\djddTdUeTd‚d	ddd\dãddTdUeTd¯d°ddd\d”ddTdUeTdädÝd{dådæd×ddTdUeTdçd&ddd\d…dsd=dUeTdidjddèdèdéddTdUeTd¢d£d`dêdêdëddTdUeTd¥d¦dìdìd\díddTdUeTd‚d	ddd\dbddTdUeTd‚d	ddd\dîddTdUeTd‚d	ddd\doddTdUeTdidjd	dkdkdïdðdTdUeTdOdPdQdñdòdóddTdUeTdd€d	d	d\dôddTdUeTd‚d	ddd\dõddTdUeTdöd÷ddd\døddTdUeTdädÝdxdùdúdûddTdUeTdüdËddd\dìdd=dUeTd„d…d d d dådýd=dUeTdþdÿdhd ddddTdUeTdedfd	dddddTdUeTdidjd	dkdkddxdTdUeTdOdPdcdddddTdUeTdd€d	d	d\d	ddTdUeTd‚d	ddd\d
ddTdUeTd¯d°ddd\dddTdUeTdOdPd dd’dddTdUeTddddd\d dd=dUeTddÈddd\dddTdUeTdüdËddd\dddTdUeTd¯d°ddd\dùdd=dUeTdOdPd dd’dddTdUeTdidjd	dkdkdØd{d=dUeTdOdPd`dddddTdUeTdd€d	d	d\dddTdUeTd‚d	ddd\dddTdUeTdüdËddd\dddTdUeTdOdPd dd’dddTdUeTd‡dˆddd\dddTdUgaZYdd„ ZZeTdOdPd dd’d eZjjdTdUeTd‡dˆddd\dddTdUgZ[G dd„ deƒZ\G dd „ d ej8ƒZ]ed!krÎe ^¡  dS ($  é    )Úcaptured_stdout)ÚBytecodeTestCaseNc              C   s$   dd„ } | ƒ }x|j r|j }qW |S )Nc           
   S   s:   ydd  W n( t k
r4 }  z
| j}W d d } ~ X Y nX |S )Né   r   )Ú	ExceptionÚ__traceback__)ÚeÚtb© r	   ú/usr/lib/python3.7/test_dis.pyÚ_error   s
    zget_tb.<locals>._error)Útb_next)r   r   r	   r	   r
   Úget_tb   s
    
r   c               @   s,   e Zd Zdd„ Zedd„ ƒZedd„ ƒZdS )Ú_Cc             C   s   |dk| _ d S )Nr   )Úx)Úselfr   r	   r	   r
   Ú__init__   s    z_C.__init__c             C   s   | dk} d S )Nr   r	   )r   r	   r	   r
   Úsm    s    z_C.smc             C   s   |dk| _ d S )Nr   )r   )Úclsr   r	   r	   r
   Úcm$   s    z_C.cmN)Ú__name__Ú
__module__Ú__qualname__r   Ústaticmethodr   Úclassmethodr   r	   r	   r	   r
   r      s   r   a>  %3d           0 LOAD_FAST                1 (x)
              2 LOAD_CONST               1 (1)
              4 COMPARE_OP               2 (==)
              6 LOAD_FAST                0 (self)
              8 STORE_ATTR               0 (x)
             10 LOAD_CONST               0 (None)
             12 RETURN_VALUE
r   a            0 LOAD_FAST                1 (1)
          2 LOAD_CONST               1 (1)
          4 COMPARE_OP               2 (==)
          6 LOAD_FAST                0 (0)
          8 STORE_ATTR               0 (0)
         10 LOAD_CONST               0 (0)
         12 RETURN_VALUE
a=  %3d           0 LOAD_FAST                1 (x)
              2 LOAD_CONST               1 (1)
              4 COMPARE_OP               2 (==)
              6 LOAD_FAST                0 (cls)
              8 STORE_ATTR               0 (x)
             10 LOAD_CONST               0 (None)
             12 RETURN_VALUE
é   a  %3d           0 LOAD_FAST                0 (x)
              2 LOAD_CONST               1 (1)
              4 COMPARE_OP               2 (==)
              6 STORE_FAST               0 (x)
              8 LOAD_CONST               0 (None)
             10 RETURN_VALUE
zBDisassembly of %s:
%s
Disassembly of %s:
%s
Disassembly of %s:
%s
c             C   s   t | ƒ dS )Nr   )Úprint)Úar	   r	   r
   Ú_f[   s    r   zò%3d           0 LOAD_GLOBAL              0 (print)
              2 LOAD_FAST                0 (a)
              4 CALL_FUNCTION            1
              6 POP_TOP

%3d           8 LOAD_CONST               1 (1)
             10 RETURN_VALUE
zÕ          0 LOAD_GLOBAL              0 (0)
          2 LOAD_FAST                0 (0)
          4 CALL_FUNCTION            1
          6 POP_TOP
          8 LOAD_CONST               1 (1)
         10 RETURN_VALUE
c              C   s   xt ddƒD ]} qW d S )Nr   é
   )Úrange)Zresr	   r	   r
   Ú	bug708901u   s    
r    a  %3d           0 SETUP_LOOP              18 (to 20)
              2 LOAD_GLOBAL              0 (range)
              4 LOAD_CONST               1 (1)

%3d           6 LOAD_CONST               2 (10)
              8 CALL_FUNCTION            2
             10 GET_ITER
        >>   12 FOR_ITER                 4 (to 18)
             14 STORE_FAST               0 (res)

%3d          16 JUMP_ABSOLUTE           12
        >>   18 POP_BLOCK
        >>   20 LOAD_CONST               0 (None)
             22 RETURN_VALUE
é   c             C   s   dst dd„ | D ƒd ƒ‚d S )Nr   c             S   s   g | ]}|‘qS r	   r	   )Ú.0Úsr	   r	   r
   ú
<listcomp>   s    zbug1333982.<locals>.<listcomp>r   )ÚAssertionError)r   r	   r	   r
   Ú
bug1333982Ž   s    r&   aÖ  %3d           0 LOAD_CONST               1 (0)
              2 POP_JUMP_IF_TRUE        26
              4 LOAD_GLOBAL              0 (AssertionError)
              6 LOAD_CONST               2 (<code object <listcomp> at 0x..., file "%s", line %d>)
              8 LOAD_CONST               3 ('bug1333982.<locals>.<listcomp>')
             10 MAKE_FUNCTION            0
             12 LOAD_FAST                0 (x)
             14 GET_ITER
             16 CALL_FUNCTION            1

%3d          18 LOAD_CONST               4 (1)
             20 BINARY_ADD
             22 CALL_FUNCTION            1
             24 RAISE_VARARGS            1

%3d     >>   26 LOAD_CONST               0 (None)
             28 RETURN_VALUE
z™%3d           0 LOAD_GLOBAL              0 (spam)
              2 POP_TOP
              4 LOAD_CONST               0 (None)
              6 RETURN_VALUE
zœ%4d           0 LOAD_GLOBAL              0 (spam)
               2 POP_TOP
               4 LOAD_CONST               0 (None)
               6 RETURN_VALUE
zÄDisassembly of f:
  4           0 LOAD_CONST               0 (None)
              2 RETURN_VALUE

Disassembly of g:
  5           0 LOAD_CONST               0 (None)
              2 RETURN_VALUE

zx + 1z–  1           0 LOAD_NAME                0 (x)
              2 LOAD_CONST               0 (1)
              4 BINARY_ADD
              6 RETURN_VALUE
z	x = x + 1z÷  1           0 LOAD_NAME                0 (x)
              2 LOAD_CONST               0 (1)
              4 BINARY_ADD
              6 STORE_NAME               0 (x)
              8 LOAD_CONST               1 (None)
             10 RETURN_VALUE
z+
x: int = 1
y: fun(1)
lst[fun(0)]: int = 1
aô    2           0 SETUP_ANNOTATIONS
              2 LOAD_CONST               0 (1)
              4 STORE_NAME               0 (x)
              6 LOAD_NAME                1 (int)
              8 LOAD_NAME                2 (__annotations__)
             10 LOAD_CONST               1 ('x')
             12 STORE_SUBSCR

  3          14 LOAD_NAME                3 (fun)
             16 LOAD_CONST               0 (1)
             18 CALL_FUNCTION            1
             20 LOAD_NAME                2 (__annotations__)
             22 LOAD_CONST               2 ('y')
             24 STORE_SUBSCR

  4          26 LOAD_CONST               0 (1)
             28 LOAD_NAME                4 (lst)
             30 LOAD_NAME                3 (fun)
             32 LOAD_CONST               3 (0)
             34 CALL_FUNCTION            1
             36 STORE_SUBSCR
             38 LOAD_NAME                1 (int)
             40 POP_TOP
             42 LOAD_CONST               4 (None)
             44 RETURN_VALUE
zx = 0
while 1:
    x += 1aÐ    1           0 LOAD_CONST               0 (0)
              2 STORE_NAME               0 (x)

  2           4 SETUP_LOOP              12 (to 18)

  3     >>    6 LOAD_NAME                0 (x)
              8 LOAD_CONST               1 (1)
             10 INPLACE_ADD
             12 STORE_NAME               0 (x)
             14 JUMP_ABSOLUTE            6
             16 POP_BLOCK
        >>   18 LOAD_CONST               2 (None)
             20 RETURN_VALUE
a¯  %3d           0 SETUP_EXCEPT            12 (to 14)

%3d           2 LOAD_CONST               1 (1)
              4 LOAD_CONST               2 (0)
    -->       6 BINARY_TRUE_DIVIDE
              8 POP_TOP
             10 POP_BLOCK
             12 JUMP_FORWARD            40 (to 54)

%3d     >>   14 DUP_TOP
             16 LOAD_GLOBAL              0 (Exception)
             18 COMPARE_OP              10 (exception match)
             20 POP_JUMP_IF_FALSE       52
             22 POP_TOP
             24 STORE_FAST               0 (e)
             26 POP_TOP
             28 SETUP_FINALLY           10 (to 40)

%3d          30 LOAD_FAST                0 (e)
             32 LOAD_ATTR                1 (__traceback__)
             34 STORE_FAST               1 (tb)
             36 POP_BLOCK
             38 LOAD_CONST               0 (None)
        >>   40 LOAD_CONST               0 (None)
             42 STORE_FAST               0 (e)
             44 DELETE_FAST              0 (e)
             46 END_FINALLY
             48 POP_EXCEPT
             50 JUMP_FORWARD             2 (to 54)
        >>   52 END_FINALLY

%3d     >>   54 LOAD_FAST                1 (tb)
             56 RETURN_VALUE
é   é   c             C   s   | › d|d›d|›d|d›S )Nú Ú4r	   )r   ÚbÚcÚdr	   r	   r
   Ú_fstring:  s    r.   aÎ  %3d           0 LOAD_FAST                0 (a)
              2 FORMAT_VALUE             0
              4 LOAD_CONST               1 (' ')
              6 LOAD_FAST                1 (b)
              8 LOAD_CONST               2 ('4')
             10 FORMAT_VALUE             4 (with format)
             12 LOAD_CONST               1 (' ')
             14 LOAD_FAST                2 (c)
             16 FORMAT_VALUE             2 (repr)
             18 LOAD_CONST               1 (' ')
             20 LOAD_FAST                3 (d)
             22 LOAD_CONST               2 ('4')
             24 FORMAT_VALUE             6 (repr, with format)
             26 BUILD_STRING             7
             28 RETURN_VALUE
c             c   s
   | V  d S )Nr	   )r   r	   r	   r
   Ú_gO  s    r/   c             C  s
   | V  d S )Nr	   )r   r	   r	   r
   Ú_agR  s    r0   c          	   Ã   s4   x.t | ƒ2 y3 d H }W q
 tk
s$X q
   Y  W d S )N)r0   ÚStopAsyncIteration)r   Úitemr	   r	   r
   Ú_coU  s    "r3   c                s   ‡ fdd„}|S )Nc                s   ‡ fdd„ˆD ƒS )Zfuncdocc                s   g | ]}ˆ | ‘qS r	   r	   )r"   Úz)r   r	   r
   r$   \  s    z#_h.<locals>.foo.<locals>.<listcomp>r	   )r   )Úy)r   r
   ÚfooZ  s    z_h.<locals>.foor	   )r5   r6   r	   )r5   r
   Ú_hY  s    r7   a   %3d           0 LOAD_CLOSURE             0 (y)
              2 BUILD_TUPLE              1
              4 LOAD_CONST               1 (<code object foo at 0x..., file "%s", line %d>)
              6 LOAD_CONST               2 ('_h.<locals>.foo')
              8 MAKE_FUNCTION            8
             10 STORE_FAST               1 (foo)

%3d          12 LOAD_FAST                1 (foo)
             14 RETURN_VALUE
a  %s
Disassembly of <code object foo at 0x..., file "%s", line %d>:
%3d           0 LOAD_CLOSURE             0 (x)
              2 BUILD_TUPLE              1
              4 LOAD_CONST               1 (<code object <listcomp> at 0x..., file "%s", line %d>)
              6 LOAD_CONST               2 ('_h.<locals>.foo.<locals>.<listcomp>')
              8 MAKE_FUNCTION            8
             10 LOAD_DEREF               1 (y)
             12 GET_ITER
             14 CALL_FUNCTION            1
             16 RETURN_VALUE
aò  %s
Disassembly of <code object <listcomp> at 0x..., file "%s", line %d>:
%3d           0 BUILD_LIST               0
              2 LOAD_FAST                0 (.0)
        >>    4 FOR_ITER                12 (to 18)
              6 STORE_FAST               1 (z)
              8 LOAD_DEREF               0 (x)
             10 LOAD_FAST                1 (z)
             12 BINARY_ADD
             14 LIST_APPEND              2
             16 JUMP_ABSOLUTE            4
        >>   18 RETURN_VALUE
c               @   sô   e Zd ZdZd<dd„Zd=dd„Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Zd:d;„ ZdS )>ÚDisTestsNéÿÿÿÿTc          	   K   sJ   t  ¡ }t |¡* |r(tj|f|Ž ntj||f|Ž W d Q R X | ¡ S )N)ÚioÚStringIOÚ
contextlibÚredirect_stdoutÚdisÚdisassembleÚgetvalue)r   ÚfuncÚlastiÚwrapperÚkwargsÚoutputr	   r	   r
   Úget_disassembly™  s    zDisTests.get_disassemblyc             C   s   |   ||d¡S )NF)rF   )r   rA   rB   r	   r	   r
   Úget_disassemble_as_string£  s    z"DisTests.get_disassemble_as_stringc             C   s   t  dd|¡S )Nz\b0x[0-9A-Fa-f]+\bz0x...)ÚreÚsub)r   Útextr	   r	   r
   Ústrip_addresses¦  s    zDisTests.strip_addressesc             C   s0   | j |dd}||kr |  |¡}|  ||¡ d S )Nr   )Údepth)rF   rK   ÚassertEqual)r   rA   ÚexpectedZgotr	   r	   r
   Údo_disassembly_test©  s    
zDisTests.do_disassembly_testc             C   s>   |   tjd d¡ |  tjd tj¡ |  tjd tj¡ d S )NZNOPé	   Ú
LOAD_CONSTÚ
STORE_NAME)rM   r>   ÚopmapZassertInZhasconstZhasname)r   r	   r	   r
   Ú
test_opmap¯  s    zDisTests.test_opmapc             C   s   |   tjtjd  d¡ d S )NÚ	LOAD_FAST)rM   r>   ÚopnamerS   )r   r	   r	   r
   Útest_opname´  s    zDisTests.test_opnamec             C   s,   |   tjd tj¡ |   tjd tj¡ d S )NÚEXTENDED_ARGrR   )rM   r>   rS   rX   ÚHAVE_ARGUMENT)r   r	   r	   r
   Útest_boundaries·  s    zDisTests.test_boundariesc          
   C   sl   xft tjƒD ]X\}}|dkrq| j|d4 tj}|tjk rJ|dtj 7 }|  t|ƒ|¡ W d Q R X qW d S )N)ZBUILD_MAP_UNPACK_WITH_CALLZBUILD_TUPLE_UNPACK_WITH_CALL)rV   r   )	Ú	enumerater>   rV   ÚsubTestZ_OPNAME_WIDTHrY   Z_OPARG_WIDTHZassertLessEqualÚlen)r   ÚopcoderV   Úwidthr	   r	   r
   Útest_widths»  s    
zDisTests.test_widthsc             C   s   |   tt¡ d S )N)rO   r   Údis_f)r   r	   r	   r
   Útest_disÆ  s    zDisTests.test_disc             C   s   |   tt¡ d S )N)rO   r    Údis_bug708901)r   r	   r	   r
   Útest_bug_708901É  s    zDisTests.test_bug_708901c             C   s   |   tt¡ d S )N)rO   r&   Údis_bug1333982)r   r	   r	   r
   Útest_bug_1333982Ì  s    zDisTests.test_bug_1333982c             C   s¸   dd„ }x.t ddƒD ] }t|d  }|  ||ƒ|¡ qW x0t dddƒD ] }t|d  }|  ||ƒ|¡ qFW x0t dddƒD ] }t|d  }|  ||ƒ|¡ qxW d	d
lm} |  |t¡ d S )Nc             S   s0   i }dd  dg|  dg ¡ }t||ƒ |d S )Nzdef foo():
 Ú z
 zspam
r6   )ÚjoinÚexec)ÚcountÚ	namespacerA   r	   r	   r
   rA   Õ  s    
z'DisTests.test_big_linenos.<locals>.funcr   i,  r   iè  r   iˆ  r   )Ú
dis_module)r   Ú_BIG_LINENO_FORMATrO   Ú_BIG_LINENO_FORMAT2Ztestrl   Údis_module_expected_results)r   rA   ÚirN   rl   r	   r	   r
   Útest_big_linenosÔ  s    zDisTests.test_big_linenosc             C   sj   dd„ }dd„ }x(t ddƒD ]}|  ||ƒ||dƒ¡ qW |  |dƒ|ddƒ¡ |  |d	ƒ|d	dƒ¡ d S )
Nc             S   s.   i }dd  dg|  ¡ d }t||ƒ |d S )Nzdef foo(x):
 ú;z	x = x + 1z

 return xr6   )rh   ri   )rj   rk   rA   r	   r	   r
   rA   í  s    
z'DisTests.test_big_offsets.<locals>.funcc                sZ   ‡ fdd„t | ƒD ƒ}|dˆ d|  ˆ d|  d f g7 }d|d dd …  |d< d	 |¡S )
Nc                s@   g | ]8}d ˆ d| ˆ d| d ˆ d| d ˆ d| d f ‘qS )z¤           %*d LOAD_FAST                0 (x)
           %*d LOAD_CONST               1 (1)
           %*d BINARY_ADD
           %*d STORE_FAST               0 (x)
é   r   r'   é   r	   )r"   rp   )Úwr	   r
   r$   ù  s   z?DisTests.test_big_offsets.<locals>.expected.<locals>.<listcomp>zK
  3        %*d LOAD_FAST                0 (x)
           %*d RETURN_VALUE
rs   r   z  2r   r!   rg   )r   rh   )rj   ru   r#   r	   )ru   r
   rN   ó  s    
 z+DisTests.test_big_offsets.<locals>.expectedr   r(   r'   iá  iâ  )r   rO   )r   rA   rN   rp   r	   r	   r
   Útest_big_offsetsì  s    zDisTests.test_big_offsetsc             C   s4   |   tt¡ |   tt¡ |   tt¡ |   tt¡ d S )N)	rO   Úexpr_strÚdis_expr_strÚsimple_stmt_strÚdis_simple_stmt_strÚannot_stmt_strÚdis_annot_stmt_strÚcompound_stmt_strÚdis_compound_stmt_str)r   r	   r	   r
   Útest_disassemble_str  s    zDisTests.test_disassemble_strc             C   s   |   tjjt¡ d S )N)rO   r   Ú__code__Úco_codeÚdis_f_co_code)r   r	   r	   r
   Útest_disassemble_bytes  s    zDisTests.test_disassemble_bytesc             C   s   |   tt¡ d S )N)rO   r   Údis_c)r   r	   r	   r
   Útest_disassemble_class  s    zDisTests.test_disassemble_classc             C   s   |   tdƒjt¡ d S )Nr   )rO   r   r   Údis_c_instance_method)r   r	   r	   r
   Ú test_disassemble_instance_method  s    z)DisTests.test_disassemble_instance_methodc             C   s   t dƒjjj}|  |t¡ d S )Nr   )r   r   r€   r   rO   Údis_c_instance_method_bytes)r   Zmethod_bytecoder	   r	   r
   Ú&test_disassemble_instance_method_bytes  s    z/DisTests.test_disassemble_instance_method_bytesc             C   s   |   tjt¡ d S )N)rO   r   r   Údis_c_static_method)r   r	   r	   r
   Útest_disassemble_static_method  s    z'DisTests.test_disassemble_static_methodc             C   s   |   tjt¡ d S )N)rO   r   r   Údis_c_class_method)r   r	   r	   r
   Útest_disassemble_class_method  s    z&DisTests.test_disassemble_class_methodc             C   s(   |   t¡}|   tdƒ¡}|  ||¡ d S )Nr   )rF   r/   rM   )r   Zgen_func_disasZ	gen_disasr	   r	   r
   Útest_disassemble_generator!  s    
z#DisTests.test_disassemble_generatorc             C   s(   |   t¡}|   tdƒ¡}|  ||¡ d S )Nr   )rF   r0   rM   )r   Zagen_func_disasZ
agen_disasr	   r	   r
   Ú test_disassemble_async_generator&  s    
z)DisTests.test_disassemble_async_generatorc             C   s4   |   t¡}tdƒ}| ¡  |   |¡}|  ||¡ d S )Nr   )rF   r3   ÚcloserM   )r   Zcoro_func_disasÚcoroZ
coro_disasr	   r	   r
   Útest_disassemble_coroutine+  s
    

z#DisTests.test_disassemble_coroutinec             C   s   |   tt¡ d S )N)rO   r.   Údis_fstring)r   r	   r	   r
   Útest_disassemble_fstring2  s    z!DisTests.test_disassemble_fstringc             C   s2   yt `W n tk
r   Y nX |  ttjd ¡ d S )N)ÚsysÚlast_tracebackÚAttributeErrorÚassertRaisesÚRuntimeErrorr>   )r   r	   r	   r
   Útest_dis_none5  s
    zDisTests.test_dis_nonec          
   C   s|   yt `W n tk
r   Y nX ydd  W n. tk
rX } z|j}|t _W d d }~X Y nX |  |jj|j¡}|  	d |¡ d S )Nr   r   )
r•   r–   r—   r   r   rG   Útb_frameÚf_codeÚtb_lastirO   )r   r   r   Ztb_disr	   r	   r
   Útest_dis_traceback<  s    zDisTests.test_dis_tracebackc             C   s   |   ttjtƒ ¡ d S )N)r˜   Ú	TypeErrorr>   Úobject)r   r	   r	   r
   Útest_dis_objectK  s    zDisTests.test_dis_objectc                sT   ‡ fdd„}|t dd |tdd |tdd |tdd |td d |tƒ d S )Nc                s(   ˆ j tf|Ž}ˆ  |¡}ˆ  || ¡ d S )N)rF   r7   rK   rM   )rN   rD   r>   )r   r	   r
   ÚcheckO  s    
z2DisTests.test_disassemble_recursive.<locals>.checkr   )rL   r   r   r!   )Údis_nested_0Údis_nested_1Údis_nested_2)r   r¢   r	   )r   r
   Útest_disassemble_recursiveN  s    z#DisTests.test_disassemble_recursive)r9   T)r9   ) r   r   r   ÚmaxDiffrF   rG   rK   rO   rT   rW   rZ   r`   rb   rd   rf   rq   rv   r   rƒ   r…   r‡   r‰   r‹   r   rŽ   r   r’   r”   rš   rž   r¡   r¦   r	   r	   r	   r
   r8   •  s:   


r8   c               @   s   e Zd Zddd„ZdS )ÚDisWithFileTestsr9   Tc             K   sD   t  ¡ }|r$tj|fd|i|—Ž ntj||fd|i|—Ž | ¡ S )NÚfile)r:   r;   r>   r?   r@   )r   rA   rB   rC   rD   rE   r	   r	   r
   rF   _  s
    z DisWithFileTests.get_disassemblyN)r9   T)r   r   r   rF   r	   r	   r	   r
   r¨   \  s   r¨   a  Name:              code_info
Filename:          (.*)
Argument count:    1
Kw-only arguments: 0
Number of locals:  1
Stack size:        3
Flags:             OPTIMIZED, NEWLOCALS, NOFREE
Constants:
   0: %r
Names:
   0: _format_code_info
   1: _get_code_object
Variable names:
   0: x)z1Formatted details of methods, functions, or code.)NT)r   c            /   s2   |f‡ ‡‡‡‡‡fdd„	‰ˆˆˆ|ˆ ˆˆfV  d S )Nc                s   t ˆˆˆ| ˆ ˆˆƒ d S )N)r   )r,   )r-   r   Úfr   r5   r4   r	   r
   rª   |  s    ztricky.<locals>.fr	   )r   r5   r4   r,   r-   r   ÚargsÚkwdsr	   )r-   r   rª   r   r5   r4   r
   Útrickyz  s    r­   aô  Name:              tricky
Filename:          (.*)
Argument count:    3
Kw-only arguments: 3
Number of locals:  8
Stack size:        7
Flags:             OPTIMIZED, NEWLOCALS, VARARGS, VARKEYWORDS, GENERATOR
Constants:
   0: None
   1: <code object f at (.*), file "(.*)", line (.*)>
   2: 'tricky.<locals>.f'
Variable names:
   0: x
   1: y
   2: z
   3: c
   4: d
   5: e
   6: args
   7: kwds
Cell variables:
   0: [edfxyz]
   1: [edfxyz]
   2: [edfxyz]
   3: [edfxyz]
   4: [edfxyz]
   5: [edfxyz]a[  Name:              f
Filename:          (.*)
Argument count:    1
Kw-only arguments: 0
Number of locals:  1
Stack size:        8
Flags:             OPTIMIZED, NEWLOCALS, NESTED
Constants:
   0: None
Names:
   0: print
Variable names:
   0: c
Free variables:
   0: [edfxyz]
   1: [edfxyz]
   2: [edfxyz]
   3: [edfxyz]
   4: [edfxyz]
   5: [edfxyz]zÌName:              <module>
Filename:          <disassembly>
Argument count:    0
Kw-only arguments: 0
Number of locals:  0
Stack size:        2
Flags:             NOFREE
Constants:
   0: 1
Names:
   0: xz×Name:              <module>
Filename:          <disassembly>
Argument count:    0
Kw-only arguments: 0
Number of locals:  0
Stack size:        2
Flags:             NOFREE
Constants:
   0: 1
   1: None
Names:
   0: xzßName:              <module>
Filename:          <disassembly>
Argument count:    0
Kw-only arguments: 0
Number of locals:  0
Stack size:        2
Flags:             NOFREE
Constants:
   0: 0
   1: 1
   2: None
Names:
   0: xc           
   Ã   sX   dI d H  x*t 2 y3 d H } W q tk
s*X q   Y  W t4 I d H š}W d Q I d H R X d S )Nr   )r+   r1   r,   )r   r-   r	   r	   r
   Ú	async_defá  s
    
  r®   zâName:              async_def
Filename:          (.*)
Argument count:    0
Kw-only arguments: 0
Number of locals:  2
Stack size:        10
Flags:             OPTIMIZED, NEWLOCALS, NOFREE, COROUTINE
Constants:
   0: None
   1: 1c               @   s\   e Zd Zejefeefee	fe
efeefeefeefgZdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚCodeInfoTestsc             C   s0   d| _ x$| jD ]\}}|  t |¡|¡ qW d S )Niè  )r§   Ú
test_pairsÚassertRegexr>   Ú	code_info)r   r   rN   r	   r	   r
   Útest_code_infoý  s    zCodeInfoTests.test_code_infoc          
   C   st   d| _ xh| jD ]^\}}tƒ }t |¡ W d Q R X |  | ¡ |d ¡ t ¡ }tj||d |  | ¡ |¡ qW d S )Niè  Ú
)r©   )	r§   r°   r   r>   Z	show_coder±   r@   r:   r;   )r   r   rN   rE   r	   r	   r
   Útest_show_code  s    zCodeInfoTests.test_show_codec             C   s   |   ttjtƒ ¡ d S )N)r˜   rŸ   r>   r²   r    )r   r	   r	   r
   Útest_code_info_object  s    z#CodeInfoTests.test_code_info_objectc             C   s   |   t d¡d¡ d S )Nr   Z0x0)rM   r>   Zpretty_flags)r   r	   r	   r
   Útest_pretty_flags_no_flags  s    z(CodeInfoTests.test_pretty_flags_no_flagsN)r   r   r   r>   r²   Úcode_info_code_infor­   Úcode_info_trickyÚco_tricky_nested_fÚcode_info_tricky_nested_frw   Úcode_info_expr_strry   Úcode_info_simple_stmt_strr}   Úcode_info_compound_stmt_strr®   Úcode_info_async_defr°   r³   rµ   r¶   r·   r	   r	   r	   r
   r¯   ò  s   

r¯   c                s(   d‡ ‡fdd„	}t ˆ ˆddg i dƒ |S )	Nr!   r'   c                s&   d‡‡‡ ‡fdd„	}t ˆˆˆ ˆƒ |S )Nr(   rt   c                s   t ˆ ˆˆˆ| |ƒ d S )N)r   )r   rª   )r   r+   r,   r-   r	   r
   Úinner  s    zouter.<locals>.f.<locals>.inner)r(   rt   )r   )r,   r-   rÀ   )r   r+   )r,   r-   r
   rª     s    zouter.<locals>.frg   r   zHello world!)r!   r'   )r   )r   r+   rª   r	   )r   r+   r
   Úouter  s    rÁ   c           	   C   sÂ   x4t dƒD ] } t| ƒ | dk r q
| dkr
P q
W tdƒ x4| rbt| ƒ | d8 } | dkrVq8| dk r8P q8W tdƒ zFydd  W n tk
r–   tdƒ Y nX | }td	ƒ W d Q R X W d td
ƒ X d S )Nr   r'   rt   zI can haz else clause?r   z%Who let lolcatz into this test suite?r   z%Here we go, here we go, here we go...zNever reach thiszOK, now we're done)r   r   ÚZeroDivisionError)rp   Údodgyr	   r	   r
   Újumpy  s,    rÄ   rQ   éd   rs   )r!   r'   z(3, 4)F)rV   r^   ÚargZargvalZargreprÚoffsetZstarts_lineZis_jump_targetZLOAD_CLOSUREé‡   r   r+   ZBUILD_TUPLEéf   rg   rt   zouter.<locals>.fz'outer.<locals>.f'r   ZMAKE_FUNCTIONé„   rP   é   Z
STORE_FASTé}   rª   é   ZLOAD_GLOBALét   r   é   é   Z
LOAD_DEREFéˆ   é   é   z''é   Ú1é   Z
BUILD_LISTég   é   Z	BUILD_MAPéi   é   zHello world!z'Hello world!'é   ZCALL_FUNCTIONéƒ   é    ZPOP_TOPé"   rU   é|   é$   ZRETURN_VALUEéS   é&   )r(   rt   z(5, 6)r,   r-   zouter.<locals>.f.<locals>.innerz!'outer.<locals>.f.<locals>.inner'rÀ   r   ÚNoneZ
SETUP_LOOPéx   é4   é6   zto 54r   Z10ZGET_ITERéD   ZFOR_ITERé]   é,   zto 44rp   r*   Z
COMPARE_OPék   ú<ZPOP_JUMP_IF_FALSEér   ZJUMP_ABSOLUTEéq   Ú6ú>Z
BREAK_LOOPéP   é(   é*   Z	POP_BLOCKéW   é.   zI can haz else clause?z'I can haz else clause?'é0   é2   él   zto 108é   é8   éb   é:   é<   é>   é@   éB   é   éF   ZINPLACE_SUBTRACTéH   éJ   éL   éN   éV   éR   éT   é   éX   éZ   é\   é^   é   é`   é   z%Who let lolcatz into this test suite?z''Who let lolcatz into this test suite?'éh   éj   ZSETUP_FINALLYéz   é´   zto 180ZSETUP_EXCEPTéy   zto 124én   ép   é   Ú0ZBINARY_TRUE_DIVIDEé   év   ZJUMP_FORWARDé˜   zto 152ZDUP_TOPrÂ   é~   zexception matché€   é–   é‚   é†   éŠ   é   z%Here we go, here we go, here we go...z''Here we go, here we go, here we go...'éŒ   éŽ   é   Z
POP_EXCEPTéY   é’   é°   zto 176é”   ZEND_FINALLYé   Z
SETUP_WITHé   éª   zto 170éš   rÃ   éœ   éž   zNever reach thisz'Never reach this'é    é¢   é¤   é¦   é¨   ZWITH_CLEANUP_STARTéQ   ZWITH_CLEANUP_FINISHé¬   é®   é²   zOK, now we're donez"OK, now we're done"é¶   é¸   éº   é¼   é¾   éÀ   c               C   s   d S )Nr	   r	   r	   r	   r
   Úsimpleø  ó    r@  c               @   s<   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ ZdS )ÚInstructionTestsc             C   s   t  t¡}|  t|ƒt¡ d S )N)r>   Úget_instructionsr@  rM   ÚlistÚexpected_opinfo_simple)r   Úactualr	   r	   r
   Útest_default_first_line  s    
z(InstructionTests.test_default_first_linec             C   s"   t jtd d}|  t|ƒt¡ d S )N)Ú
first_line)r>   rC  r@  rM   rD  rE  )r   rF  r	   r	   r
   Útest_first_line_set_to_None  s    z,InstructionTests.test_first_line_set_to_Nonec             C   s"   t jttd}|  t|ƒt¡ d S )N)rH  )r>   rC  rÁ   Úexpected_outer_linerM   rD  Úexpected_opinfo_outer)r   rF  r	   r	   r
   Ú
test_outer	  s    zInstructionTests.test_outerc          	   C   s:   t ƒ  tƒ }W d Q R X tj|td}|  t|ƒt¡ d S )N)rH  )r   rÁ   r>   rC  Úexpected_f_linerM   rD  Úexpected_opinfo_f)r   rª   rF  r	   r	   r
   Útest_nested  s    zInstructionTests.test_nestedc          	   C   s<   t ƒ  tƒ ƒ }W d Q R X tj|td}|  t|ƒt¡ d S )N)rH  )r   rÁ   r>   rC  Úexpected_inner_linerM   rD  Úexpected_opinfo_inner)r   rÀ   rF  r	   r	   r
   Útest_doubly_nested  s    z#InstructionTests.test_doubly_nestedc             C   s"   t jttd}|  t|ƒt¡ d S )N)rH  )r>   rC  rÄ   Úexpected_jumpy_linerM   rD  Úexpected_opinfo_jumpy)r   rF  r	   r	   r
   Ú
test_jumpy  s    zInstructionTests.test_jumpyN)	r   r   r   rG  rI  rL  rO  rR  rU  r	   r	   r	   r
   rB  ÿ  s   rB  c               @   sL   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dS )ÚBytecodeTestsc          
   C   sf   xNt tdƒjdt jgD ]6}| j|d  t |¡}|  |jt	j
¡ W d Q R X qW |  ttjtƒ ¡ d S )Nr   za=1)Úobj)r   r   r   r€   r\   r>   ÚBytecodeZassertIsInstanceZcodeobjÚtypesÚCodeTyper˜   rŸ   r    )r   rW  r+   r	   r	   r
   Útest_instantiation   s
    
z BytecodeTests.test_instantiationc          
   C   sb   x\t tdƒjdt jgD ]D}| j|d. tt |¡ƒ}tt |¡ƒ}|  	||¡ W d Q R X qW d S )Nr   za=1)rW  )
r   r   r   r€   r\   rD  r>   rX  rC  rM   )r   rW  Z
via_objectZvia_generatorr	   r	   r
   Útest_iteration)  s
    zBytecodeTests.test_iterationc             C   s"   t jttd}|  t|ƒt¡ d S )N)rH  )r>   rX  rÁ   rJ  rM   rD  rK  )r   rF  r	   r	   r
   Útest_explicit_first_line0  s    z&BytecodeTests.test_explicit_first_linec             C   sl   t  t¡  ¡ }| ¡  d¡d }ttjjƒ}|  ||¡ t jtdd  ¡ }| ¡  d¡d }|  |d¡ d S )Nr)   r   i^  )rH  Z350)	r>   rX  r@  ÚstripÚ	partitionÚstrr€   Úco_firstlinenorM   )r   rF  rN   r	   r	   r
   Útest_source_line_in_disassembly4  s    z-BytecodeTests.test_source_line_in_disassemblyc             C   s8   d| _ x,tjD ]"\}}t |¡}|  | ¡ |¡ qW d S )Niè  )r§   r¯   r°   r>   rX  r±   Úinfo)r   r   rN   r+   r	   r	   r
   Ú	test_info?  s    
zBytecodeTests.test_infoc             C   s   t  t¡  ¡ }|  |t¡ d S )N)r>   rX  r   rM   ra   )r   rF  r	   r	   r
   Útest_disassembledE  s    zBytecodeTests.test_disassembledc             C   s8   t ƒ }tj |¡}x|jr"|j}qW |  |j|j¡ d S )N)r   r>   rX  Úfrom_tracebackr   rM   Zcurrent_offsetr   )r   r   r+   r	   r	   r
   Útest_from_tracebackI  s
     
z!BytecodeTests.test_from_tracebackc             C   s&   t ƒ }tj |¡}|  | ¡ t¡ d S )N)r   r>   rX  rf  rM   Údis_traceback)r   r   r+   r	   r	   r
   Útest_from_traceback_disP  s    z%BytecodeTests.test_from_traceback_disN)r   r   r   r[  r\  r]  rb  rd  re  rg  ri  r	   r	   r	   r
   rV    s   	rV  Ú__main__)T)r   r   )_Ztest.supportr   Ztest.bytecode_helperr   Zunittestr•   r>   r:   rH   rY  r<   r   r›   rœ   ZTRACEBACK_CODEr   r   r€   ra  r†   rˆ   r   rŒ   r   rŠ   r   r„   r   ra   r‚   r    rc   r&   Ú__file__re   rm   rn   ro   rw   rx   ry   rz   r{   r|   r}   r~   rh  r.   r“   r/   r0   r3   r7   r£   r¤   r¥   ZTestCaser8   r¨   ÚflagsÚoptimizer¸   r   r­   r¹   Ú__func__Ú	co_constsrº   r»   r¼   r½   r¾   r®   r¿   r¯   rÁ   rÄ   rJ  Z_line_offsetZcode_object_frM  Zcode_object_innerrP  rS  ZInstructionÚreprrK  rN  rQ  rT  r@  rE  rB  rV  Úmainr	   r	   r	   r
   Ú<module>   sð  


	





	$




 H #	


 6