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


Python marshal.dumps方法代码示例

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


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

示例1: run_code

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dumps [as 别名]
def run_code(self, function, *args, **kwargs):
        log.debug("%s() args:%s kwargs:%s on target", function.func_name, args, kwargs)
        data = {"cmd":self.CODE,
                "code":marshal.dumps(function.func_code),
                "name":function.func_name,
                "args":args,
                "kwargs":kwargs,
                "defaults":function.__defaults__,
                "closure":function.__closure__}
        self.send_data(data)
        log.debug("waiting for code to execute...")
        data = self.recv_data()
        if data["cmd"] == self.EXCEPT:
            log.debug("received exception")
            raise self._process_target_except(data)
        assert data["cmd"] == self.RETURN
        return data["value"] 
开发者ID:blackberry,项目名称:ALF,代码行数:19,代码来源:SockPuppet.py

示例2: forked_run_report

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dumps [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

示例3: _write_pyc

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dumps [as 别名]
def _write_pyc(state, co, source_stat, pyc):
    # Technically, we don't have to have the same pyc format as
    # (C)Python, since these "pycs" should never be seen by builtin
    # import. However, there's little reason deviate.
    try:
        with atomicwrites.atomic_write(pyc, mode="wb", overwrite=True) as fp:
            fp.write(importlib.util.MAGIC_NUMBER)
            # as of now, bytecode header expects 32-bit numbers for size and mtime (#4903)
            mtime = int(source_stat.st_mtime) & 0xFFFFFFFF
            size = source_stat.st_size & 0xFFFFFFFF
            # "<LL" stands for 2 unsigned longs, little-ending
            fp.write(struct.pack("<LL", mtime, size))
            fp.write(marshal.dumps(co))
    except EnvironmentError as e:
        state.trace("error writing pyc file at {}: errno={}".format(pyc, e.errno))
        # we ignore any failure to write the cache file
        # there are many reasons, permission-denied, __pycache__ being a
        # file etc.
        return False
    return True 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:22,代码来源:rewrite.py

示例4: func_dump

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dumps [as 别名]
def func_dump(func):
  """Serializes a user defined function.

  Arguments:
      func: the function to serialize.

  Returns:
      A tuple `(code, defaults, closure)`.
  """
  code = marshal.dumps(func.__code__).decode('raw_unicode_escape')
  defaults = func.__defaults__
  if func.__closure__:
    closure = tuple(c.cell_contents for c in func.__closure__)
  else:
    closure = None
  return code, defaults, closure 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:18,代码来源:generic_utils.py

示例5: test_file_multiple_reads

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dumps [as 别名]
def test_file_multiple_reads(self):
        """calling load w/ a file should only advance the length of the file"""
        l = []
        for i in xrange(10):
            l.append(marshal.dumps({i:i}))

        data = ''.join(l)
        with open('tempfile.txt', 'w') as f:
            f.write(data)

        with open('tempfile.txt') as f:
            for i in xrange(10):
                obj = marshal.load(f)
                self.assertEqual(obj, {i:i})

        self.delete_files('tempfile.txt') 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:18,代码来源:test_marshal.py

示例6: convert_pyc_file

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dumps [as 别名]
def convert_pyc_file(to_opcodes, pyc_file):
    pyc_code_obj_in = unmarshal_pyc_code(pyc_file)
    
    # recursively look for code objects
    # should also rebuild code object
    code_object_out = recurse_convert_code_objects(pyc_code_obj_in, to_opcodes)

    magic = '\x03\xf3\x0d\x0a'  # 62211 version
    time = '\x00'*4
    new_pyc_out = magic + time + marshal.dumps(code_object_out)
    
    filename = os.path.basename(pyc_code_obj_in.co_filename)
    filename = filename.replace(".pyc", "_converted.pyc")

    output_filename = os.path.dirname(pyc_file) + "\\" + filename

    with open(output_filename, 'wb') as f:
        f.write(new_pyc_out)
    
    return output_filename 
开发者ID:tenable,项目名称:poc,代码行数:22,代码来源:convert_pyc_opcodes.py

示例7: send_rpc_request

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dumps [as 别名]
def send_rpc_request(sock, req_obj, unknown):
    marsh = marshal.dumps(req_obj)  # python object

    # build out the header
    header =  "\x78\x01\x01" + struct.pack('<h', len(marsh))
    header += chr(unknown) # not sure exactly what this is
    header += "\xff"

    # add the ADLER32 checksum
    checksum = struct.pack('>i', zlib.adler32(marsh))

    post_data = header + marsh + checksum
    message = build_post(post_data)
    try:
        sock.send(message)

        resp = sock.recv(1024)

        if resp is None:
            print("Did not receive a response from server.")
    except Exception as e:
        print("Error with request:")
        print(e) 
开发者ID:tenable,项目名称:poc,代码行数:25,代码来源:druva_insync_osx_lpe.py

示例8: send_rpc_request

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dumps [as 别名]
def send_rpc_request(sock, req_obj, unknown):
    marsh = marshal.dumps(req_obj)  # python object

    # build out the header
    header =  "\x78\x01\x01" + struct.pack('<h', len(marsh))
    header += chr(unknown) # not sure exactly what this is
    header += "\xff"

    # add the ADLER32 checksum
    checksum = struct.pack('>i', zlib.adler32(marsh))

    post_data = header + marsh + checksum
    message = build_post(post_data)
    try:
        sock.send(message)
        #print("Sent request.")

        resp = sock.recv(1024)

        if resp is None:
            print("Did not receive a response from server.")
    except Exception as e:
        print("Error with request:")
        print(e) 
开发者ID:tenable,项目名称:poc,代码行数:26,代码来源:insync_rpc_set_acl_auth_exploit.py

示例9: func_dump

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dumps [as 别名]
def func_dump(func):
    """Serializes a user defined function.

    # Arguments
        func: the function to serialize.

    # Returns
        A tuple `(code, defaults, closure)`.
    """
    raw_code = marshal.dumps(func.__code__)
    code = codecs.encode(raw_code, 'base64').decode('ascii')
    defaults = func.__defaults__
    if func.__closure__:
        closure = tuple(c.cell_contents for c in func.__closure__)
    else:
        closure = None
    return code, defaults, closure 
开发者ID:danieljf24,项目名称:dual_encoding,代码行数:19,代码来源:generic_utils.py

示例10: putmessage

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dumps [as 别名]
def putmessage(self, message):
        self.debug("putmessage:%d:" % message[0])
        try:
            s = pickle.dumps(message)
        except pickle.PicklingError:
            print >>sys.__stderr__, "Cannot pickle:", repr(message)
            raise
        s = struct.pack("<i", len(s)) + s
        while len(s) > 0:
            try:
                r, w, x = select.select([], [self.sock], [])
                n = self.sock.send(s[:BUFSIZE])
            except (AttributeError, TypeError):
                raise IOError, "socket no longer exists"
            except socket.error:
                raise
            else:
                s = s[n:] 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:20,代码来源:rpc.py

示例11: send_data

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dumps [as 别名]
def send_data(self, data):
        is_ack = (data["cmd"] == self.ACK)
        data = pickle.dumps(data, pickle.HIGHEST_PROTOCOL)
        data_len = len(data)
        assert data_len < 0xFFFFFFFF, "Transfer too large!"
        log.debug("-> sending %d bytes", data_len)
        self.conn.sendall(struct.pack("I", data_len))
        self.conn.sendall(data)
        if not is_ack:
            assert self.recv_data()["cmd"] == self.ACK
            log.debug("ACK received") 
开发者ID:blackberry,项目名称:ALF,代码行数:13,代码来源:SockPuppet.py

示例12: __init__

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dumps [as 别名]
def __init__(self, function):
        #print(function.__closure__)
        self.func_code = marshal.dumps(function.func_code) 
开发者ID:pyscf,项目名称:pyscf,代码行数:5,代码来源:mpi_pool.py

示例13: marshal_dump

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dumps [as 别名]
def marshal_dump(code, f):
        if isinstance(f, file):
            marshal.dump(code, f)
        else:
            f.write(marshal.dumps(code)) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:7,代码来源:bccache.py

示例14: _child

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dumps [as 别名]
def _child(self, nice_level, child_on_start, child_on_exit):
        # right now we need to call a function, but first we need to
        # map all IO that might happen
        sys.stdout = stdout = get_unbuffered_io(1, self.STDOUT)
        sys.stderr = stderr = get_unbuffered_io(2, self.STDERR)
        retvalf = self.RETVAL.open("wb")
        EXITSTATUS = 0
        try:
            if nice_level:
                os.nice(nice_level)
            try:
                if child_on_start is not None:
                    child_on_start()
                retval = self.fun(*self.args, **self.kwargs)
                retvalf.write(marshal.dumps(retval))
                if child_on_exit is not None:
                    child_on_exit()
            except:
                excinfo = py.code.ExceptionInfo()
                stderr.write(str(excinfo._getreprcrash()))
                EXITSTATUS = self.EXITSTATUS_EXCEPTION
        finally:
            stdout.close()
            stderr.close()
            retvalf.close()
        os.close(1)
        os.close(2)
        os._exit(EXITSTATUS) 
开发者ID:pytest-dev,项目名称:py,代码行数:30,代码来源:forkedfunc.py

示例15: _compile

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dumps [as 别名]
def _compile(*filenames: str):
    for filename in filenames:
        code = compile_ex_python_from_filename(filename)
        timestamp = struct.pack('i', int(time.time()))
        marshalled_code_object = marshal.dumps(code)
        filename, ext = os.path.splitext(filename)
        filename = filename + '.pyc'
        with Path(filename).open('wb') as f:
            f.write(MAGIC_NUMBER)
            f.write(timestamp)
            f.write(b'A\x00\x00\x00')
            f.write(marshalled_code_object) 
开发者ID:Xython,项目名称:YAPyPy,代码行数:14,代码来源:cli.py


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