Commits

gstarnberger committed 9708c4c Merge
  • Participants
  • Parent commits a5b9295, 91f148a

Comments (0)

Files changed (26)

 
-                 uncompyle -- A Python byte-code decompiler
-                          0.11
-                          2011-1-9
+                 uncompyle -- A Python 2.7 byte-code decompiler
+                          0.12
+                          2012-1-23
 
 Introduction
 ------------

scripts/uncompyler.py

         except verify.VerifyCmpError:
             raise
     else:
+        # create directories beforehand
+        for f in files:
+          try:
+            os.makedirs(os.path.join(out_base, os.path.dirname(f)))
+          except OSError:
+            pass
         fqueue = Queue(len(files)+numproc)
         for f in files:
             fqueue.put(f)
        author = "Hartmut Goebel",
        author_email = "hartmut@oberon.noris.de",
        url = "http://github.com/gstarnberger/uncompyle",
-       packages=['uncompyle', 'uncompyle.dis', 'uncompyle.opcode'],
+       packages=['uncompyle'],
        scripts=['scripts/uncompyler.py'],
       )

uncompyle/Parser.py

         _come_from ::= 
 
         
-        list_for ::= expr _for designator list_iter JUMP_BACK COME_FROM
+        list_for ::= expr _for designator list_iter JUMP_BACK
         list_if ::= expr jmp_false list_iter               
         list_if_not ::= expr jmp_true list_iter               
 
         stmt ::= setcomp_func
         
         setcomp_func ::= BUILD_SET_0 LOAD_FAST FOR_ITER designator comp_iter
-                JUMP_BACK COME_FROM RETURN_VALUE RETURN_LAST
+                JUMP_BACK RETURN_VALUE RETURN_LAST
         
         comp_iter ::= comp_if
         comp_iter ::= comp_ifnot
 
         comp_if ::= expr jmp_false comp_iter
         comp_ifnot ::= expr jmp_true comp_iter
-        comp_for ::= expr _for designator comp_iter JUMP_BACK COME_FROM
+        comp_for ::= expr _for designator comp_iter JUMP_BACK
         '''
 
 
         
         stmt ::= genexpr_func
         
-        genexpr_func ::= LOAD_FAST FOR_ITER designator comp_iter JUMP_BACK COME_FROM
+        genexpr_func ::= LOAD_FAST FOR_ITER designator comp_iter JUMP_BACK
         '''
 
 
         stmt ::= dictcomp_func
         
         dictcomp_func ::= BUILD_MAP LOAD_FAST FOR_ITER designator
