python类HAVE_ARGUMENT的实例源码

depends.py 文件源码 项目:Flask_Blog 作者: sugarguo 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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 * long_type(65536)
                continue

        else:
            arg = None
            ptr += 1

        yield op,arg
recipe-578965.py 文件源码 项目:code 作者: ActiveState 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def find_code(code, f):
    i = 0
    while i < len(code):
        if f(code, i):
            return i
        elif code[i] < dis.HAVE_ARGUMENT:
            i += 1
        else:
            i += 3

# http://nedbatchelder.com/blog/201301/byterun_and_making_cells.html
depends.py 文件源码 项目:swjtu-pyscraper 作者: Desgard 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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:
                long_type = six.integer_types[-1]
                extended_arg = arg * long_type(65536)
                continue

        else:
            arg = None
            ptr += 1

        yield op, arg
depends.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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
depends.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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
depends.py 文件源码 项目:noc-orchestrator 作者: DirceuSilvaLabs 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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:
                long_type = six.integer_types[-1]
                extended_arg = arg * long_type(65536)
                continue

        else:
            arg = None
            ptr += 1

        yield op,arg
py33compat.py 文件源码 项目:jira_worklog_scanner 作者: pgarneau 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
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)
depends.py 文件源码 项目:zanph 作者: zanph 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
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:
                long_type = six.integer_types[-1]
                extended_arg = arg * long_type(65536)
                continue

        else:
            arg = None
            ptr += 1

        yield op,arg
modulefinder.py 文件源码 项目:hostapd-mana 作者: adde88 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def scan_opcodes_25(self, co,
                     unpack = struct.unpack):
        # Scan the code, and yield 'interesting' opcode combinations
        # Python 2.5 version (has absolute and relative imports)
        code = co.co_code
        names = co.co_names
        consts = co.co_consts
        LOAD_LOAD_AND_IMPORT = LOAD_CONST + LOAD_CONST + IMPORT_NAME
        while code:
            c = code[0]
            if c in STORE_OPS:
                oparg, = unpack('<H', code[1:3])
                yield "store", (names[oparg],)
                code = code[3:]
                continue
            if code[:9:3] == LOAD_LOAD_AND_IMPORT:
                oparg_1, oparg_2, oparg_3 = unpack('<xHxHxH', code[:9])
                level = consts[oparg_1]
                if level == -1: # normal import
                    yield "import", (consts[oparg_2], names[oparg_3])
                elif level == 0: # absolute import
                    yield "absolute_import", (consts[oparg_2], names[oparg_3])
                else: # relative import
                    yield "relative_import", (level, consts[oparg_2], names[oparg_3])
                code = code[9:]
                continue
            if c >= HAVE_ARGUMENT:
                code = code[3:]
            else:
                code = code[1:]
py33compat.py 文件源码 项目:Sci-Finder 作者: snverse 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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)
py33compat.py 文件源码 项目:Sci-Finder 作者: snverse 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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)
depends.py 文件源码 项目:ascii-art-py 作者: blinglnav 项目源码 文件源码 阅读 18 收藏 0 点赞 0 评论 0
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:
                long_type = six.integer_types[-1]
                extended_arg = arg * long_type(65536)
                continue

        else:
            arg = None
            ptr += 1

        yield op, arg
cloudpickle.py 文件源码 项目:MIT-Thesis 作者: alec-heif 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def extract_code_globals(co):
        """
        Find all globals names read or written to by codeblock co
        """
        code = co.co_code
        if not PY3:
            code = [ord(c) for c in code]
        names = co.co_names
        out_names = set()

        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:
                    out_names.add(names[oparg])

        # see if nested function have any global refs
        if co.co_consts:
            for const in co.co_consts:
                if type(const) is types.CodeType:
                    out_names |= CloudPickler.extract_code_globals(const)

        return out_names
