当前位置: 首页>>代码示例>>Python>>正文


Python marshal.loads方法代码示例

本文整理汇总了Python中marshal.loads方法的典型用法代码示例。如果您正苦于以下问题:Python marshal.loads方法的具体用法?Python marshal.loads怎么用?Python marshal.loads使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在marshal的用法示例。


在下文中一共展示了marshal.loads方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: recv_data

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import loads [as 别名]
def recv_data(self):
        data_remaining = struct.unpack("I", self.conn.recv(4))[0]
        if not data_remaining:
            log.debug("no data?!")
            return None
        log.debug("<- recving %d bytes", data_remaining)
        data = []
        while data_remaining:
            recv_bytes = data_remaining if data_remaining < self.SOCK_BUF else self.SOCK_BUF
            data.append(self.conn.recv(recv_bytes))
            data_len = len(data[-1])
            if data_len == 0:
                break
            data_remaining -= data_len
        data = pickle.loads("".join(data))
        if data["cmd"] != self.ACK:
            self.send_ack()
        return data 
开发者ID:blackberry,项目名称:ALF,代码行数:20,代码来源:SockPuppet.py

示例2: waitfinish

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import loads [as 别名]
def waitfinish(self, waiter=os.waitpid):
        pid, systemstatus = waiter(self.pid, 0)
        if systemstatus:
            if os.WIFSIGNALED(systemstatus):
                exitstatus = os.WTERMSIG(systemstatus) + 128
            else:
                exitstatus = os.WEXITSTATUS(systemstatus)
        else:
            exitstatus = 0
        signal = systemstatus & 0x7f
        if not exitstatus and not signal:
            retval = self.RETVAL.open('rb')
            try:
                retval_data = retval.read()
            finally:
                retval.close()
            retval = marshal.loads(retval_data)
        else:
            retval = None
        stdout = self.STDOUT.read()
        stderr = self.STDERR.read()
        self._removetemp()
        return Result(exitstatus, signal, retval, stdout, stderr) 
开发者ID:pytest-dev,项目名称:py,代码行数:25,代码来源:forkedfunc.py

示例3: forked_run_report

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import loads [as 别名]
def forked_run_report(item):
    # for now, we run setup/teardown in the subprocess
    # XXX optionally allow sharing of setup/teardown
    from _pytest.runner import runtestprotocol
    EXITSTATUS_TESTEXIT = 4
    import marshal

    def runforked():
        try:
            reports = runtestprotocol(item, log=False)
        except KeyboardInterrupt:
            os._exit(EXITSTATUS_TESTEXIT)
        return marshal.dumps([serialize_report(x) for x in reports])

    ff = py.process.ForkedFunc(runforked)
    result = ff.waitfinish()
    if result.retval is not None:
        report_dumps = marshal.loads(result.retval)
        return [runner.TestReport(**x) for x in report_dumps]
    else:
        if result.exitstatus == EXITSTATUS_TESTEXIT:
            pytest.exit("forked test item %s raised Exit" % (item,))
        return [report_process_crash(item, result)] 
开发者ID:pytest-dev,项目名称:pytest-forked,代码行数:25,代码来源:__init__.py

示例4: func_load

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import loads [as 别名]
def func_load(code, defaults=None, closure=None, globs=None):
  """Deserializes a user defined function.

  Arguments:
      code: bytecode of the function.
      defaults: defaults of the function.
      closure: closure of the function.
      globs: dictionary of global objects.

  Returns:
      A function object.
  """
  if isinstance(code, (tuple, list)):  # unpack previous dump
    code, defaults, closure = code
    if isinstance(defaults, list):
      defaults = tuple(defaults)
  code = marshal.loads(code.encode('raw_unicode_escape'))
  if globs is None:
    globs = globals()
  return python_types.FunctionType(
      code, globs, name=code.co_name, argdefs=defaults, closure=closure) 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:23,代码来源:generic_utils.py

示例5: test_int64

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import loads [as 别名]
def test_int64(self):
        # Simulate int marshaling on a 64-bit box.  This is most interesting if
        # we're running the test on a 32-bit box, of course.

        def to_little_endian_string(value, nbytes):
            bytes = []
            for i in range(nbytes):
                bytes.append(chr(value & 0xff))
                value >>= 8
            return ''.join(bytes)

        maxint64 = (1L << 63) - 1
        minint64 = -maxint64-1

        for base in maxint64, minint64, -maxint64, -(minint64 >> 1):
            while base:
                s = 'I' + to_little_endian_string(base, 8)
                got = marshal.loads(s)
                self.assertEqual(base, got)
                if base == -1:  # a fixed-point for shifting right 1
                    base = 0
                else:
                    base >>= 1 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:25,代码来源:test_marshal.py

