Python pickle.whichmodule() Examples
The following are 27 code examples for showing how to use pickle.whichmodule(). 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: pywren-ibm-cloud Author: pywren File: cloudpickle.py License: Apache License 2.0 | 6 votes |
def _whichmodule(obj, name): """Find the module an object belongs to. This function differs from ``pickle.whichmodule`` in two ways: - it does not mangle the cases where obj's module is __main__ and obj was not found in any module. - Errors arising during module introspection are ignored, as those errors are considered unwanted side effects. """ module_name = getattr(obj, '__module__', None) if module_name is not None: return module_name # Protect the iteration by using a list copy of sys.modules against dynamic # modules that trigger imports of other modules upon calls to getattr. for module_name, module in list(sys.modules.items()): if module_name == '__main__' or module is None: continue try: if _getattribute(module, name)[0] is obj: return module_name except Exception: pass return None
Example 2
Project: ironpython2 Author: IronLanguages File: win32serviceutil.py License: Apache License 2.0 | 6 votes |
def GetServiceClassString(cls, argv = None): if argv is None: argv = sys.argv import pickle modName = pickle.whichmodule(cls, cls.__name__) if modName == '__main__': try: fname = win32api.GetFullPathName(argv[0]) path = os.path.split(fname)[0] # Eaaaahhhh - sometimes this will be a short filename, which causes # problems with 1.5.1 and the silly filename case rule. # Get the long name fname = os.path.join(path, win32api.FindFiles(fname)[0][8]) except win32api.error: raise error("Could not resolve the path name '%s' to a full path" % (argv[0])) modName = os.path.splitext(fname)[0] return modName + "." + cls.__name__
Example 3
Project: recruit Author: Frank-qlu File: __init__.py License: Apache License 2.0 | 5 votes |
def _ufunc_reduce(func): from pickle import whichmodule name = func.__name__ return _ufunc_reconstruct, (whichmodule(func, name), name)
Example 4
Project: lambda-packs Author: ryfeus File: __init__.py License: MIT License | 5 votes |
def _ufunc_reduce(func): from pickle import whichmodule name = func.__name__ return _ufunc_reconstruct, (whichmodule(func, name), name)
Example 5
Project: auto-alt-text-lambda-api Author: abhisuri97 File: __init__.py License: MIT License | 5 votes |
def _ufunc_reduce(func): from pickle import whichmodule name = func.__name__ return _ufunc_reconstruct, (whichmodule(func, name), name)
Example 6
Project: vnpy_crypto Author: birforce File: __init__.py License: MIT License | 5 votes |
def _ufunc_reduce(func): from pickle import whichmodule name = func.__name__ return _ufunc_reconstruct, (whichmodule(func, name), name)
Example 7
Project: Computable Author: ktraunmueller File: __init__.py License: MIT License | 5 votes |
def _ufunc_reduce(func): from pickle import whichmodule name = func.__name__ return _ufunc_reconstruct, (whichmodule(func, name), name)
Example 8
Project: Mastering-Elasticsearch-7.0 Author: PacktPublishing File: __init__.py License: MIT License | 5 votes |
def _ufunc_reduce(func): from pickle import whichmodule name = func.__name__ return _ufunc_reconstruct, (whichmodule(func, name), name)
Example 9
Project: Safejumper-for-Desktop Author: proxysh File: reflect.py License: GNU General Public License v2.0 | 5 votes |
def fullFuncName(func): qualName = (str(pickle.whichmodule(func, func.__name__)) + '.' + func.__name__) if namedObject(qualName) is not func: raise Exception("Couldn't find %s as %s." % (func, qualName)) return qualName
Example 10
Project: GraphicDesignPatternByPython Author: Relph1119 File: __init__.py License: MIT License | 5 votes |
def _ufunc_reduce(func): from pickle import whichmodule name = func.__name__ return _ufunc_reconstruct, (whichmodule(func, name), name)
Example 11
Project: predictive-maintenance-using-machine-learning Author: awslabs File: __init__.py License: Apache License 2.0 | 5 votes |
def _ufunc_reduce(func): from pickle import whichmodule name = func.__name__ return _ufunc_reconstruct, (whichmodule(func, name), name)
Example 12
Project: Fluid-Designer Author: Microvellum File: __init__.py License: GNU General Public License v3.0 | 5 votes |
def _ufunc_reduce(func): from pickle import whichmodule name = func.__name__ return _ufunc_reconstruct, (whichmodule(func, name), name)
Example 13
Project: pySINDy Author: luckystarufo File: __init__.py License: MIT License | 5 votes |
def _ufunc_reduce(func): from pickle import whichmodule name = func.__name__ return _ufunc_reconstruct, (whichmodule(func, name), name)
Example 14
Project: learn_python3_spider Author: wistbean File: reflect.py License: MIT License | 5 votes |
def fullFuncName(func): qualName = (str(pickle.whichmodule(func, func.__name__)) + '.' + func.__name__) if namedObject(qualName) is not func: raise Exception("Couldn't find %s as %s." % (func, qualName)) return qualName
Example 15
Project: mxnet-lambda Author: awslabs File: __init__.py License: Apache License 2.0 | 5 votes |
def _ufunc_reduce(func): from pickle import whichmodule name = func.__name__ return _ufunc_reconstruct, (whichmodule(func, name), name)
Example 16
Project: ray Author: ray-project File: cloudpickle.py License: Apache License 2.0 | 5 votes |
def _whichmodule(obj, name): """Find the module an object belongs to. This function differs from ``pickle.whichmodule`` in two ways: - it does not mangle the cases where obj's module is __main__ and obj was not found in any module. - Errors arising during module introspection are ignored, as those errors are considered unwanted side effects. """ if sys.version_info[:2] < (3, 7) and isinstance(obj, typing.TypeVar): # pragma: no branch # noqa # Workaround bug in old Python versions: prior to Python 3.7, # T.__module__ would always be set to "typing" even when the TypeVar T # would be defined in a different module. # # For such older Python versions, we ignore the __module__ attribute of # TypeVar instances and instead exhaustively lookup those instances in # all currently imported modules. module_name = None else: module_name = getattr(obj, '__module__', None) if module_name is not None: return module_name # Protect the iteration by using a copy of sys.modules against dynamic # modules that trigger imports of other modules upon calls to getattr or # other threads importing at the same time. for module_name, module in sys.modules.copy().items(): # Some modules such as coverage can inject non-module objects inside # sys.modules if ( module_name == '__main__' or module is None or not isinstance(module, types.ModuleType) ): continue try: if _getattribute(module, name)[0] is obj: return module_name except Exception: pass return None
Example 17
Project: ImageFusion Author: pfchai File: __init__.py License: MIT License | 5 votes |
def _ufunc_reduce(func): from pickle import whichmodule name = func.__name__ return _ufunc_reconstruct, (whichmodule(func, name), name)
Example 18
Project: Splunking-Crime Author: nccgroup File: __init__.py License: GNU Affero General Public License v3.0 | 5 votes |
def _ufunc_reduce(func): from pickle import whichmodule name = func.__name__ return _ufunc_reconstruct, (whichmodule(func, name), name)
Example 19
Project: python-for-android Author: kuri65536 File: reflect.py License: Apache License 2.0 | 5 votes |
def fullFuncName(func): qualName = (str(pickle.whichmodule(func, func.__name__)) + '.' + func.__name__) if namedObject(qualName) is not func: raise Exception("Couldn't find %s as %s." % (func, qualName)) return qualName
Example 20
Project: BitTorrent Author: kenorb-contrib File: reflect.py License: GNU General Public License v3.0 | 5 votes |
def fullFuncName(func): qualName = (str(pickle.whichmodule(func, func.__name__)) + '.' + func.__name__) if namedObject(qualName) is not func: raise Exception("Couldn't find %s as %s." % (func, qualName)) return qualName
Example 21
Project: pywren Author: pywren File: cloudpickle.py License: Apache License 2.0 | 5 votes |
def save_global(self, obj, name=None, pack=struct.pack): """ Save a "global". The name of this method is somewhat misleading: all types get dispatched here. """ if obj.__module__ == "__builtin__" or obj.__module__ == "builtins": if obj in _BUILTIN_TYPE_NAMES: return self.save_reduce(_builtin_type, (_BUILTIN_TYPE_NAMES[obj],), obj=obj) if name is None: name = obj.__name__ modname = getattr(obj, "__module__", None) if modname is None: try: # whichmodule() could fail, see # https://bitbucket.org/gutworth/six/issues/63/importing-six-breaks-pickling modname = pickle.whichmodule(obj, name) except Exception: modname = '__main__' if modname == '__main__': themodule = None else: __import__(modname) themodule = sys.modules[modname] self.modules.add(themodule) if hasattr(themodule, name) and getattr(themodule, name) is obj: return Pickler.save_global(self, obj, name) typ = type(obj) if typ is not obj and isinstance(obj, (type, types.ClassType)): self.save_dynamic_class(obj) else: raise pickle.PicklingError("Can't pickle %r" % obj)
Example 22
Project: elasticintel Author: securityclippy File: __init__.py License: GNU General Public License v3.0 | 5 votes |
def _ufunc_reduce(func): from pickle import whichmodule name = func.__name__ return _ufunc_reconstruct, (whichmodule(func, name), name)
Example 23
Project: coffeegrindsize Author: jgagneastro File: __init__.py License: MIT License | 5 votes |
def _ufunc_reduce(func): from pickle import whichmodule name = func.__name__ return _ufunc_reconstruct, (whichmodule(func, name), name)
Example 24
Project: Carnets Author: holzschu File: __init__.py License: BSD 3-Clause "New" or "Revised" License | 5 votes |
def _ufunc_reduce(func): from pickle import whichmodule name = func.__name__ return _ufunc_reconstruct, (whichmodule(func, name), name)
Example 25
Project: Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda Author: PacktPublishing File: __init__.py License: MIT License | 5 votes |
def _ufunc_reduce(func): from pickle import whichmodule name = func.__name__ return _ufunc_reconstruct, (whichmodule(func, name), name)
Example 26
Project: twitter-stock-recommendation Author: alvarobartt File: __init__.py License: MIT License | 5 votes |
def _ufunc_reduce(func): from pickle import whichmodule name = func.__name__ return _ufunc_reconstruct, (whichmodule(func, name), name)
Example 27
Project: keras-lambda Author: sunilmallya File: __init__.py License: MIT License | 5 votes |
def _ufunc_reduce(func): from pickle import whichmodule name = func.__name__ return _ufunc_reconstruct, (whichmodule(func, name), name)