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


Python marshal.dump方法代码示例

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


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

示例1: randfloats

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dump [as 别名]
def randfloats(n):
    """Return a list of n random floats in [0, 1)."""
    # Generating floats is expensive, so this writes them out to a file in
    # a temp directory.  If the file already exists, it just reads them
    # back in and shuffles them a bit.
    fn = os.path.join(td, "rr%06d" % n)
    try:
        fp = open(fn, "rb")
    except IOError:
        r = random.random
        result = [r() for i in xrange(n)]
        try:
            try:
                fp = open(fn, "wb")
                marshal.dump(result, fp)
                fp.close()
                fp = None
            finally:
                if fp:
                    try:
                        os.unlink(fn)
                    except os.error:
                        pass
        except IOError, msg:
            print "can't write", fn, ":", msg 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:27,代码来源:sortperf.py

示例2: test_foreign_code

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dump [as 别名]
def test_foreign_code(self):
        py_compile.compile(self.file_name)
        with open(self.compiled_name, "rb") as f:
            header = f.read(8)
            code = marshal.load(f)
        constants = list(code.co_consts)
        foreign_code = test_main.func_code
        pos = constants.index(1)
        constants[pos] = foreign_code
        code = type(code)(code.co_argcount, code.co_nlocals, code.co_stacksize,
                          code.co_flags, code.co_code, tuple(constants),
                          code.co_names, code.co_varnames, code.co_filename,
                          code.co_name, code.co_firstlineno, code.co_lnotab,
                          code.co_freevars, code.co_cellvars)
        with open(self.compiled_name, "wb") as f:
            f.write(header)
            marshal.dump(code, f)
        mod = self.import_module()
        self.assertEqual(mod.constant.co_filename, foreign_code.co_filename) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:21,代码来源:test_import.py

示例3: save_views

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dump [as 别名]
def save_views(self):
        # save the current color
        self.__optiondb['RED'] = self.__red
        self.__optiondb['GREEN'] = self.__green
        self.__optiondb['BLUE'] = self.__blue
        for v in self.__views:
            if hasattr(v, 'save_options'):
                v.save_options(self.__optiondb)
        # save the name of the file used for the color database.  we'll try to
        # load this first.
        self.__optiondb['DBFILE'] = self.__colordb.filename()
        fp = None
        try:
            try:
                fp = open(self.__initfile, 'w')
            except IOError:
                print >> sys.stderr, 'Cannot write options to file:', \
                      self.__initfile
            else:
                marshal.dump(self.__optiondb, fp)
        finally:
            if fp:
                fp.close() 
开发者ID:aliyun,项目名称:oss-ftp,代码行数:25,代码来源:Switchboard.py

示例4: save

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dump [as 别名]
def save(self, fname, iszip=True):
        d = {}
        for k, v in self.__dict__.items():
            if isinstance(v, set):
                d[k] = list(v)
            elif hasattr(v, '__dict__'):
                d[k] = v.__dict__
            else:
                d[k] = v
        if sys.version_info[0] == 3:
            fname = fname + '.3'
        if not iszip:
            marshal.dump(d, open(fname, 'wb'))
        else:
            f = gzip.open(fname, 'wb')
            f.write(marshal.dumps(d))
            f.close() 
开发者ID:bighuang624,项目名称:sentiment-analysis-webapp,代码行数:19,代码来源:tnt.py

示例5: handle_item

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dump [as 别名]
def handle_item(path, item):
        marshal.dump((path, item), stdout)
        return True 
开发者ID:zllrunning,项目名称:hand-detection.PyTorch,代码行数:5,代码来源:xml2dict.py

示例6: marshal_dump

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

示例7: write_bytecode

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dump [as 别名]
def write_bytecode(self, f):
        """Dump the bytecode into the file or file like object passed."""
        if self.code is None:
            raise TypeError('can\'t write empty bucket')
        f.write(bc_magic)
        pickle.dump(self.checksum, f, 2)
        marshal_dump(self.code, f) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:9,代码来源:bccache.py

示例8: dump_stats

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dump [as 别名]
def dump_stats(self, file):
        f = open(file, 'wb')
        self.create_stats()
        marshal.dump(self.stats, f)
        f.close() 