示例6: test_loads_recursion

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import loads [as 别名]
def test_loads_recursion(self):
        def run_tests(N, check):
            # (((...None...),),)
            check(b'(\x01\x00\x00\x00' * N + b'N')
            # [[[...None...]]]
            check(b'[\x01\x00\x00\x00' * N + b'N')
            # {None: {None: {None: ...None...}}}
            check(b'{N' * N + b'N' + b'0' * N)
            # frozenset([frozenset([frozenset([...None...])])])
            check(b'>\x01\x00\x00\x00' * N + b'N')
        # Check that the generated marshal data is valid and marshal.loads()
        # works for moderately deep nesting
        run_tests(100, marshal.loads)
        # Very deeply nested structure shouldn't blow the stack
        def check(s):
            self.assertRaises(ValueError, marshal.loads, s)
        run_tests(2**20, check) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_marshal.py

示例7: loads

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import loads [as 别名]
def loads(str):
    file = StringIO(str)
    return Unpickler(file).load()

# Doctest 
开发者ID:glmcdona,项目名称:meddle,代码行数:7,代码来源:pickle.py

示例8: marshal_load

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import loads [as 别名]
def marshal_load(f):
        if isinstance(f, file):
            return marshal.load(f)
        return marshal.loads(f.read()) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:6,代码来源:bccache.py

示例9: load_module

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import loads [as 别名]
def load_module(self, fullname):
        if fullname in sys.modules:
            return sys.modules[fullname]

        mod = sys.modules.setdefault(fullname, imp.new_module(fullname))
        mod.__file__ = "<%s>" % fullname
        mod.__loader__ = self
        if conf.isPycFile:
            code = marshal.loads(self.contents[8:])
        else:
            code = compile(self.contents, mod.__file__, "exec")
        exec code in mod.__dict__
        return mod 
开发者ID:vulscanteam,项目名称:vulscan,代码行数:15,代码来源:common.py

示例10: __deserializeBlobArgs

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import loads [as 别名]
def __deserializeBlobArgs(self, protocolmsg):
        import marshal
        blobinfo = protocolmsg.annotations["BLBI"]
        blobinfo, objId, method = marshal.loads(blobinfo)
        blob = client.SerializedBlob(blobinfo, protocolmsg, is_blob=True)
        return objId, method, (blob,), {}  # object, method, vargs, kwargs 
开发者ID:irmen,项目名称:Pyro5,代码行数:8,代码来源:server.py

示例11: loads

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import loads [as 别名]
def loads(self, data):
        raise NotImplementedError("implement in subclass") 
开发者ID:irmen,项目名称:Pyro5,代码行数:4,代码来源:serializers.py

示例12: loadsCall

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import loads [as 别名]
def loadsCall(self, data):
        obj, method, vargs, kwargs = serpent.loads(data)
        vargs = self.recreate_classes(vargs)
        kwargs = self.recreate_classes(kwargs)
        return obj, method, vargs, kwargs 
开发者ID:irmen,项目名称:Pyro5,代码行数:7,代码来源:serializers.py

示例13: _get_codeobj

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import loads [as 别名]
def _get_codeobj(pyfile):
    """ Returns the code object, given a python file """
    from imp import PY_COMPILED, PY_SOURCE

    result, fileobj, fullpath = _check_if_pyc(pyfile)

    # WARNING:
    # fp.read() can blowup if the module is extremely large file.
    # Lookout for overflow errors.
    try:
        data = fileobj.read()
    finally:
        fileobj.close()

    # This is a .pyc file. Treat accordingly.
    if result is PY_COMPILED:
        # .pyc format is as follows:
        # 0 - 4 bytes: Magic number, which changes with each create of .pyc file.
        #              First 2 bytes change with each marshal of .pyc file. Last 2 bytes is "\r\n".
        # 4 - 8 bytes: Datetime value, when the .py was last changed.
        # 8 - EOF: Marshalled code object data.
        # So to get code object, just read the 8th byte onwards till EOF, and
        # UN-marshal it.
        import marshal
        code_obj = marshal.loads(data[8:])

    elif result is PY_SOURCE:
        # This is a .py file.
        code_obj = compile(data, fullpath, 'exec')

    else:
        # Unsupported extension
        raise Exception("Input file is unknown format: {0}".format(fullpath))

    # Return code object
    return code_obj 
开发者ID:jpush,项目名称:jbox,代码行数:38,代码来源:_compat.py

示例14: test_with_marshal

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import loads [as 别名]
def test_with_marshal(self):
        arg = unicode(r'\222', 'unicode-escape')
        self.assertRaises(UnicodeError, marshal.loads, arg) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:5,代码来源:test_getargs.py

示例15: test_marshal

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import loads [as 别名]
def test_marshal(self):
        import marshal
        self.assertIs(marshal.loads(marshal.dumps(True)), True)
        self.assertIs(marshal.loads(marshal.dumps(False)), False) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:6,代码来源:test_bool.py


注:本文中的marshal.loads方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。