overrides.py 文件源码 项目:third_person_im 作者: bstadie 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def _get_base_class_names(frame):
    """Get baseclass names from the code object"""
    co, lasti = frame.f_code, frame.f_lasti
    code = co.co_code
    i = 0
    extended_arg = 0
    extends = []
    while i <= lasti:
        c = code[i]
        op = ord(c)
        i += 1
        if op >= dis.HAVE_ARGUMENT:
            oparg = ord(code[i]) + ord(code[i+1])*256 + extended_arg
            extended_arg = 0
            i += 2
            if op == dis.EXTENDED_ARG:
                extended_arg = oparg*int(65536)
            if op in dis.hasconst:
                if type(co.co_consts[oparg]) == str:
                    extends = []
            elif op in dis.hasname:
                if dis.opname[op] == 'LOAD_NAME':
                    extends.append(('name', co.co_names[oparg]))
                if dis.opname[op] == 'LOAD_ATTR':
                    extends.append(('attr', co.co_names[oparg]))
    items = []
    previous_item = []
    for t, s in extends:
        if t == 'name':
            if previous_item:
                items.append(previous_item)
            previous_item = [s]
        else:
            previous_item += [s]
    if previous_item:
        items.append(previous_item)
    return items
py33compat.py 文件源码 项目:ivaochdoc 作者: ivaoch 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
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)
py33compat.py 文件源码 项目:aws-cfn-plex 作者: lordmuffin 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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)
vm.py 文件源码 项目:PyVyM 作者: ssarangi 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def get_opcode(self):
        # Based on the settings decide to show the line-by-line trace
        # Get the current line being executed
        current_lineno = self.__exec_frame.line_no_obj.line_number(self.__exec_frame.ip)

        ip = self.__exec_frame.ip
            # Update the line number only if the currently executing line has changed.
        if self.__exec_frame.line_no_obj.currently_executing_line is None or \
            self.__exec_frame.line_no_obj.currently_executing_line != current_lineno:
            self.__exec_frame.line_no_obj.currently_executing_line = current_lineno
            self.__exec_frame.line_no_obj.currently_executing_line = current_lineno

        if self.__config.show_line_execution:
            current_line = self.__exec_frame.line_no_obj.get_source_line(current_lineno)
            print("Execution Line: %s" % current_line)

        op = self.__exec_frame.program[self.__exec_frame.ip]
        ip += 1
        opmethod = "execute_%s" % dis.opname[op]

        oparg = None
        if op >= dis.HAVE_ARGUMENT:
            low = self.__exec_frame.program[ip]
            high = self.__exec_frame.program[ip + 1]
            oparg = (high << 8) | low

        return opmethod, oparg, current_lineno
py33compat.py 文件源码 项目:RPoint 作者: george17-meet 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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)
master.py 文件源码 项目:mitogen 作者: dw 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def scan_code_imports(co, LOAD_CONST=dis.opname.index('LOAD_CONST'),
                          IMPORT_NAME=dis.opname.index('IMPORT_NAME')):
    """Given a code object `co`, scan its bytecode yielding any
    ``IMPORT_NAME`` and associated prior ``LOAD_CONST`` instructions
    representing an `Import` statement or `ImportFrom` statement.

    :return:
        Generator producing `(level, modname, namelist)` tuples, where:

        * `level`: -1 for normal import, 0, for absolute import, and >0 for
          relative import.
        * `modname`: Name of module to import, or from where `namelist` names
          are imported.
        * `namelist`: for `ImportFrom`, the list of names to be imported from
          `modname`.
    """
    # Yield `(op, oparg)` tuples from the code object `co`.
    ordit = itertools.imap(ord, co.co_code)
    nextb = ordit.next

    opit = ((c, (None
                 if c < dis.HAVE_ARGUMENT else
                 (nextb() | (nextb() << 8))))
            for c in ordit)

    opit, opit2, opit3 = itertools.tee(opit, 3)
    next(opit2)
    next(opit3)
    next(opit3)

    for oparg1, oparg2, (op3, arg3) in itertools.izip(opit, opit2, opit3):
        if op3 == IMPORT_NAME:
            op2, arg2 = oparg2
            op1, arg1 = oparg1
            if op1 == op2 == LOAD_CONST:
                yield (co.co_consts[arg1],
                       co.co_names[arg3],
                       co.co_consts[arg2] or ())
depends.py 文件源码 项目:isni-reconcile 作者: cmh2166 项目源码 文件源码 阅读 20 收藏 0 点赞 0 评论 0
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


问题


面经


文章

微信
公众号

扫码关注公众号