开发者ID:glmcdona,项目名称:meddle,代码行数:7,代码来源:profile.py

示例9: dump_stats

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dump [as 别名]
def dump_stats(self, filename):
        """Write the profile data to a file we know how to load back."""
        f = file(filename, 'wb')
        try:
            marshal.dump(self.stats, f)
        finally:
            f.close()

    # list the tuple indices and directions for sorting,
    # along with some printable description 
开发者ID:glmcdona,项目名称:meddle,代码行数:12,代码来源:pstats.py

示例10: _compile

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dump [as 别名]
def _compile(pathname, timestamp):
    """Compile (and cache) a Python source file.

    The file specified by <pathname> is compiled to a code object and
    returned.

    Presuming the appropriate privileges exist, the bytecodes will be
    saved back to the filesystem for future imports. The source file's
    modification timestamp must be provided as a Long value.
    """
    codestring = open(pathname, 'rU').read()
    if codestring and codestring[-1] != '\n':
        codestring = codestring + '\n'
    code = __builtin__.compile(codestring, pathname, 'exec')

    # try to cache the compiled code
    try:
        f = open(pathname + _suffix_char, 'wb')
    except IOError:
        pass
    else:
        f.write('\0\0\0\0')
        f.write(struct.pack('<I', timestamp))
        marshal.dump(code, f)
        f.flush()
        f.seek(0, 0)
        f.write(imp.get_magic())
        f.close()

    return code 
开发者ID:glmcdona,项目名称:meddle,代码行数:32,代码来源:imputil.py

示例11: dump_stats

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dump [as 别名]
def dump_stats(self, file):
        import marshal
        f = open(file, 'wb')
        self.create_stats()
        marshal.dump(self.stats, f)
        f.close() 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:8,代码来源:cProfile.py

示例12: test_bool

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dump [as 别名]
def test_bool(self):
        for b in (True, False):
            new = marshal.loads(marshal.dumps(b))
            self.assertEqual(b, new)
            self.assertEqual(type(b), type(new))
            marshal.dump(b, file(test_support.TESTFN, "wb"))
            new = marshal.load(file(test_support.TESTFN, "rb"))
            self.assertEqual(b, new)
            self.assertEqual(type(b), type(new)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:11,代码来源:test_marshal.py

示例13: test_unicode

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dump [as 别名]
def test_unicode(self):
        for s in [u"", u"Andr� Previn", u"abc", u" "*10000]:
            new = marshal.loads(marshal.dumps(s))
            self.assertEqual(s, new)
            self.assertEqual(type(s), type(new))
            marshal.dump(s, file(test_support.TESTFN, "wb"))
            new = marshal.load(file(test_support.TESTFN, "rb"))
            self.assertEqual(s, new)
            self.assertEqual(type(s), type(new))
        os.unlink(test_support.TESTFN) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_marshal.py

示例14: test_string

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dump [as 别名]
def test_string(self):
        for s in ["", "Andr� Previn", "abc", " "*10000]:
            new = marshal.loads(marshal.dumps(s))
            self.assertEqual(s, new)
            self.assertEqual(type(s), type(new))
            marshal.dump(s, file(test_support.TESTFN, "wb"))
            new = marshal.load(file(test_support.TESTFN, "rb"))
            self.assertEqual(s, new)
            self.assertEqual(type(s), type(new))
        os.unlink(test_support.TESTFN) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:12,代码来源:test_marshal.py

示例15: test_buffer

# 需要导入模块: import marshal [as 别名]
# 或者: from marshal import dump [as 别名]
def test_buffer(self):
        for s in ["", "Andr� Previn", "abc", " "*10000]:
            with test_support.check_py3k_warnings(("buffer.. not supported",
                                                     DeprecationWarning)):
                b = buffer(s)
            new = marshal.loads(marshal.dumps(b))
            self.assertEqual(s, new)
            marshal.dump(b, file(test_support.TESTFN, "wb"))
            new = marshal.load(file(test_support.TESTFN, "rb"))
            self.assertEqual(s, new)
        os.unlink(test_support.TESTFN) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:13,代码来源:test_marshal.py


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