-                comp_iter JUMP_BACK COME_FROM RETURN_VALUE RETURN_LAST
+                comp_iter JUMP_BACK RETURN_VALUE RETURN_LAST
 
         '''
 
 
         return_stmt ::= expr RETURN_VALUE
 
-        stmt ::= yield_stmt
-        yield_stmt ::= expr YIELD_STMT
-        yield_stmt ::= expr YIELD_STMT POP_TOP
-
-        yield_stmt ::= expr YIELD_VALUE
-        yield_stmt ::= expr YIELD_VALUE POP_TOP
-
         stmt ::= break_stmt
         break_stmt ::= BREAK_LOOP
         
                 POP_BLOCK LOAD_CONST COME_FROM
                 WITH_CLEANUP END_FINALLY
 
-        withasstmt ::= expr SETUP_WITH designator stmts
+        withasstmt ::= expr SETUP_WITH designator stmts_opt
                 POP_BLOCK LOAD_CONST COME_FROM
                 WITH_CLEANUP END_FINALLY
 
 
         forstmt ::= SETUP_LOOP expr _for designator
                 l_stmts_opt _jump_back
-                COME_FROM POP_BLOCK COME_FROM
+                POP_BLOCK COME_FROM
         forstmt ::= SETUP_LOOP expr _for designator
                 return_stmts 
-                COME_FROM POP_BLOCK COME_FROM
+                POP_BLOCK COME_FROM
 
         forelsestmt ::= SETUP_LOOP expr _for designator
                 l_stmts_opt _jump_back
-                COME_FROM POP_BLOCK stmts COME_FROM
+                POP_BLOCK stmts COME_FROM
         forelsestmt ::= SETUP_LOOP expr _for designator
                 return_stmts _come_from
-                COME_FROM POP_BLOCK stmts COME_FROM
+                POP_BLOCK stmts COME_FROM
 
         forelselaststmt ::= SETUP_LOOP expr _for designator
                 l_stmts_opt _jump_back
-                COME_FROM POP_BLOCK c_stmts COME_FROM
+                POP_BLOCK c_stmts COME_FROM
         forelselaststmt ::= SETUP_LOOP expr _for designator
                 return_stmts _come_from
-                COME_FROM POP_BLOCK c_stmts COME_FROM
+                POP_BLOCK c_stmts COME_FROM
 
         return_stmts ::= return_stmt
         return_stmts ::= _stmts return_stmt
         expr ::= slice1
         expr ::= slice2
         expr ::= slice3
+        expr ::= buildslice2
+        expr ::= buildslice3
+        expr ::= yield
+
         
         
         binary_expr ::= expr expr binary_op
         slice2 ::= expr expr DUP_TOPX_2 SLICE+2
         slice3 ::= expr expr expr SLICE+3
         slice3 ::= expr expr expr DUP_TOPX_3 SLICE+3
+        buildslice3 ::= expr expr expr BUILD_SLICE_3
+        buildslice2 ::= expr expr BUILD_SLICE_2
+        
+        yield ::= expr YIELD_VALUE
 
         _mklambda ::= load_closure mklambda
         _mklambda ::= mklambda
     #
     #    expr ::= {expr}^n BUILD_LIST_n
     #    expr ::= {expr}^n BUILD_TUPLE_n
-    #    expr ::= {expr}^n BUILD_SLICE_n
     #    unpack_list ::= UNPACK_LIST {expr}^n
     #    unpack ::= UNPACK_TUPLE {expr}^n
     #    unpack ::= UNPACK_SEQEUENE {expr}^n
         op = k[:string.rfind(k, '_')]
         if op in ('BUILD_LIST', 'BUILD_TUPLE', 'BUILD_SET'):
             rule = 'build_list ::= ' + 'expr '*v + k
-        elif op == 'BUILD_SLICE':
-            rule = 'expr ::= ' + 'expr '*v + k
         elif op in ('UNPACK_TUPLE', 'UNPACK_SEQUENCE'):
             rule = 'unpack ::= ' + k + ' designator'*v
         elif op == 'UNPACK_LIST':
                   ('expr '*v, k), nop)
             p.addRule('genexpr ::= %s load_closure LOAD_GENEXPR %s expr GET_ITER CALL_FUNCTION_1' %
                   ('expr '*v, k), nop)
+            p.addRule('setcomp ::= %s load_closure LOAD_SETCOMP %s expr GET_ITER CALL_FUNCTION_1' %
+                  ('expr '*v, k), nop)
             p.addRule('dictcomp ::= %s load_closure LOAD_DICTCOMP %s expr GET_ITER CALL_FUNCTION_1' %
                   ('expr '*v, k), nop)
             rule = 'mkfunc ::= %s load_closure LOAD_CONST %s' % ('expr '*v, k)

uncompyle/Scanner.py

 __all__ = ['Token', 'Scanner', 'getscanner']
 
 import types
+import dis
+
+globals().update(dis.opmap)
+
 
 class Token:
     """
     This is similar to the original code object, but additionally
     the diassembled code is stored in the attribute '_tokens'.
     """
-    def __init__(self, co, scanner):
+    def __init__(self, co, scanner, classname=None):
         for i in dir(co):
             if i.startswith('co_'):
                 setattr(self, i, getattr(co, i))
-        self._tokens, self._customize = scanner.disassemble(co)
+        self._tokens, self._customize = scanner.disassemble(co, classname)
 
 class Scanner:
     def __init__(self, version):
         from sys import version_info
         self.__pyversion = float('%d.%d' % version_info[0:2])
 
-        # use module 'dis' for this version
-        import dis.dis_files as dis_files
-        self.dis = dis_files.by_version[version]
         self.resetTokenClass()
 
-        dis = self.dis
         self.JUMP_OPs = map(lambda op: dis.opname[op],
                             dis.hasjrel + dis.hasjabs)
 
-        # setup an opmap if we don't have one
-        try:
-            dis.opmap
-        except:
-            opmap = {}
-            opname = dis.opname
-            for i in range(len(opname)):
-                opmap[opname[i]] = i
-            dis.opmap = opmap
         copmap = {}
         for i in range(len(dis.cmp_op)):
             copmap[dis.cmp_op[i]] = i
     def resetTokenClass(self):
         self.setTokenClass(Token)
         
-    def disassemble(self, co):
+    def disassemble(self, co, classname=None):
         """
         Disassemble a code object, returning a list of 'Token'.
 
         """
         rv = []
         customize = {}
-        dis = self.dis # shortcut
         Token = self.Token # shortcut
         code = co.co_code
         n = len(code)
             while j < start_byte:
                 self.lines.append((prev_line_no, start_byte))
                 j += 1
-            last_opname = dis.opname[ord(code[self.prev[start_byte]])]
-            if last_opname in ('POP_JUMP_IF_FALSE', 'POP_JUMP_IF_TRUE'):
+            last_op = ord(code[self.prev[start_byte]])
+            if last_op in (POP_JUMP_IF_FALSE, POP_JUMP_IF_TRUE):
                 self.if_lines[prev_line_no] = True
             else:
                 self.if_lines[prev_line_no] = False
         self.if_lines[prev_line_no] = False
         
         cf = self.find_jump_targets(code)
-        POP_JUMP_IF_FALSE = self.dis.opmap['POP_JUMP_IF_FALSE']
-        POP_JUMP_IF_TRUE  = self.dis.opmap['POP_JUMP_IF_TRUE']
+
+        if classname:
+            classname = '_' + classname.lstrip('_') + '__'
+            def unmangle(name):
+                if name.startswith(classname) and name[-2:] != '__':
+                    return name[len(classname) - 2:]
+                return name
+                
+            free = [ unmangle(name) for name in (co.co_cellvars + co.co_freevars) ]
+            names = [ unmangle(name) for name in co.co_names ]
+            varnames = [ unmangle(name) for name in co.co_varnames ]
+        else:
+            free = co.co_cellvars + co.co_freevars
+            names = co.co_names
+            varnames = co.co_varnames
 
         i = 0
         extended_arg = 0
-        free = None
         while i < n:
             offset = i
             k = 0
                                     offset="%s_%d" % (offset, k) ))
                     k += 1
                     
-#            if self.__end_if_line.has_key(offset):
-#                rv.append(Token('END_IF_LINE', None, repr(self.__end_if_line[offset]), 
-#                            offset="%s_" % offset ))
             c = code[i]
             op = ord(c)
             opname = dis.opname[op]
                     else:
                         pattr = const
                 elif op in dis.hasname:
-                    pattr = co.co_names[oparg]
+                    pattr = names[oparg]
                 elif op in dis.hasjrel:
                     pattr = repr(i + oparg)
                 elif op in dis.hasjabs:
                     pattr = repr(oparg)
                 elif op in dis.haslocal:
-                    pattr = co.co_varnames[oparg]
+                    pattr = varnames[oparg]
                 elif op in dis.hascompare:
                     pattr = dis.cmp_op[oparg]
                 elif op in dis.hasfree:
-                    if free is None:
-                        free = co.co_cellvars + co.co_freevars
                     pattr = free[oparg]
 
-            if opname == 'SET_LINENO':
-                continue
-            elif opname in ('BUILD_LIST', 'BUILD_TUPLE', 'BUILD_SLICE', 'BUILD_SET',
+            if opname in ('BUILD_LIST', 'BUILD_TUPLE', 'BUILD_SET', 'BUILD_SLICE',
                             'UNPACK_LIST', 'UNPACK_TUPLE', 'UNPACK_SEQUENCE',
                             'MAKE_FUNCTION', 'CALL_FUNCTION', 'MAKE_CLOSURE',
                             'CALL_FUNCTION_VAR', 'CALL_FUNCTION_KW',
                     continue
                 else:
                     opname = '%s_%d' % (opname, oparg)
-                    customize[opname] = oparg
-#            elif opname == 'POP_JUMP_IF_TRUE':
-#                target = self.__get_target(code, offset)
-#                if (dis.opname[ord(code[target])] == 'FOR_ITER') and (self.lines[offset] != self.lines[offset+3]):
-#                    opname = 'CONTINUE_IF_TRUE'
+                    if opname not in ('BUILD_SLICE_2', 'BUILD_SLICE_3'):
+                        customize[opname] = oparg
             elif opname == 'JUMP_ABSOLUTE':
                 target = self.__get_target(code, offset)
                 if target < offset:
         if op is None:
             op = ord(code[pos])
         target = ord(code[pos+1]) + ord(code[pos+2]) * 256
-        if op in self.dis.hasjrel:
+        if op in dis.hasjrel:
             target += pos + 3
         return target
 
         Return index to it or None if not found.
         """
 
-        assert(start>=0 and end<len(code))
+        assert(start>=0 and end<=len(code))
 
-        HAVE_ARGUMENT = self.dis.HAVE_ARGUMENT
+        HAVE_ARGUMENT = dis.HAVE_ARGUMENT
 
         try:    instr[0]
         except: instr = [instr]
         Return index to it or None if not found.
         """
 
-        if not (start>=0 and end<len(code)):
+        if not (start>=0 and end<=len(code)):
             return None
 
-        HAVE_ARGUMENT = self.dis.HAVE_ARGUMENT
+        HAVE_ARGUMENT = dis.HAVE_ARGUMENT
 
         try:    instr[0]
         except: instr = [instr]
         Return a list with indexes to them or [] if none found.
         """
 
-        assert(start>=0 and end<len(code))
+        assert(start>=0 and end<=len(code))
 
-        HAVE_ARGUMENT = self.dis.HAVE_ARGUMENT
+        HAVE_ARGUMENT = dis.HAVE_ARGUMENT
 
         try:    instr[0]
         except: instr = [instr]
         Return the next jump that was generated by an except SomeException:
         construct in a try...except...else clause or None if not found.
         """
-        HAVE_ARGUMENT = self.dis.HAVE_ARGUMENT
-        JUMP_FORWARD  = self.dis.opmap['JUMP_FORWARD']
-        JUMP_ABSOLUTE = self.dis.opmap['JUMP_ABSOLUTE']
-        END_FINALLY   = self.dis.opmap['END_FINALLY']
-        POP_TOP       = self.dis.opmap['POP_TOP']
-        DUP_TOP       = self.dis.opmap['DUP_TOP']
-        try:    SET_LINENO = self.dis.opmap['SET_LINENO']
-        except: SET_LINENO = None
+        HAVE_ARGUMENT = dis.HAVE_ARGUMENT
 
         lookup = [JUMP_ABSOLUTE, JUMP_FORWARD]
         while start < end:
             x = jmp+3
             while x <= end and pos < 4:
                 op = ord(code[x])
-                if op == SET_LINENO:
-                    x += 3
-                    continue
-                elif op >= HAVE_ARGUMENT:
+                if op >= HAVE_ARGUMENT:
                     break
                 ops[pos] = op
                 opp[pos] = x
             start = jmp + 3
         return None
 
-    def __list_comprehension(self, code, pos, op=None):
-        """
-        Determine if there is a list comprehension structure starting at pos
-        """
-        BUILD_LIST = self.dis.opmap['BUILD_LIST']
-        DUP_TOP    = self.dis.opmap['DUP_TOP']
-        LOAD_ATTR  = self.dis.opmap['LOAD_ATTR']
-        if op is None:
-            op = ord(code[pos])
-        if op != BUILD_LIST:
-            return 0
-        try:
-            elems = ord(code[pos+1]) + ord(code[pos+2])*256
-            codes = (op, elems, ord(code[pos+3]), ord(code[pos+4]))
-        except IndexError:
-            return 0
-        return (codes==(BUILD_LIST, 0, DUP_TOP, LOAD_ATTR))
-
-    def __ignore_if(self, code, pos):
-        """
-        Return true if this 'if' is to be ignored.
-        """
-        POP_TOP      = self.dis.opmap['POP_TOP']
-        COMPARE_OP   = self.dis.opmap['COMPARE_OP']
-        EXCEPT_MATCH = self.dis.copmap['exception match']
-
-        ## If that was added by a while loop
-        if pos in self.__ignored_ifs:
-            return 1
-
-        # Check if we can test only for POP_TOP for this -Dan
-        # Maybe need to be done as above (skip SET_LINENO's)
-        if (ord(code[pos-3])==COMPARE_OP and
-            (ord(code[pos-2]) + ord(code[pos-1])*256)==EXCEPT_MATCH and
-            ord(code[pos+3])==POP_TOP and
-            ord(code[pos+4])==POP_TOP and
-            ord(code[pos+5])==POP_TOP and
-            ord(code[pos+6])==POP_TOP):
-            return 1 ## Exception match
-        return 0
-
     def __fix_parent(self, code, target, parent):
         """Fix parent boundaries if needed"""
-        JUMP_ABSOLUTE = self.dis.opmap['JUMP_ABSOLUTE']
         start = parent['start']
         end = parent['end']
-        ## Map the second start point for 'while 1:' in python 2.3+ to start
-        try:    target = self.__while1[target]
-        except: pass
+
         if target >= start or end-start < 3 or target not in self.__loops:
             return
         if ord(code[end-3])==JUMP_ABSOLUTE:
 
         # TODO: check the struct boundaries more precisely -Dan
 
-        SETUP_LOOP    = self.dis.opmap['SETUP_LOOP']
-        BUILD_LIST    = self.dis.opmap['BUILD_LIST']
-        FOR_ITER      = self.dis.opmap['FOR_ITER']
-        GET_ITER      = self.dis.opmap['GET_ITER']
-        SETUP_EXCEPT  = self.dis.opmap['SETUP_EXCEPT']
-        JUMP_FORWARD  = self.dis.opmap['JUMP_FORWARD']
-        JUMP_ABSOLUTE = self.dis.opmap['JUMP_ABSOLUTE']
-        POP_JUMP_IF_FALSE = self.dis.opmap['POP_JUMP_IF_FALSE']
-        POP_JUMP_IF_TRUE  = self.dis.opmap['POP_JUMP_IF_TRUE']
-        JUMP_IF_FALSE_OR_POP = self.dis.opmap['JUMP_IF_FALSE_OR_POP']
-        JUMP_IF_TRUE_OR_POP = self.dis.opmap['JUMP_IF_TRUE_OR_POP']
-        END_FINALLY   = self.dis.opmap['END_FINALLY']
-        POP_TOP       = self.dis.opmap['POP_TOP']
-        POP_BLOCK       = self.dis.opmap['POP_BLOCK']
-        RETURN_VALUE = self.dis.opmap['RETURN_VALUE']
-        CONTINUE_LOOP = self.dis.opmap['CONTINUE_LOOP']
-        LOAD_ATTR = self.dis.opmap['LOAD_ATTR']
-        LOAD_FAST = self.dis.opmap['LOAD_FAST']
-        RAISE_VARARGS = self.dis.opmap['RAISE_VARARGS']
         # Ev remove this test and make op a mandatory argument -Dan
         if op is None:
             op = ord(code[pos])
 
         if op == SETUP_LOOP:
             start = pos+3
-#            if ord(code[start])==JUMP_FORWARD:
-                ## This is a while 1 (has a particular structure)
-#                start = self.__get_target(code, start, JUMP_FORWARD)
-#                start = self.__restrict_to_parent(start, parent)
-#                self.__while1[pos+3] = start ## map between the 2 start points
             target = self.__get_target(code, pos, op)
             end    = self.__restrict_to_parent(target, parent)
             if target != end:
                 (line_no, next_line_byte) = self.lines[pos]
                 test = self.prev[next_line_byte]
                 assert(test is not None)
-                self.__ignored_ifs.append(test)
                 test_target = self.__get_target(code, test)
                 if test_target > (jump_back+3):
                     jump_back = test_target
             self.__structs.append({'type': loop_type + '-else',
                                    'start': jump_back+3,
                                    'end':   end})
-        elif self.__list_comprehension(code, pos, op):
-            get_iter = self.__first_instr(code, pos+7, end, GET_ITER)
-            for_iter = self.__first_instr(code, get_iter, end, FOR_ITER)
-            assert(get_iter is not None and for_iter is not None)
-            start  = get_iter+1
-            target = self.__get_target(code, for_iter, FOR_ITER)
-            end    = self.__restrict_to_parent(target, parent)
-            jump_back = self.__last_instr(code, start, end, JUMP_ABSOLUTE,
-                                          start, False)
-            assert(jump_back is not None)
-            target = self.__get_target(code, jump_back, JUMP_ABSOLUTE)
-            start = self.__restrict_to_parent(target, parent)
-            self.__structs.append({'type': 'list-comprehension',
-                                   'start': start,
-                                   'end':   jump_back})
         elif op == SETUP_EXCEPT:
             start  = pos+3
             target = self.__get_target(code, pos, op)
        #         if target != end:
        #             self.__fixed_jumps[jmp] = end
                 i = jmp+3
-        elif op in (POP_JUMP_IF_FALSE, POP_JUMP_IF_TRUE):
 
-#            if self.__ignore_if(code, pos):
-#                return
+        elif op in (POP_JUMP_IF_FALSE, POP_JUMP_IF_TRUE):
             start = pos+3 
             target = self.__get_target(code, pos, op)
             rtarget = self.__restrict_to_parent(target, parent)
             if (ord(code[self.prev[target]]) in (JUMP_IF_FALSE_OR_POP, JUMP_IF_TRUE_OR_POP,
                     POP_JUMP_IF_FALSE, POP_JUMP_IF_TRUE)) and (target > pos):  
                 self.__fixed_jumps[pos] = self.prev[target]
-                if op == POP_JUMP_IF_TRUE:
-                    self.pjit_tgt[self.prev[target]] = True
                 return
                 
             #is this not at the end of a line
                             good_op = True
                     else:
                         if start < target < next_line_byte:
-                            if ord(code[self.prev[target]]) in (JUMP_ABSOLUTE, JUMP_FORWARD):
+                            if ord(code[self.prev[target]]) in (JUMP_ABSOLUTE, JUMP_FORWARD, RETURN_VALUE):
                                 good_op = True
                         while p_op in (JUMP_ABSOLUTE, JUMP_FORWARD, POP_BLOCK):
                             if p_op in (JUMP_ABSOLUTE, JUMP_FORWARD):
                              or ((ord(code[self.lines[j][1]-3]) == POP_JUMP_IF_TRUE)
                                  and (ord(code[self.__get_target(code, self.lines[j][1]-3)-3]) == POP_JUMP_IF_FALSE)
                                  and (self.__get_target(code, self.__get_target(code, self.lines[j][1]-3)-3) == target))))
-                       or (ord(code[self.prev[self.lines[j][1]]]) in (LOAD_ATTR, LOAD_FAST))):
+                       or (ord(code[self.prev[self.lines[j][1]]]) in (LOAD_ATTR, LOAD_FAST, JUMP_IF_FALSE_OR_POP, JUMP_IF_TRUE_OR_POP))):
                     if (self.if_lines.get(i, False) and (self.__get_target(code, self.lines[j][1]-3) == target)):
                         num_pj += 1
                     j = self.lines[j][1]
                     i = self.lines[j][0]
-                    if (ord(code[self.prev[j]]) not in (LOAD_ATTR, LOAD_FAST)):
+                    if (ord(code[self.prev[j]]) not in (LOAD_ATTR, LOAD_FAST, JUMP_IF_FALSE_OR_POP, JUMP_IF_TRUE_OR_POP)):
                         k = j
                 if k > next_line_byte:
                     if num_pj > 1 and target > pos:
                 self.__structs.append({'type':  'if-then',
                                        'start': start,
                                        'end':   rtarget})
-                
+        elif op in (JUMP_IF_FALSE_OR_POP, JUMP_IF_TRUE_OR_POP):
+            target = self.__get_target(code, pos, op)
+            if target > pos:
+                unop_target = self.__last_instr(code, pos, target, JUMP_FORWARD, target)
+                if unop_target and ord(code[unop_target+3]) != ROT_TWO:
+                    self.__fixed_jumps[pos] = unop_target
                 
                 
              
         This procedure is modelled after dis.findlables(), but here
         for each target the number of jumps are counted.
         """
-        HAVE_ARGUMENT = self.dis.HAVE_ARGUMENT
+        HAVE_ARGUMENT = dis.HAVE_ARGUMENT
 
-        hasjrel = self.dis.hasjrel
-        hasjabs = self.dis.hasjabs
+        hasjrel = dis.hasjrel
+        hasjabs = dis.hasjabs
 
         needFixing = (self.__pyversion >= 2.3)
 
                            'start': 0,
                            'end':   n-1}]
         self.__loops = []  ## All loop entry points
-        self.__while1 = {} ## 'while 1:' in python 2.3+ has another start point
         self.__fixed_jumps = {} ## Map fixed jumps to their real destination
-        self.__ignored_ifs = [] ## JUMP_IF_XXXX's we should ignore
-#        self.__end_if_line = {}
         self.__jump_back_else = {}
-        self.pjit_tgt = {}
-        POP_JUMP_IF_FALSE = self.dis.opmap['POP_JUMP_IF_FALSE']
-        POP_JUMP_IF_TRUE  = self.dis.opmap['POP_JUMP_IF_TRUE']
-        JUMP_IF_FALSE_OR_POP = self.dis.opmap['JUMP_IF_FALSE_OR_POP']
-        JUMP_IF_TRUE_OR_POP  = self.dis.opmap['JUMP_IF_TRUE_OR_POP']
-        JUMP_ABSOLUTE = self.dis.opmap['JUMP_ABSOLUTE']
-        JUMP_FORWARD = self.dis.opmap['JUMP_FORWARD']
-        lastif = self.__last_instr(code, 0, n-1, [POP_JUMP_IF_FALSE, POP_JUMP_IF_TRUE], n-4)
 
         targets = {}
         i = 0
                     
                 
                 if label is None:
-                    if op in hasjrel:
+                    if op in hasjrel and op != FOR_ITER:
                         label = i + 3 + oparg
                     elif op in hasjabs:
                         if op in [JUMP_IF_FALSE_OR_POP, JUMP_IF_TRUE_OR_POP]:

uncompyle/Walker.py

 INDENT_PER_LEVEL = ' ' # additional intent per pretty-print level
 
 TABLE_R = {
-    'build_tuple2':	( '%C', (0,-1,', ') ),
     'POP_TOP':		( '%|%c\n', 0 ),
     'STORE_ATTR':	( '%c.%[1]{pattr}', 0),
 #   'STORE_SUBSCR':	( '%c[%c]', 0, 1 ),
     'STORE_DEREF':	( '%{pattr}', ),
     'unpack':		( '(%C,)', (1, sys.maxint, ', ') ),
     'unpack_list':	( '[%C]', (1, sys.maxint, ', ') ),
+    'build_tuple2':	( '%P', (0,-1,', ', 100) ),
 
     #'list_compr':	( '[ %c ]', -2),	# handled by n_list_compr
     'list_iter':	( '%c', 0),
     'gen_comp_body':    ( '%c', 0 ),
     'dict_comp_body':   ( '%c:%c', 1, 0 ),
     
-    'assign':		( '%|%c = %c\n', -1, 0 ),
+    'assign':		( '%|%c = %p\n', -1, (0,200) ),
     'augassign1':	( '%|%c %c %c\n', 0, 2, 1),
     'augassign2':	( '%|%c.%[2]{pattr} %c %c\n', 0, -3, -4),
 #   'dup_topx':		( '%c', 0),
     'print_nl_to':	( '%|print >> %c\n', 0 ),
     'print_to_items':	( '%C', (0, 2, ', ') ),
 
-    'call_stmt':	( '%|%c\n', 0),
+    'call_stmt':	( '%|%p\n', (0,200)),
     'break_stmt':	( '%|break\n', ),
     'continue_stmt':	( '%|continue\n', ),
     'jcontinue_stmt':	( '%|continue\n', ),
     'raise_stmt':	( '%|raise %[0]C\n', (0,sys.maxint,', ') ),
-    'yield_stmt':	( '%|yield %c\n', 0),
+#    'yield':	( 'yield %c', 0),
 #    'return_stmt':	( '%|return %c\n', 0),
 
     'ifstmt':		( '%|if %c:\n%+%c%-', 0, 1 ),
     'while1stmt':	( '%|while 1:\n%+%c%-\n', 1 ),
     'whileelsestmt':	( '%|while %c:\n%+%c%-%|else:\n%+%c%-\n', 1, 2, -2 ),
     'whileelselaststmt':	( '%|while %c:\n%+%c%-%|else:\n%+%c%-\n', 1, 2, -2 ),
-    'while1elsestmt':	( '%|while 1:\n%+%c%-%|else:\n%+%c%-\n', 4, -2 ),
     'forstmt':		( '%|for %c in %c:\n%+%c%-\n', 3, 1, 4 ),
     'forelsestmt':	(
         '%|for %c in %c:\n%+%c%-%|else:\n%+%c%-\n', 3, 1, 4, -2),
     'forelselaststmt':	(
-        '%|for %c in %c:\n%+%c%-%|else:\n%+%c%-\n', 3, 1, 4, -2),
+        '%|for %c in %c:\n%+%c%-%|else:\n%+%c%-', 3, 1, 4, -2),
     'trystmt':		( '%|try:\n%+%c%-%c', 1, 5 ),
     'c_trystmt':		( '%|try:\n%+%c%-%c', 1, 5 ),
+    'tf_trystmt':		( '%c%-%c%+', 1, 5 ),
     'except':		( '%|except:\n%+%c%-', 3 ),
     'except2':		( '%|except:\n%+%c%-', 3 ),
     'except_cond1':	( '%|except %c:\n', 1 ),
     'except_else':	( '%|else:\n%+%c%-', 2 ),
     'except_else2':	( '%|else:\n%+%c%-', 1 ),
     'except_else3':	( '%|else:\n%+%c%-', 2 ),
-    'tryfinallystmt':	( '%|try:\n%+%c%-\n%|finally:\n%+%c%-\n', 1, 5 ),
+    'tryfinallystmt':	( '%|try:\n%+%c%-%|finally:\n%+%c%-', 1, 5 ),
     'withstmt':     ( '%|with %c:\n%+%c%-', 0, 3),
     'withasstmt':   ( '%|with %c as %c:\n%+%c%-', 0, 2, 3),
     'passstmt':		( '%|pass\n', ),
     'slice1':               2,
     'slice2':               2,
     'slice3':               2,
+    'buildslice2':          2,
+    'buildslice3':          2,
     'call_function':        2,
     
     'BINARY_POWER':         4,
     'conditionaland':       28,
     'conditionalnot':       28,
     
-    '_mklambda':            30
+    '_mklambda':            30,
+    'yield':                101
 }
 
 ASSIGN_TUPLE_PARAM = lambda param_name: \
         self.prec = 100
         self.return_none = False
         self.mod_globs = set()
+        self.currentclass = None
 
     f = property(lambda s: s.__params['f'],
                  lambda s, x: s.__params.__setitem__('f', x),
         print >> self.f
 
     def print_docstring(self, indent, docstring):
-
-        def unquote(quote, string):
-            unquote = '\\' + quote
-            while string.find(quote) >= 0:
-                    string = string.replace(quote, unquote)
-            return string
-       
-        if docstring.find('\\\n') or docstring.find('\n'): # multiline string
-            if docstring.find('"""') >=0:
-                quote = "'''"
-            else:
-                quote = '"""';
-            unquote(quote, docstring)
-            docstring = docstring.split('\n')
-            self.write(indent, quote)
-            for i in range(len(docstring)-1):
-                self.print_( repr(docstring[i])[1:-1] )
-            self.print_(repr(docstring[-1])[1:-1], quote)
+        quote = '"""'
+        self.write(indent)
+        if type(docstring) == unicode:
+            self.write('u')
+            docstring = repr(docstring.expandtabs())[2:-1]
+        else:
+            docstring = repr(docstring.expandtabs())[1:-1]            
+        
+        for (orig, replace) in (('\\\\', '\t'), 
+                                ('\\r\\n', '\n'),
+                                ('\\n', '\n'),
+                                ('\\r', '\n'),
+                                ('\\"', '"'),
+                                ("\\'", "'")):
+            docstring = docstring.replace(orig, replace)
+
+        #Do a raw string if there are backslashes but no other escaped characters:
+        #also check some edge cases
+        if ('\t' in docstring
+            and '\\' not in docstring
+            and len(docstring) >= 2
+            and docstring[-1] != '\t'
+            and (docstring[-1] != '"'
+                 or docstring[-2] == '\t')):
+            self.write('r') #raw string
+            #restore backslashes unescaped since raw
+            docstring = docstring.replace('\t', '\\')
+        else:
+            #Escape '"' if it's the last character, so it doesn't ruin the ending triple quote
+            if len(docstring) and docstring[-1] == '"':
+                docstring = docstring[:-1] + '\\"'
+            #Escape triple quote anywhere
+            docstring = docstring.replace('"""', '\\"\\"\\"')
+            #Restore escaped backslashes
+            docstring = docstring.replace('\t', '\\\\')
+        lines = docstring.split('\n')
+        calculate_indent = sys.maxint
+        for line in lines[1:]:
+            stripped = line.lstrip()
+            calculate_indent = min(calculate_indent, len(line) - len(stripped))
+        # Remove indentation (first line is special):
+        trimmed = [lines[0]]
+        if calculate_indent < sys.maxint:
+            trimmed += [line[calculate_indent:] for line in lines[1:]]
+
+        self.write(quote)
+        if len(trimmed) == 0:
+            self.print_(quote)
+        elif len(trimmed) == 1:
+            self.print_(trimmed[0], quote)
         else:
