Python pickle.GLOBAL Examples

The following are 4 code examples for showing how to use pickle.GLOBAL(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module pickle , or try the search function .

Example 1
Project: medicare-demo   Author: ofermend   File: test_cpickle_jy.py    License: Apache License 2.0 6 votes vote down vote up
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 
Example 2
Project: CTFCrackTools-V2   Author: Acmesec   File: test_cpickle_jy.py    License: GNU General Public License v3.0 6 votes vote down vote up
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 
Example 3
Project: CTFCrackTools   Author: Acmesec   File: test_cpickle_jy.py    License: GNU General Public License v3.0 6 votes vote down vote up
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 
Example 4
Project: code   Author: ActiveState   File: recipe-572213.py    License: MIT License 5 votes vote down vote up
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)