Python dis.EXTENDED_ARG Examples
The following are 30
code examples of dis.EXTENDED_ARG().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
dis
, or try the search function
.
Example #1
Source File: cloudpickle.py From BentoML with Apache License 2.0 | 6 votes |
def _walk_global_ops(code): """ Yield (opcode, argument number) tuples for all global-referencing instructions in *code*. """ code = getattr(code, 'co_code', b'') if PY2: # pragma: no branch code = map(ord, code) n = len(code) i = 0 extended_arg = 0 while i < n: op = code[i] i += 1 if op >= HAVE_ARGUMENT: oparg = code[i] + code[i + 1] * 256 + extended_arg extended_arg = 0 i += 2 if op == EXTENDED_ARG: extended_arg = oparg * 65536 if op in GLOBAL_OPS: yield op, oparg
Example #2
Source File: cloudpickle.py From FATE with Apache License 2.0 | 6 votes |
def _walk_global_ops(code): """ Yield (opcode, argument number) tuples for all global-referencing instructions in *code*. """ code = getattr(code, 'co_code', b'') if not PY3: code = map(ord, code) n = len(code) i = 0 extended_arg = 0 while i < n: op = code[i] i += 1 if op >= HAVE_ARGUMENT: oparg = code[i] + code[i + 1] * 256 + extended_arg extended_arg = 0 i += 2 if op == EXTENDED_ARG: extended_arg = oparg * 65536 if op in GLOBAL_OPS: yield op, oparg
Example #3
Source File: cloudpickle.py From FATE with Apache License 2.0 | 6 votes |
def _walk_global_ops(code): """ Yield (opcode, argument number) tuples for all global-referencing instructions in *code*. """ code = getattr(code, 'co_code', b'') if not PY3: code = map(ord, code) n = len(code) i = 0 extended_arg = 0 while i < n: op = code[i] i += 1 if op >= HAVE_ARGUMENT: oparg = code[i] + code[i + 1] * 256 + extended_arg extended_arg = 0 i += 2 if op == EXTENDED_ARG: extended_arg = oparg * 65536 if op in GLOBAL_OPS: yield op, oparg
Example #4
Source File: modulefinder.py From odoo13-x64 with GNU General Public License v3.0 | 6 votes |
def scan_opcodes(self, co): # Scan the code, and yield 'interesting' opcode combinations code = co.co_code names = co.co_names consts = co.co_consts opargs = [(op, arg) for _, op, arg in dis._unpack_opargs(code) if op != EXTENDED_ARG] for i, (op, oparg) in enumerate(opargs): if op in STORE_OPS: yield "store", (names[oparg],) continue if (op == IMPORT_NAME and i >= 2 and opargs[i-1][0] == opargs[i-2][0] == LOAD_CONST): level = consts[opargs[i-2][1]] fromlist = consts[opargs[i-1][1]] if level == 0: # absolute import yield "absolute_import", (fromlist, names[oparg]) else: # relative import yield "relative_import", (level, fromlist, names[oparg]) continue
Example #5
Source File: cloudpickle.py From LearningApacheSpark with MIT License | 6 votes |
def _walk_global_ops(code): """ Yield (opcode, argument number) tuples for all global-referencing instructions in *code*. """ code = getattr(code, 'co_code', b'') if not PY3: code = map(ord, code) n = len(code) i = 0 extended_arg = 0 while i < n: op = code[i] i += 1 if op >= HAVE_ARGUMENT: oparg = code[i] + code[i + 1] * 256 + extended_arg extended_arg = 0 i += 2 if op == EXTENDED_ARG: extended_arg = oparg * 65536 if op in GLOBAL_OPS: yield op, oparg
Example #6
Source File: modulefinder.py From Imogen with MIT License | 6 votes |
def scan_opcodes(self, co): # Scan the code, and yield 'interesting' opcode combinations code = co.co_code names = co.co_names consts = co.co_consts opargs = [(op, arg) for _, op, arg in dis._unpack_opargs(code) if op != EXTENDED_ARG] for i, (op, oparg) in enumerate(opargs): if op in STORE_OPS: yield "store", (names[oparg],) continue if (op == IMPORT_NAME and i >= 2 and opargs[i-1][0] == opargs[i-2][0] == LOAD_CONST): level = consts[opargs[i-2][1]] fromlist = consts[opargs[i-1][1]] if level == 0: # absolute import yield "absolute_import", (fromlist, names[oparg]) else: # relative import yield "relative_import", (level, fromlist, names[oparg]) continue
Example #7
Source File: cloudpickle.py From pywren-ibm-cloud with Apache License 2.0 | 6 votes |
def _walk_global_ops(code): """ Yield (opcode, argument number) tuples for all global-referencing instructions in *code*. """ code = getattr(code, 'co_code', b'') if PY2: # pragma: no branch code = map(ord, code) n = len(code) i = 0 extended_arg = 0 while i < n: op = code[i] i += 1 if op >= HAVE_ARGUMENT: oparg = code[i] + code[i + 1] * 256 + extended_arg extended_arg = 0 i += 2 if op == EXTENDED_ARG: extended_arg = oparg * 65536 if op in GLOBAL_OPS: yield op, oparg
Example #8
Source File: cloudpickle.py From eggroll with Apache License 2.0 | 6 votes |
def _walk_global_ops(code): """ Yield (opcode, argument number) tuples for all global-referencing instructions in *code*. """ code = getattr(code, 'co_code', b'') if not PY3: code = map(ord, code) n = len(code) i = 0 extended_arg = 0 while i < n: op = code[i] i += 1 if op >= HAVE_ARGUMENT: oparg = code[i] + code[i + 1] * 256 + extended_arg extended_arg = 0 i += 2 if op == EXTENDED_ARG: extended_arg = oparg * 65536 if op in GLOBAL_OPS: yield op, oparg
Example #9
Source File: modulefinder.py From Carnets with BSD 3-Clause "New" or "Revised" License | 6 votes |
def scan_opcodes(self, co): # Scan the code, and yield 'interesting' opcode combinations code = co.co_code names = co.co_names consts = co.co_consts opargs = [(op, arg) for _, op, arg in dis._unpack_opargs(code) if op != EXTENDED_ARG] for i, (op, oparg) in enumerate(opargs): if op in STORE_OPS: yield "store", (names[oparg],) continue if (op == IMPORT_NAME and i >= 2 and opargs[i-1][0] == opargs[i-2][0] == LOAD_CONST): level = consts[opargs[i-2][1]] fromlist = consts[opargs[i-1][1]] if level == 0: # absolute import yield "absolute_import", (fromlist, names[oparg]) else: # relative import yield "relative_import", (level, fromlist, names[oparg]) continue
Example #10
Source File: assembler.py From monasca-analytics with Apache License 2.0 | 6 votes |
def __iter__(self): i = 0 extended_arg = 0 code = self.co_code n = len(code) while i < n: op = code[i] if op >= HAVE_ARGUMENT: oparg = code[i + 1] + code[i + 2] * 256 + extended_arg extended_arg = 0 if op == EXTENDED_ARG: extended_arg = oparg * 65536 i += 3 continue yield i, op, oparg i += 3 else: yield i, op, None i += 1
Example #11
Source File: modulefinder.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def scan_opcodes_25(self, co, unpack = struct.unpack): # Scan the code, and yield 'interesting' opcode combinations code = co.co_code names = co.co_names consts = co.co_consts opargs = [(op, arg) for _, op, arg in dis._unpack_opargs(code) if op != EXTENDED_ARG] for i, (op, oparg) in enumerate(opargs): if op in STORE_OPS: yield "store", (names[oparg],) continue if (op == IMPORT_NAME and i >= 2 and opargs[i-1][0] == opargs[i-2][0] == LOAD_CONST): level = consts[opargs[i-2][1]] fromlist = consts[opargs[i-1][1]] if level == 0: # absolute import yield "absolute_import", (fromlist, names[oparg]) else: # relative import yield "relative_import", (level, fromlist, names[oparg]) continue
Example #12
Source File: cloudpickle.py From pywren with Apache License 2.0 | 6 votes |
def _walk_global_ops(code): """ Yield (opcode, argument number) tuples for all global-referencing instructions in *code*. """ code = getattr(code, 'co_code', b'') if not PY3: code = map(ord, code) n = len(code) i = 0 extended_arg = 0 while i < n: op = code[i] i += 1 if op >= HAVE_ARGUMENT: oparg = code[i] + code[i + 1] * 256 + extended_arg extended_arg = 0 i += 2 if op == EXTENDED_ARG: extended_arg = oparg * 65536 if op in GLOBAL_OPS: yield op, oparg
Example #13
Source File: modulefinder.py From PokemonGo-DesktopMap with MIT License | 6 votes |
def _unpack_opargs(code): # enumerate() is not an option, since we sometimes process # multiple elements on a single pass through the loop extended_arg = 0 n = len(code) i = 0 while i < n: op = ord(code[i]) offset = i i = i+1 arg = None if op >= HAVE_ARGUMENT: arg = ord(code[i]) + ord(code[i+1])*256 + extended_arg extended_arg = 0 i = i+2 if op == EXTENDED_ARG: extended_arg = arg*65536 yield (offset, op, arg) # Modulefinder does a good job at simulating Python's, but it can not # handle __path__ modifications packages make at runtime. Therefore there # is a mechanism whereby you can register extra paths in this map for a # package, and it will be honored. # Note this is a mapping is lists of paths.
Example #14
Source File: modulefinder.py From PokemonGo-DesktopMap with MIT License | 6 votes |
def scan_opcodes(self, co, unpack = struct.unpack): # Scan the code, and yield 'interesting' opcode combinations # Version for Python 2.4 and older code = co.co_code names = co.co_names consts = co.co_consts opargs = [(op, arg) for _, op, arg in _unpack_opargs(code) if op != EXTENDED_ARG] for i, (op, oparg) in enumerate(opargs): if c in STORE_OPS: yield "store", (names[oparg],) continue if (op == IMPORT_NAME and i >= 1 and opargs[i-1][0] == LOAD_CONST): fromlist = consts[opargs[i-1][1]] yield "import", (fromlist, names[oparg]) continue
Example #15
Source File: overrides.py From overrides with Apache License 2.0 | 6 votes |
def op_stream(code, max): """Generator function: convert Python bytecode into a sequence of opcode-argument pairs.""" i = [0] def next(): val = code[i[0]] i[0] += 1 return val ext_arg = 0 while i[0] <= max: op, arg = next(), next() if op == dis.EXTENDED_ARG: ext_arg += arg ext_arg <<= 8 continue else: yield (op, arg + ext_arg) ext_arg = 0
Example #16
Source File: modulefinder.py From PokemonGo-DesktopMap with MIT License | 6 votes |
def scan_opcodes_25(self, co): # Scan the code, and yield 'interesting' opcode combinations code = co.co_code names = co.co_names consts = co.co_consts opargs = [(op, arg) for _, op, arg in _unpack_opargs(code) if op != EXTENDED_ARG] for i, (op, oparg) in enumerate(opargs): if op in STORE_OPS: yield "store", (names[oparg],) continue if (op == IMPORT_NAME and i >= 2 and opargs[i-1][0] == opargs[i-2][0] == LOAD_CONST): level = consts[opargs[i-2][1]] fromlist = consts[opargs[i-1][1]] if level == -1: # normal import yield "import", (fromlist, names[oparg]) elif level == 0: # absolute import yield "absolute_import", (fromlist, names[oparg]) else: # relative import yield "relative_import", (level, fromlist, names[oparg]) continue
Example #17
Source File: executing.py From executing with MIT License | 6 votes |
def get_instructions(co): code = co.co_code n = len(code) i = 0 extended_arg = 0 while i < n: offset = i c = code[i] op = ord(c) argval = None 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 * 65536 if op in hasconst: argval = co.co_consts[oparg] yield Instruction(offset, argval, opname[op])
Example #18
Source File: modulefinder.py From unity-python with MIT License | 6 votes |
def _unpack_opargs(code): # enumerate() is not an option, since we sometimes process # multiple elements on a single pass through the loop extended_arg = 0 n = len(code) i = 0 while i < n: op = ord(code[i]) offset = i i = i+1 arg = None if op >= HAVE_ARGUMENT: arg = ord(code[i]) + ord(code[i+1])*256 + extended_arg extended_arg = 0 i = i+2 if op == EXTENDED_ARG: extended_arg = arg*65536 yield (offset, op, arg) # Modulefinder does a good job at simulating Python's, but it can not # handle __path__ modifications packages make at runtime. Therefore there # is a mechanism whereby you can register extra paths in this map for a # package, and it will be honored. # Note this is a mapping is lists of paths.
Example #19
Source File: modulefinder.py From unity-python with MIT License | 6 votes |
def scan_opcodes(self, co, unpack = struct.unpack): # Scan the code, and yield 'interesting' opcode combinations # Version for Python 2.4 and older code = co.co_code names = co.co_names consts = co.co_consts opargs = [(op, arg) for _, op, arg in _unpack_opargs(code) if op != EXTENDED_ARG] for i, (op, oparg) in enumerate(opargs): if c in STORE_OPS: yield "store", (names[oparg],) continue if (op == IMPORT_NAME and i >= 1 and opargs[i-1][0] == LOAD_CONST): fromlist = consts[opargs[i-1][1]] yield "import", (fromlist, names[oparg]) continue
Example #20
Source File: modulefinder.py From ironpython2 with Apache License 2.0 | 6 votes |
def scan_opcodes_25(self, co): # Scan the code, and yield 'interesting' opcode combinations code = co.co_code names = co.co_names consts = co.co_consts opargs = [(op, arg) for _, op, arg in _unpack_opargs(code) if op != EXTENDED_ARG] for i, (op, oparg) in enumerate(opargs): if op in STORE_OPS: yield "store", (names[oparg],) continue if (op == IMPORT_NAME and i >= 2 and opargs[i-1][0] == opargs[i-2][0] == LOAD_CONST): level = consts[opargs[i-2][1]] fromlist = consts[opargs[i-1][1]] if level == -1: # normal import yield "import", (fromlist, names[oparg]) elif level == 0: # absolute import yield "absolute_import", (fromlist, names[oparg]) else: # relative import yield "relative_import", (level, fromlist, names[oparg]) continue
Example #21
Source File: modulefinder.py From ironpython2 with Apache License 2.0 | 6 votes |
def scan_opcodes(self, co, unpack = struct.unpack): # Scan the code, and yield 'interesting' opcode combinations # Version for Python 2.4 and older code = co.co_code names = co.co_names consts = co.co_consts opargs = [(op, arg) for _, op, arg in _unpack_opargs(code) if op != EXTENDED_ARG] for i, (op, oparg) in enumerate(opargs): if c in STORE_OPS: yield "store", (names[oparg],) continue if (op == IMPORT_NAME and i >= 1 and opargs[i-1][0] == LOAD_CONST): fromlist = consts[opargs[i-1][1]] yield "import", (fromlist, names[oparg]) continue
Example #22
Source File: modulefinder.py From ironpython2 with Apache License 2.0 | 6 votes |
def _unpack_opargs(code): # enumerate() is not an option, since we sometimes process # multiple elements on a single pass through the loop extended_arg = 0 n = len(code) i = 0 while i < n: op = ord(code[i]) offset = i i = i+1 arg = None if op >= HAVE_ARGUMENT: arg = ord(code[i]) + ord(code[i+1])*256 + extended_arg extended_arg = 0 i = i+2 if op == EXTENDED_ARG: extended_arg = arg*65536 yield (offset, op, arg) # Modulefinder does a good job at simulating Python's, but it can not # handle __path__ modifications packages make at runtime. Therefore there # is a mechanism whereby you can register extra paths in this map for a # package, and it will be honored. # Note this is a mapping is lists of paths.
Example #23
Source File: modulefinder.py From unity-python with MIT License | 6 votes |
def scan_opcodes_25(self, co): # Scan the code, and yield 'interesting' opcode combinations code = co.co_code names = co.co_names consts = co.co_consts opargs = [(op, arg) for _, op, arg in _unpack_opargs(code) if op != EXTENDED_ARG] for i, (op, oparg) in enumerate(opargs): if op in STORE_OPS: yield "store", (names[oparg],) continue if (op == IMPORT_NAME and i >= 2 and opargs[i-1][0] == opargs[i-2][0] == LOAD_CONST): level = consts[opargs[i-2][1]] fromlist = consts[opargs[i-1][1]] if level == -1: # normal import yield "import", (fromlist, names[oparg]) elif level == 0: # absolute import yield "absolute_import", (fromlist, names[oparg]) else: # relative import yield "relative_import", (level, fromlist, names[oparg]) continue
Example #24
Source File: modulefinder.py From android_universal with MIT License | 6 votes |
def scan_opcodes(self, co): # Scan the code, and yield 'interesting' opcode combinations code = co.co_code names = co.co_names consts = co.co_consts opargs = [(op, arg) for _, op, arg in dis._unpack_opargs(code) if op != EXTENDED_ARG] for i, (op, oparg) in enumerate(opargs): if op in STORE_OPS: yield "store", (names[oparg],) continue if (op == IMPORT_NAME and i >= 2 and opargs[i-1][0] == opargs[i-2][0] == LOAD_CONST): level = consts[opargs[i-2][1]] fromlist = consts[opargs[i-1][1]] if level == 0: # absolute import yield "absolute_import", (fromlist, names[oparg]) else: # relative import yield "relative_import", (level, fromlist, names[oparg]) continue
Example #25
Source File: cloudpickle.py From spark-cluster-deployment with Apache License 2.0 | 6 votes |
def extract_code_globals(co): """ Find all globals names read or written to by codeblock co """ code = co.co_code names = co.co_names out_names = set() n = len(code) i = 0 extended_arg = 0 while i < n: op = code[i] 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 if op in GLOBAL_OPS: out_names.add(names[oparg]) #print 'extracted', out_names, ' from ', names return out_names
Example #26
Source File: executing.py From executing with MIT License | 6 votes |
def _get_instructions(co): code = co.co_code linestarts = dict(findlinestarts(co)) n = len(code) i = 0 extended_arg = 0 while i < n: offset = i c = code[i] op = ord(c) lineno = linestarts.get(i) argval = None 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 * 65536 if op in hasconst: argval = co.co_consts[oparg] yield Instruction(offset, argval, opname[op], lineno)
Example #27
Source File: depends.py From datafari with Apache License 2.0 | 5 votes |
def _iter_code(code): """Yield '(op,arg)' pair for each operation in code object 'code'""" from array import array from dis import HAVE_ARGUMENT, EXTENDED_ARG bytes = array('b',code.co_code) eof = len(code.co_code) ptr = 0 extended_arg = 0 while ptr<eof: op = bytes[ptr] if op>=HAVE_ARGUMENT: arg = bytes[ptr+1] + bytes[ptr+2]*256 + extended_arg ptr += 3 if op==EXTENDED_ARG: extended_arg = arg * compat.long_type(65536) continue else: arg = None ptr += 1 yield op,arg
Example #28
Source File: test_dis.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_boundaries(self): self.assertEqual(dis.opmap["EXTENDED_ARG"], dis.EXTENDED_ARG) self.assertEqual(dis.opmap["STORE_NAME"], dis.HAVE_ARGUMENT)
Example #29
Source File: py33compat.py From Ansible with MIT License | 5 votes |
def __iter__(self): """Yield '(op,arg)' pair for each operation in code object 'code'""" bytes = array.array('b', self.code.co_code) eof = len(self.code.co_code) ptr = 0 extended_arg = 0 while ptr < eof: op = bytes[ptr] if op >= dis.HAVE_ARGUMENT: arg = bytes[ptr + 1] + bytes[ptr + 2] * 256 + extended_arg ptr += 3 if op == dis.EXTENDED_ARG: long_type = six.integer_types[-1] extended_arg = arg * long_type(65536) continue else: arg = None ptr += 1 yield OpArg(op, arg)
Example #30
Source File: test_dis.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_boundaries(self): self.assertEqual(dis.opmap["EXTENDED_ARG"], dis.EXTENDED_ARG) self.assertEqual(dis.opmap["STORE_NAME"], dis.HAVE_ARGUMENT)