-            self.print_(indent, repr(docstring))
+            self.print_(trimmed[0])
+            for line in trimmed[1:-1]:
+                self.print_( indent, line )
+            self.print_(indent, trimmed[-1],quote)
+
             
     def n_return_stmt(self, node):
         if self.__params['isLambda']:
             self.print_()
             self.prune() # stop recursing
         
+    def n_yield(self, node):
+        self.write('yield')
+        if node != AST('yield', [NONE, Token('YIELD_VALUE')]):
+            self.write(' ')
+            self.preorder(node[0])
+        self.prune() # stop recursing
+
+    def n_buildslice3(self, node):
+        if node[0] != NONE:
+            self.preorder(node[0])
+        self.write(':')
+        if node[1] != NONE:
+            self.preorder(node[1])
+        self.write(':')
+        if node[2] != NONE:
+            self.preorder(node[2])
+        self.prune() # stop recursing
+
+    def n_buildslice2(self, node):
+        if node[0] != NONE:
+            self.preorder(node[0])
+        self.write(':')
+        if node[1] != NONE:
+            self.preorder(node[1])
+        self.prune() # stop recursing
+
 #    def n_l_stmts(self, node):
 #        if node[0] == '_stmts':
 #            if len(node[0]) >= 2 and node[0][1] == 'stmt':
 
 
     def n_delete_subscr(self, node):
