本文整理汇总了Python中pickle.GLOBAL属性的典型用法代码示例。如果您正苦于以下问题:Python pickle.GLOBAL属性的具体用法?Python pickle.GLOBAL怎么用?Python pickle.GLOBAL使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类pickle
的用法示例。
在下文中一共展示了pickle.GLOBAL属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testWithUserDefinedImport
# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import GLOBAL [as 别名]
def testWithUserDefinedImport(self):
"""test cPickle calling a user defined import function."""
# This tests the fix for http://bugs.jython.org/issue1665
# setup
original_import = __builtin__.__import__
def import_hook(name, _globals=None, locals=None, fromlist=None, level= -1):
return original_import(name, _globals, locals, fromlist, level)
# test
__builtin__.__import__ = import_hook
try:
if "no_such_module" in sys.modules:
del sys.modules["no_such_module"] # force cPickle to call __import__
self.assertRaises(ImportError, cPickle.loads, pickle.GLOBAL + "no_such_module\n" + "no_such_class\n")
finally:
__builtin__.__import__ = original_import
示例2: save_global_byname
# 需要导入模块: import pickle [as 别名]
# 或者: from pickle import GLOBAL [as 别名]
def save_global_byname(self, obj, modname, objname):
""" Save obj as a global reference. Used for objects that pickle does not find correctly. """
self.write('%s%s\n%s\n' % (pickle.GLOBAL, modname, objname))
self.memoize(obj)