本文整理汇总了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
示例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)
示例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)]
示例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)
示例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
示例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)
示例7: loads
# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import loads [as 别名]
def loads(str):
file = StringIO(str)
return Unpickler(file).load()
# Doctest
示例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())
示例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
示例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
示例11: loads
# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import loads [as 别名]
def loads(self, data):
raise NotImplementedError("implement in subclass")
示例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
示例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
示例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)
示例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)