-        maybe_tuple = node[-2][-1]
-        if maybe_tuple.type.startswith('BUILD_TUPLE'):
-            maybe_tuple.type = 'build_tuple2'
-        self.default(node)
+        if node[-2][0] == 'build_list' and node[-2][0][-1].type.startswith('BUILD_TUPLE'):
+            if node[-2][0][-1] != 'BUILD_TUPLE_0':
+                node[-2][0].type = 'build_tuple2'
+        self.default(node)        
+#        maybe_tuple = node[-2][-1]
+#        if maybe_tuple.type.startswith('BUILD_TUPLE'):
+#            maybe_tuple.type = 'build_tuple2'
+#        self.default(node)
 
     n_store_subscr = n_binary_subscr = n_delete_subscr
         
-
+#    'tryfinallystmt':	( '%|try:\n%+%c%-%|finally:\n%+%c%-', 1, 5 ),
+    def n_tryfinallystmt(self, node):
+        if node[1] == 'stmts' and \
+           len(node[1]) == 1 and \
+           node[1][0] == 'sstmt' and \
+           node[1][0][0] == 'stmt' and \
+           node[1][0][0][0] == 'trystmt' or node[1][0][0] == 'c_trystmt':
+            node[1][0][0][0].type = 'tf_trystmt'
+        self.default(node)
+        
     def n_exec_stmt(self, node):
         """
         exec_stmt ::= expr exprlist DUP_TOP EXEC_STMT
         self.write( ' ]')
         self.prune() # stop recursing
         self.prec = p
-
+    
     def comprehension_walk(self, node, iter_index):
         p = self.prec
         self.prec = 100
         code = node[-5].attr
 
         assert type(code) == CodeType
-        code = Code(code, self.scanner)
+        code = Code(code, self.scanner, self.currentclass)
         #assert isinstance(code, Code)
 
         ast = self.build_ast(code._tokens, code._customize)
 
     n_dictcomp = n_setcomp
        
-
+    
     def n_classdef(self, node):
         # class definition ('class X(A,B,C):')
-        assert node[0].pattr == node[-1][-1].pattr
-        self.print_()
-        self.write(self.indent, 'class ', str(node[-1][-1].pattr))
-        self.print_super_classes(node)
-        self.print_(':')
-
-        # class body
-        self.indentMore()
-        self.build_class(node[-4][-2].attr)
-        self.indentLess()
-        self.prune()
+        cclass = self.currentclass
+        self.currentclass = str(node[0].pattr)
 
-    def n_classdefdeco2(self, node):
-        # class definition ('class X(A,B,C):')
         self.print_()
-        self.write(self.indent, 'class ', str(node[0].pattr))
+        self.write(self.indent, 'class ', self.currentclass)
         self.print_super_classes(node)
         self.print_(':')
-
+        
         # class body
         self.indentMore()
-        self.build_class(node[-3][-2].attr)
+        self.build_class(node[2][-2].attr)
         self.indentLess()
         self.prune()
+        
+        self.currentclass = cclass
+
+    n_classdefdeco2 = n_classdef
 
     def print_super_classes(self, node):
         node = node[1][0]
         code = node[-2].attr
 
         assert type(code) == CodeType
-        code = Code(code, self.scanner)
+        code = Code(code, self.scanner, self.currentclass)
         #assert isinstance(code, Code)
 
         # add defaults values to parameter names
         paramnames.reverse(); defparams.reverse()
 
         try:
-            ast = self.build_ast(code._tokens, code._customize, isLambda = isLambda, noneInNames = ('None' in code.co_names))
+            ast = self.build_ast(code._tokens,
+                                 code._customize,
+                                 isLambda = isLambda,
+                                 noneInNames = ('None' in code.co_names))
         except ParserError as p:
             self.write( str(p))
             self.ERROR = p
         """Dump class definition, doc string and class body."""
 
         assert type(code) == CodeType
-        code = Code(code, self.scanner)
+        code = Code(code, self.scanner, self.currentclass)
         #assert isinstance(code, Code)
 
         indent = self.indent
         # if docstring exists, dump it
         if code.co_consts and code.co_consts[0] != None and ast[0][0] == ASSIGN_DOC_STRING(code.co_consts[0]):
             self.print_docstring(indent, code.co_consts[0])
+            self.print_()
             del ast[0]
         
 

uncompyle/__init__.py

     magic = fp.read(4)
     try:
         version = magics.versions[magic]
-        # marshal = marshal_files.import_(magic=magic)
     except KeyError:
-#        raise ImportError, "Unknown magic number in %s" % filename
-        version = '2.7'
+        raise ImportError, "Unknown magic number %s in %s" % (ord(magic[0])+256*ord(magic[1]), filename)
+    if version != '2.7':
+        raise ImportError, "This is a Python %s file! Only Python 2.7 files are supported."
     #print version
     fp.read(4) # timestamp
     co = marshal.load(fp)
         dir = os.path.dirname(outfile)
         failed_file = outfile + '_failed'
         if os.path.exists(failed_file): os.remove(failed_file)
-        if not os.path.exists(dir):
-            try:
-                os.makedirs(dir)
-            except:
-                raise "Can't create output dir '%s'" % dir
+        try:
+            os.makedirs(dir)
+        except OSError:
+            pass
         return open(outfile, 'w')
 
     of = outfile
             raise
         except:
             failed_files += 1
-            sys.stderr.write("### Can't uncompyle  %s\n" % infile)
+            sys.stderr.write("### Can't uncompyle %s\n" % infile)
             if outfile:
                 outstream.close()
                 os.rename(outfile, outfile + '_failed')
-                import traceback
-                traceback.print_exc()
+            import traceback
+            traceback.print_exc()
             #raise
 	else: # uncompyle successfull
             if outfile:

uncompyle/dis/__init__.py

Empty file removed.

uncompyle/dis/dis_15.py

-"""Disassembler of Python byte code into mnemonics."""
-
-import sys
-import string
-import types
-
-def dis(x=None):
-	"""Disassemble classes, methods, functions, or code.
-
-	With no argument, disassemble the last traceback.
-
-	"""
-	if not x:
-		distb()
-		return
-	if type(x) is types.InstanceType:
-		x = x.__class__
-	if hasattr(x, '__dict__'):
-		items = x.__dict__.items()
-		items.sort()
-		for name, x1 in items:
-			if type(x1) in (types.MethodType,
-					types.FunctionType,
-					types.CodeType):
-				print "Disassembly of %s:" % name
-				try:
-					dis(x1)
-				except TypeError, msg:
-					print "Sorry:", msg
-				print
-	else:
-		if hasattr(x, 'im_func'):
-			x = x.im_func
-		if hasattr(x, 'func_code'):
-			x = x.func_code
-		if hasattr(x, 'co_code'):
-			disassemble(x)
-		else:
-			raise TypeError, \
-			      "don't know how to disassemble %s objects" % \
-			      type(x).__name__
-
-def distb(tb=None):
-	"""Disassemble a traceback (default: last traceback)."""
-	if not tb:
-		try:
-			tb = sys.last_traceback
-		except AttributeError:
-			raise RuntimeError, "no last traceback to disassemble"
-		while tb.tb_next: tb = tb.tb_next
-	disassemble(tb.tb_frame.f_code, tb.tb_lasti)
-
-def disassemble(co, lasti=-1):
-	"""Disassemble a code object."""
-	code = co.co_code
-	labels = findlabels(code)
-	n = len(code)
-	i = 0
-	while i < n:
-		c = code[i]
-		op = ord(c)
-		if op == SET_LINENO and i > 0: print # Extra blank line
-		if i == lasti: print '-->',
-		else: print '   ',
-		if i in labels: print '>>',
-		else: print '  ',
-		print string.rjust(`i`, 4),
-		print string.ljust(opname[op], 15),
-		i = i+1
-		if op >= HAVE_ARGUMENT:
-			oparg = ord(code[i]) + ord(code[i+1])*256
-			i = i+2
-			print string.rjust(`oparg`, 5),
-			if op in hasconst:
-				print '(' + `co.co_consts[oparg]` + ')',
-			elif op in hasname:
-				print '(' + co.co_names[oparg] + ')',
-			elif op in hasjrel:
-				print '(to ' + `i + oparg` + ')',
-			elif op in haslocal:
-				print '(' + co.co_varnames[oparg] + ')',
-			elif op in hascompare:
-				print '(' + cmp_op[oparg] + ')',
-		print
-
-disco = disassemble
-
-def findlabels(code):
-	"""Detect all offsets in a byte code which are jump targets.
-
-	Return the list of offsets.
-
-	"""
-	labels = []
-	n = len(code)
-	i = 0
-	while i < n:
-		c = code[i]
-		op = ord(c)
-		i = i+1
-		if op >= HAVE_ARGUMENT:
-			oparg = ord(code[i]) + ord(code[i+1])*256
-			i = i+2
-			label = -1
-			if op in hasjrel:
-				label = i+oparg
-			elif op in hasjabs:
-				label = oparg
-			if label >= 0:
-				if label not in labels:
-					labels.append(label)
-	return labels
-
-cmp_op = ('<', '<=', '==', '!=', '>', '>=', 'in', 'not in', 'is',
-        'is not', 'exception match', 'BAD')
-
-hasconst = []
-hasname = []
-hasjrel = []
-hasjabs = []
-haslocal = []
-hascompare = []
-
-opname = [''] * 256
-for op in range(256): opname[op] = '<' + `op` + '>'
-
-def def_op(name, op):
-	opname[op] = name
-
-def name_op(name, op):
-	opname[op] = name
-	hasname.append(op)
-
-def jrel_op(name, op):
-	opname[op] = name
-	hasjrel.append(op)
-
-def jabs_op(name, op):
-	opname[op] = name
-	hasjabs.append(op)
-
-# Instruction opcodes for compiled code
-
-def_op('STOP_CODE', 0)
-def_op('POP_TOP', 1)
-def_op('ROT_TWO', 2)
-def_op('ROT_THREE', 3)
-def_op('DUP_TOP', 4)
-
-def_op('UNARY_POSITIVE', 10)
-def_op('UNARY_NEGATIVE', 11)
-def_op('UNARY_NOT', 12)
-def_op('UNARY_CONVERT', 13)
-
-def_op('UNARY_INVERT', 15)
-
-def_op('BINARY_POWER', 19)
-
-def_op('BINARY_MULTIPLY', 20)
-def_op('BINARY_DIVIDE', 21)
-def_op('BINARY_MODULO', 22)
-def_op('BINARY_ADD', 23)
-def_op('BINARY_SUBTRACT', 24)
-def_op('BINARY_SUBSCR', 25)
-
-def_op('SLICE+0', 30)
-def_op('SLICE+1', 31)
-def_op('SLICE+2', 32)
-def_op('SLICE+3', 33)
-
-def_op('STORE_SLICE+0', 40)
-def_op('STORE_SLICE+1', 41)
-def_op('STORE_SLICE+2', 42)
-def_op('STORE_SLICE+3', 43)
-
-def_op('DELETE_SLICE+0', 50)
-def_op('DELETE_SLICE+1', 51)
-def_op('DELETE_SLICE+2', 52)
-def_op('DELETE_SLICE+3', 53)
-
-def_op('STORE_SUBSCR', 60)
-def_op('DELETE_SUBSCR', 61)
-
-def_op('BINARY_LSHIFT', 62)
-def_op('BINARY_RSHIFT', 63)
-def_op('BINARY_AND', 64)
-def_op('BINARY_XOR', 65)
-def_op('BINARY_OR', 66)
-
-def_op('PRINT_EXPR', 70)
-def_op('PRINT_ITEM', 71)
-def_op('PRINT_NEWLINE', 72)
-
-def_op('BREAK_LOOP', 80)
-
-def_op('LOAD_LOCALS', 82)
-def_op('RETURN_VALUE', 83)
-
-def_op('EXEC_STMT', 85)
-
-def_op('POP_BLOCK', 87)
-def_op('END_FINALLY', 88)
-def_op('BUILD_CLASS', 89)
-
-HAVE_ARGUMENT = 90		# Opcodes from here have an argument: 
-
-name_op('STORE_NAME', 90)	# Index in name list 
-name_op('DELETE_NAME', 91)	# "" 
-def_op('UNPACK_TUPLE', 92)	# Number of tuple items 
-def_op('UNPACK_LIST', 93)	# Number of list items 
-name_op('STORE_ATTR', 95)	# Index in name list 
-name_op('DELETE_ATTR', 96)	# ""
-name_op('STORE_GLOBAL', 97)	# ""
-name_op('DELETE_GLOBAL', 98)	# ""
-
-def_op('LOAD_CONST', 100)	# Index in const list 
-hasconst.append(100)
-name_op('LOAD_NAME', 101)	# Index in name list 
-def_op('BUILD_TUPLE', 102)	# Number of tuple items 
-def_op('BUILD_LIST', 103)	# Number of list items 
-def_op('BUILD_MAP', 104)	# Always zero for now 
-name_op('LOAD_ATTR', 105)	# Index in name list 
-def_op('COMPARE_OP', 106)	# Comparison operator 
-hascompare.append(106)
-name_op('IMPORT_NAME', 107)	# Index in name list 
-name_op('IMPORT_FROM', 108)	# Index in name list 
-
-jrel_op('JUMP_FORWARD', 110)	# Number of bytes to skip 
-jrel_op('JUMP_IF_FALSE', 111)	# "" 
-jrel_op('JUMP_IF_TRUE', 112)	# "" 
-jabs_op('JUMP_ABSOLUTE', 113)	# Target byte offset from beginning of code 
-jrel_op('FOR_LOOP', 114)	# Number of bytes to skip 
-
-name_op('LOAD_GLOBAL', 116)	# Index in name list
-
-jrel_op('SETUP_LOOP', 120)	# Distance to target address
-jrel_op('SETUP_EXCEPT', 121)	# ""
-jrel_op('SETUP_FINALLY', 122)	# ""
-
-def_op('LOAD_FAST', 124)	# Local variable number
-haslocal.append(124)
-def_op('STORE_FAST', 125)	# Local variable number
-haslocal.append(125)
-def_op('DELETE_FAST', 126)	# Local variable number
-haslocal.append(126)
-
-def_op('SET_LINENO', 127)	# Current line number
-SET_LINENO = 127
-
-def_op('RAISE_VARARGS', 130)
-def_op('CALL_FUNCTION', 131)
-def_op('MAKE_FUNCTION', 132)
-def_op('BUILD_SLICE', 133)

uncompyle/dis/dis_16.py

-"""Disassembler of Python byte code into mnemonics."""
-
-import sys
-import string
-import types
-
-def dis(x=None):
-	"""Disassemble classes, methods, functions, or code.
-
-	With no argument, disassemble the last traceback.
-
-	"""
-	if not x:
-		distb()
-		return
-	if type(x) is types.InstanceType:
-		x = x.__class__
-	if hasattr(x, '__dict__'):
-		items = x.__dict__.items()
-		items.sort()
-		for name, x1 in items:
-			if type(x1) in (types.MethodType,
-					types.FunctionType,
-					types.CodeType):
-				print "Disassembly of %s:" % name
-				try:
-					dis(x1)
-				except TypeError, msg:
-					print "Sorry:", msg
-				print
-	else:
-		if hasattr(x, 'im_func'):
-			x = x.im_func
-		if hasattr(x, 'func_code'):
-			x = x.func_code
-		if hasattr(x, 'co_code'):
-			disassemble(x)
-		else:
-			raise TypeError, \
-			      "don't know how to disassemble %s objects" % \
-			      type(x).__name__
-
-def distb(tb=None):
-	"""Disassemble a traceback (default: last traceback)."""
-	if not tb:
-		try:
-			tb = sys.last_traceback
-		except AttributeError:
-			raise RuntimeError, "no last traceback to disassemble"
-		while tb.tb_next: tb = tb.tb_next
-	disassemble(tb.tb_frame.f_code, tb.tb_lasti)
-
-def disassemble(co, lasti=-1):
-	"""Disassemble a code object."""
-	code = co.co_code
-	labels = findlabels(code)
-	n = len(code)
-	i = 0
-	while i < n:
-		c = code[i]
-		op = ord(c)
-		if op == SET_LINENO and i > 0: print # Extra blank line
-		if i == lasti: print '-->',
-		else: print '   ',
-		if i in labels: print '>>',
-		else: print '  ',
-		print string.rjust(`i`, 4),
-		print string.ljust(opname[op], 20),
-		i = i+1
-		if op >= HAVE_ARGUMENT:
-			oparg = ord(code[i]) + ord(code[i+1])*256
-			i = i+2
-			print string.rjust(`oparg`, 5),
-			if op in hasconst:
-				print '(' + `co.co_consts[oparg]` + ')',
-			elif op in hasname:
-				print '(' + co.co_names[oparg] + ')',
-			elif op in hasjrel:
-				print '(to ' + `i + oparg` + ')',
-			elif op in haslocal:
-				print '(' + co.co_varnames[oparg] + ')',
-			elif op in hascompare:
-				print '(' + cmp_op[oparg] + ')',
-		print
-
-disco = disassemble			# XXX For backwards compatibility
-
-def findlabels(code):
-	"""Detect all offsets in a byte code which are jump targets.
-
-	Return the list of offsets.
-
-	"""
-	labels = []
-	n = len(code)
-	i = 0
-	while i < n:
-		c = code[i]
-		op = ord(c)
-		i = i+1
-		if op >= HAVE_ARGUMENT:
-			oparg = ord(code[i]) + ord(code[i+1])*256
-			i = i+2
-			label = -1
-			if op in hasjrel:
-				label = i+oparg
-			elif op in hasjabs:
-				label = oparg
-			if label >= 0:
-				if label not in labels:
-					labels.append(label)
-	return labels
-
-cmp_op = ('<', '<=', '==', '!=', '>', '>=', 'in', 'not in', 'is',
-        'is not', 'exception match', 'BAD')
-
-hasconst = []
-hasname = []
-hasjrel = []
-hasjabs = []
-haslocal = []
-hascompare = []
-
-opname = [''] * 256
-for op in range(256): opname[op] = '<' + `op` + '>'
-
-def def_op(name, op):
-	opname[op] = name
-
-def name_op(name, op):
-	opname[op] = name
-	hasname.append(op)
-
-def jrel_op(name, op):
-	opname[op] = name
-	hasjrel.append(op)
-
-def jabs_op(name, op):
-	opname[op] = name
-	hasjabs.append(op)
-
-# Instruction opcodes for compiled code
-
-def_op('STOP_CODE', 0)
-def_op('POP_TOP', 1)
-def_op('ROT_TWO', 2)
-def_op('ROT_THREE', 3)
-def_op('DUP_TOP', 4)
-
-def_op('UNARY_POSITIVE', 10)
-def_op('UNARY_NEGATIVE', 11)
-def_op('UNARY_NOT', 12)
-def_op('UNARY_CONVERT', 13)
-
-def_op('UNARY_INVERT', 15)
-
-def_op('BINARY_POWER', 19)
-
-def_op('BINARY_MULTIPLY', 20)
-def_op('BINARY_DIVIDE', 21)
-def_op('BINARY_MODULO', 22)
-def_op('BINARY_ADD', 23)
-def_op('BINARY_SUBTRACT', 24)
-def_op('BINARY_SUBSCR', 25)
-
-def_op('SLICE+0', 30)
-def_op('SLICE+1', 31)
-def_op('SLICE+2', 32)
-def_op('SLICE+3', 33)
-
-def_op('STORE_SLICE+0', 40)
-def_op('STORE_SLICE+1', 41)
-def_op('STORE_SLICE+2', 42)
-def_op('STORE_SLICE+3', 43)
-
-def_op('DELETE_SLICE+0', 50)
-def_op('DELETE_SLICE+1', 51)
-def_op('DELETE_SLICE+2', 52)
-def_op('DELETE_SLICE+3', 53)
-
-def_op('STORE_SUBSCR', 60)
-def_op('DELETE_SUBSCR', 61)
-
-def_op('BINARY_LSHIFT', 62)
-def_op('BINARY_RSHIFT', 63)
-def_op('BINARY_AND', 64)
-def_op('BINARY_XOR', 65)
-def_op('BINARY_OR', 66)
-
-def_op('PRINT_EXPR', 70)
-def_op('PRINT_ITEM', 71)
-def_op('PRINT_NEWLINE', 72)
-
-def_op('BREAK_LOOP', 80)
-
-def_op('LOAD_LOCALS', 82)
-def_op('RETURN_VALUE', 83)
-
-def_op('EXEC_STMT', 85)
-
-def_op('POP_BLOCK', 87)
-def_op('END_FINALLY', 88)
-def_op('BUILD_CLASS', 89)
-
-HAVE_ARGUMENT = 90		# Opcodes from here have an argument: 
-
-name_op('STORE_NAME', 90)	# Index in name list 
-name_op('DELETE_NAME', 91)	# "" 
-def_op('UNPACK_TUPLE', 92)	# Number of tuple items 
-def_op('UNPACK_LIST', 93)	# Number of list items 
-name_op('STORE_ATTR', 95)	# Index in name list 
-name_op('DELETE_ATTR', 96)	# ""
-name_op('STORE_GLOBAL', 97)	# ""
-name_op('DELETE_GLOBAL', 98)	# ""
-
-def_op('LOAD_CONST', 100)	# Index in const list 
-hasconst.append(100)
-name_op('LOAD_NAME', 101)	# Index in name list 
-def_op('BUILD_TUPLE', 102)	# Number of tuple items 
-def_op('BUILD_LIST', 103)	# Number of list items 
-def_op('BUILD_MAP', 104)	# Always zero for now 
-name_op('LOAD_ATTR', 105)	# Index in name list 
-def_op('COMPARE_OP', 106)	# Comparison operator 
-hascompare.append(106)
-name_op('IMPORT_NAME', 107)	# Index in name list 
-name_op('IMPORT_FROM', 108)	# Index in name list 
-
-jrel_op('JUMP_FORWARD', 110)	# Number of bytes to skip 
-jrel_op('JUMP_IF_FALSE', 111)	# "" 
-jrel_op('JUMP_IF_TRUE', 112)	# "" 
-jabs_op('JUMP_ABSOLUTE', 113)	# Target byte offset from beginning of code 
-jrel_op('FOR_LOOP', 114)	# Number of bytes to skip 
-
-name_op('LOAD_GLOBAL', 116)	# Index in name list
-
-jrel_op('SETUP_LOOP', 120)	# Distance to target address
-jrel_op('SETUP_EXCEPT', 121)	# ""
-jrel_op('SETUP_FINALLY', 122)	# ""
-
-def_op('LOAD_FAST', 124)	# Local variable number
-haslocal.append(124)
-def_op('STORE_FAST', 125)	# Local variable number
-haslocal.append(125)
-def_op('DELETE_FAST', 126)	# Local variable number
-haslocal.append(126)
-
-def_op('SET_LINENO', 127)	# Current line number
-SET_LINENO = 127
-
-def_op('RAISE_VARARGS', 130)    # Number of raise arguments (1, 2, or 3)
-def_op('CALL_FUNCTION', 131)    # #args + (#kwargs << 8)
-def_op('MAKE_FUNCTION', 132)    # Number of args with default values
-def_op('BUILD_SLICE', 133)      # Number of items
-
-def_op('CALL_FUNCTION_VAR', 140)     # #args + (#kwargs << 8)
-def_op('CALL_FUNCTION_KW', 141)      # #args + (#kwargs << 8)
-def_op('CALL_FUNCTION_VAR_KW', 142)  # #args + (#kwargs << 8)
-
-
-def _test():
-	"""Simple test program to disassemble a file."""
-	if sys.argv[1:]:
-		if sys.argv[2:]:
-			sys.stderr.write("usage: python dis.py [-|file]\n")
-			sys.exit(2)
-		fn = sys.argv[1]
-		if not fn or fn == "-":
-			fn = None
-	else:
-		fn = None
-	if not fn:
-		f = sys.stdin
-	else:
-		f = open(fn)
-	source = f.read()
-	if fn:
-		f.close()
-	else:
-		fn = "<stdin>"
-	code = compile(source, fn, "exec")
-	dis(code)
-
-if __name__ == "__main__":
-	_test()

uncompyle/dis/dis_20.py

-"""Disassembler of Python byte code into mnemonics."""
-
-import sys
-import string
-import types
-
-def dis(x=None):
-	"""Disassemble classes, methods, functions, or code.
-
-	With no argument, disassemble the last traceback.
-
-	"""
-	if not x:
-		distb()
-		return
-	if type(x) is types.InstanceType:
-		x = x.__class__
-	if hasattr(x, '__dict__'):
-		items = x.__dict__.items()
-		items.sort()
-		for name, x1 in items:
-			if type(x1) in (types.MethodType,
-					types.FunctionType,
-					types.CodeType):
-				print "Disassembly of %s:" % name
-				try:
-					dis(x1)
-				except TypeError, msg:
-					print "Sorry:", msg
-				print
-	else:
-		if hasattr(x, 'im_func'):
-			x = x.im_func
-		if hasattr(x, 'func_code'):
-			x = x.func_code
-		if hasattr(x, 'co_code'):
-			disassemble(x)
-		else:
-			raise TypeError, \
-			      "don't know how to disassemble %s objects" % \
-			      type(x).__name__
-
-def distb(tb=None):
-	"""Disassemble a traceback (default: last traceback)."""
-	if not tb:
-		try:
-			tb = sys.last_traceback
-		except AttributeError:
-			raise RuntimeError, "no last traceback to disassemble"
-		while tb.tb_next: tb = tb.tb_next
-	disassemble(tb.tb_frame.f_code, tb.tb_lasti)
-
-def disassemble(co, lasti=-1):
-	"""Disassemble a code object."""
-	code = co.co_code
-	labels = findlabels(code)
-	n = len(code)
-	i = 0
-	extended_arg = 0
-	while i < n:
-		c = code[i]
-		op = ord(c)
-		if op == SET_LINENO and i > 0: print # Extra blank line
-		if i == lasti: print '-->',
-		else: print '   ',
-		if i in labels: print '>>',
-		else: print '  ',
-		print string.rjust(`i`, 4),
-		print string.ljust(opname[op], 20),
-		i = i+1
-		if op >= HAVE_ARGUMENT:
-			oparg = ord(code[i]) + ord(code[i+1])*256 + extended_arg
-			extended_arg = 0
-			i = i+2
-			if op == EXTENDED_ARG:
-				extended_arg = oparg*65536L
-			print string.rjust(`oparg`, 5),
-			if op in hasconst:
-				print '(' + `co.co_consts[oparg]` + ')',
-			elif op in hasname:
-				print '(' + co.co_names[oparg] + ')',
-			elif op in hasjrel:
-				print '(to ' + `i + oparg` + ')',
-			elif op in haslocal:
-				print '(' + co.co_varnames[oparg] + ')',
-			elif op in hascompare:
-				print '(' + cmp_op[oparg] + ')',
-		print
-
-disco = disassemble			# XXX For backwards compatibility
-
-def findlabels(code):
-	"""Detect all offsets in a byte code which are jump targets.
-
-	Return the list of offsets.
-
-	"""
-	labels = []
-	n = len(code)
-	i = 0
-	while i < n:
-		c = code[i]
-		op = ord(c)
-		i = i+1
-		if op >= HAVE_ARGUMENT:
-			oparg = ord(code[i]) + ord(code[i+1])*256
-			i = i+2
-			label = -1
-			if op in hasjrel:
-				label = i+oparg
-			elif op in hasjabs:
-				label = oparg
-			if label >= 0:
-				if label not in labels:
-					labels.append(label)
-	return labels
-
-cmp_op = ('<', '<=', '==', '!=', '>', '>=', 'in', 'not in', 'is',
-        'is not', 'exception match', 'BAD')
-
-hasconst = []
-hasname = []
-hasjrel = []
-hasjabs = []
-haslocal = []
-hascompare = []
-
-opname = [''] * 256
-for op in range(256): opname[op] = '<' + `op` + '>'
-
-def def_op(name, op):
-	opname[op] = name
-
-def name_op(name, op):
-	opname[op] = name
-	hasname.append(op)
-
-def jrel_op(name, op):
-	opname[op] = name
-	hasjrel.append(op)
-
-def jabs_op(name, op):
-	opname[op] = name
-	hasjabs.append(op)
-
-# Instruction opcodes for compiled code
-
-def_op('STOP_CODE', 0)
-def_op('POP_TOP', 1)
-def_op('ROT_TWO', 2)
-def_op('ROT_THREE', 3)
-def_op('DUP_TOP', 4)
-def_op('ROT_FOUR', 5)
-
-def_op('UNARY_POSITIVE', 10)
-def_op('UNARY_NEGATIVE', 11)
-def_op('UNARY_NOT', 12)
-def_op('UNARY_CONVERT', 13)
-
-def_op('UNARY_INVERT', 15)
-
-def_op('BINARY_POWER', 19)
-
-def_op('BINARY_MULTIPLY', 20)
-def_op('BINARY_DIVIDE', 21)
-def_op('BINARY_MODULO', 22)
-def_op('BINARY_ADD', 23)
-def_op('BINARY_SUBTRACT', 24)
-def_op('BINARY_SUBSCR', 25)
-
-def_op('SLICE+0', 30)
-def_op('SLICE+1', 31)
-def_op('SLICE+2', 32)
-def_op('SLICE+3', 33)
-
-def_op('STORE_SLICE+0', 40)
-def_op('STORE_SLICE+1', 41)
-def_op('STORE_SLICE+2', 42)
-def_op('STORE_SLICE+3', 43)
-
-def_op('DELETE_SLICE+0', 50)
-def_op('DELETE_SLICE+1', 51)
-def_op('DELETE_SLICE+2', 52)
-def_op('DELETE_SLICE+3', 53)
-
-def_op('INPLACE_ADD', 55)
-def_op('INPLACE_SUBTRACT', 56)
-def_op('INPLACE_MULTIPLY', 57)
-def_op('INPLACE_DIVIDE', 58)
-def_op('INPLACE_MODULO', 59)
-def_op('STORE_SUBSCR', 60)
-def_op('DELETE_SUBSCR', 61)
-
-def_op('BINARY_LSHIFT', 62)
-def_op('BINARY_RSHIFT', 63)
-def_op('BINARY_AND', 64)
-def_op('BINARY_XOR', 65)
-def_op('BINARY_OR', 66)
-def_op('INPLACE_POWER', 67)
-
-def_op('PRINT_EXPR', 70)
-def_op('PRINT_ITEM', 71)
-def_op('PRINT_NEWLINE', 72)
-def_op('PRINT_ITEM_TO', 73)
-def_op('PRINT_NEWLINE_TO', 74)
-def_op('INPLACE_LSHIFT', 75)
-def_op('INPLACE_RSHIFT', 76)
-def_op('INPLACE_AND', 77)
-def_op('INPLACE_XOR', 78)
-def_op('INPLACE_OR', 79)
-def_op('BREAK_LOOP', 80)
-
-def_op('LOAD_LOCALS', 82)
-def_op('RETURN_VALUE', 83)
-def_op('IMPORT_STAR', 84)
-def_op('EXEC_STMT', 85)
-
-def_op('POP_BLOCK', 87)
-def_op('END_FINALLY', 88)
-def_op('BUILD_CLASS', 89)
-
-HAVE_ARGUMENT = 90		# Opcodes from here have an argument: 
-
-name_op('STORE_NAME', 90)	# Index in name list 
-name_op('DELETE_NAME', 91)	# "" 
-def_op('UNPACK_SEQUENCE', 92)	# Number of tuple items 
-
-name_op('STORE_ATTR', 95)	# Index in name list 
-name_op('DELETE_ATTR', 96)	# ""
-name_op('STORE_GLOBAL', 97)	# ""
-name_op('DELETE_GLOBAL', 98)	# ""
-def_op('DUP_TOPX', 99)		# number of items to duplicate
-def_op('LOAD_CONST', 100)	# Index in const list 
-hasconst.append(100)
-name_op('LOAD_NAME', 101)	# Index in name list 
-def_op('BUILD_TUPLE', 102)	# Number of tuple items 
-def_op('BUILD_LIST', 103)	# Number of list items 
-def_op('BUILD_MAP', 104)	# Always zero for now 
-name_op('LOAD_ATTR', 105)	# Index in name list 
-def_op('COMPARE_OP', 106)	# Comparison operator 
-hascompare.append(106)
-name_op('IMPORT_NAME', 107)	# Index in name list 
-name_op('IMPORT_FROM', 108)	# Index in name list 
-
-jrel_op('JUMP_FORWARD', 110)	# Number of bytes to skip 
-jrel_op('JUMP_IF_FALSE', 111)	# "" 
-jrel_op('JUMP_IF_TRUE', 112)	# "" 
-jabs_op('JUMP_ABSOLUTE', 113)	# Target byte offset from beginning of code 
-jrel_op('FOR_LOOP', 114)	# Number of bytes to skip 
-
-name_op('LOAD_GLOBAL', 116)	# Index in name list
-
-jrel_op('SETUP_LOOP', 120)	# Distance to target address
-jrel_op('SETUP_EXCEPT', 121)	# ""
-jrel_op('SETUP_FINALLY', 122)	# ""
-
-def_op('LOAD_FAST', 124)	# Local variable number
-haslocal.append(124)
-def_op('STORE_FAST', 125)	# Local variable number
-haslocal.append(125)
-def_op('DELETE_FAST', 126)	# Local variable number
-haslocal.append(126)
-
-def_op('SET_LINENO', 127)	# Current line number
-SET_LINENO = 127
-
-def_op('RAISE_VARARGS', 130)    # Number of raise arguments (1, 2, or 3)
-def_op('CALL_FUNCTION', 131)    # #args + (#kwargs << 8)
-def_op('MAKE_FUNCTION', 132)    # Number of args with default values
-def_op('BUILD_SLICE', 133)      # Number of items
-
-def_op('CALL_FUNCTION_VAR', 140)     # #args + (#kwargs << 8)
-def_op('CALL_FUNCTION_KW', 141)      # #args + (#kwargs << 8)
-def_op('CALL_FUNCTION_VAR_KW', 142)  # #args + (#kwargs << 8)
-
-def_op('EXTENDED_ARG', 143) 
-EXTENDED_ARG = 143
-
-def _test():
-	"""Simple test program to disassemble a file."""
-	if sys.argv[1:]:
-		if sys.argv[2:]:
-			sys.stderr.write("usage: python dis.py [-|file]\n")
-			sys.exit(2)
-		fn = sys.argv[1]
-		if not fn or fn == "-":
-			fn = None
-	else:
-		fn = None
-	if not fn:
-		f = sys.stdin
-	else:
-		f = open(fn)
-	source = f.read()
-	if fn:
-		f.close()
-	else:
-		fn = "<stdin>"
-	code = compile(source, fn, "exec")
-	dis(code)
-
-if __name__ == "__main__":
-	_test()

uncompyle/dis/dis_21.py

-"""Disassembler of Python byte code into mnemonics."""
-
-import sys
-import types
-
-__all__ = ["dis","disassemble","distb","disco","opname","cmp_op",
-           "hasconst","hasname","hasjrel","hasjabs","haslocal",
-           "hascompare", "hasfree"]
-
-def dis(x=None):
-    """Disassemble classes, methods, functions, or code.
-
-    With no argument, disassemble the last traceback.
-
-    """
-    if not x:
-        distb()
-        return
-    if type(x) is types.InstanceType:
-        x = x.__class__
-    if hasattr(x, 'im_func'):
-        x = x.im_func
-    if hasattr(x, 'func_code'):
-        x = x.func_code
-    if hasattr(x, '__dict__'):
-        items = x.__dict__.items()
-        items.sort()
-        for name, x1 in items:
-            if type(x1) in (types.MethodType,
-                            types.FunctionType,
-                            types.CodeType):
-                print "Disassembly of %s:" % name
-                try:
-                    dis(x1)
-                except TypeError, msg:
-                    print "Sorry:", msg
-                print
-    elif hasattr(x, 'co_code'):
-        disassemble(x)
-    else:
-        raise TypeError, \
-              "don't know how to disassemble %s objects" % \
-              type(x).__name__
-
-def distb(tb=None):
-    """Disassemble a traceback (default: last traceback)."""
-    if not tb:
-        try:
-            tb = sys.last_traceback
-        except AttributeError:
-            raise RuntimeError, "no last traceback to disassemble"
-        while tb.tb_next: tb = tb.tb_next
-    disassemble(tb.tb_frame.f_code, tb.tb_lasti)
-
-def disassemble(co, lasti=-1):
-    """Disassemble a code object."""
-    code = co.co_code
-    labels = findlabels(code)
-    n = len(code)
-    i = 0
-    extended_arg = 0
-    free = None
-    while i < n:
-        c = code[i]
-        op = ord(c)
-        if op == SET_LINENO and i > 0: print # Extra blank line
-        if i == lasti: print '-->',
-        else: print '   ',
-        if i in labels: print '>>',
-        else: print '  ',
-        print `i`.rjust(4),
-        print opname[op].ljust(20),
-        i = i+1
-        if op >= HAVE_ARGUMENT:
-            oparg = ord(code[i]) + ord(code[i+1])*256 + extended_arg
-            extended_arg = 0
-            i = i+2
-            if op == EXTENDED_ARG:
-                extended_arg = oparg*65536L
-            print `oparg`.rjust(5),
-            if op in hasconst:
-                print '(' + `co.co_consts[oparg]` + ')',
-            elif op in hasname:
-                print '(' + co.co_names[oparg] + ')',
-            elif op in hasjrel:
-                print '(to ' + `i + oparg` + ')',
-            elif op in haslocal:
-                print '(' + co.co_varnames[oparg] + ')',
-            elif op in hascompare:
-                print '(' + cmp_op[oparg] + ')',
-            elif op in hasfree:
-                if free is None:
-                    free = co.co_cellvars + co.co_freevars
-                print '(' + free[oparg] + ')',
-        print
-
-disco = disassemble                     # XXX For backwards compatibility
-
-def findlabels(code):
-    """Detect all offsets in a byte code which are jump targets.
-
-    Return the list of offsets.
-
-    """
-    labels = []
-    n = len(code)
-    i = 0
-    while i < n:
-        c = code[i]
-        op = ord(c)
-        i = i+1
-        if op >= HAVE_ARGUMENT:
-            oparg = ord(code[i]) + ord(code[i+1])*256
-            i = i+2
-            label = -1
-            if op in hasjrel:
-                label = i+oparg
-            elif op in hasjabs:
-                label = oparg
-            if label >= 0:
-                if label not in labels:
-                    labels.append(label)
-    return labels
-
-cmp_op = ('<', '<=', '==', '!=', '>', '>=', 'in', 'not in', 'is',
-        'is not', 'exception match', 'BAD')
-
-hasconst = []
-hasname = []
-hasjrel = []
-hasjabs = []
-haslocal = []
-hascompare = []
-hasfree = []
-
-opname = [''] * 256
-for op in range(256): opname[op] = '<' + `op` + '>'
-
-def def_op(name, op):
-    opname[op] = name
-
-def name_op(name, op):
-    opname[op] = name
-    hasname.append(op)
-
-def jrel_op(name, op):
-    opname[op] = name
-    hasjrel.append(op)
-
-def jabs_op(name, op):
-    opname[op] = name
-    hasjabs.append(op)
-
-# Instruction opcodes for compiled code
-
-def_op('STOP_CODE', 0)
-def_op('POP_TOP', 1)
-def_op('ROT_TWO', 2)
-def_op('ROT_THREE', 3)
-def_op('DUP_TOP', 4)
-def_op('ROT_FOUR', 5)
-
-def_op('UNARY_POSITIVE', 10)
-def_op('UNARY_NEGATIVE', 11)
-def_op('UNARY_NOT', 12)
-def_op('UNARY_CONVERT', 13)
-
-def_op('UNARY_INVERT', 15)
-
-def_op('BINARY_POWER', 19)
-
-def_op('BINARY_MULTIPLY', 20)
-def_op('BINARY_DIVIDE', 21)
-def_op('BINARY_MODULO', 22)
-def_op('BINARY_ADD', 23)
-def_op('BINARY_SUBTRACT', 24)
-def_op('BINARY_SUBSCR', 25)
-
-def_op('SLICE+0', 30)
-def_op('SLICE+1', 31)
-def_op('SLICE+2', 32)
-def_op('SLICE+3', 33)
-
-def_op('STORE_SLICE+0', 40)
-def_op('STORE_SLICE+1', 41)
-def_op('STORE_SLICE+2', 42)
-def_op('STORE_SLICE+3', 43)
-
-def_op('DELETE_SLICE+0', 50)
-def_op('DELETE_SLICE+1', 51)
-def_op('DELETE_SLICE+2', 52)
-def_op('DELETE_SLICE+3', 53)
-
-def_op('INPLACE_ADD', 55)
-def_op('INPLACE_SUBTRACT', 56)
-def_op('INPLACE_MULTIPLY', 57)
-def_op('INPLACE_DIVIDE', 58)
-def_op('INPLACE_MODULO', 59)
-def_op('STORE_SUBSCR', 60)
-def_op('DELETE_SUBSCR', 61)
-
-def_op('BINARY_LSHIFT', 62)
-def_op('BINARY_RSHIFT', 63)
-def_op('BINARY_AND', 64)
-def_op('BINARY_XOR', 65)
-def_op('BINARY_OR', 66)
-def_op('INPLACE_POWER', 67)
-
-def_op('PRINT_EXPR', 70)
-def_op('PRINT_ITEM', 71)
-def_op('PRINT_NEWLINE', 72)
-def_op('PRINT_ITEM_TO', 73)
-def_op('PRINT_NEWLINE_TO', 74)
-def_op('INPLACE_LSHIFT', 75)
-def_op('INPLACE_RSHIFT', 76)
-def_op('INPLACE_AND', 77)
-def_op('INPLACE_XOR', 78)
-def_op('INPLACE_OR', 79)
-def_op('BREAK_LOOP', 80)
-
-def_op('LOAD_LOCALS', 82)
-def_op('RETURN_VALUE', 83)
-def_op('IMPORT_STAR', 84)
-def_op('EXEC_STMT', 85)
-
-def_op('POP_BLOCK', 87)
-def_op('END_FINALLY', 88)
-def_op(