Python sys.builtin_module_names() Examples
The following are 30
code examples of sys.builtin_module_names().
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 also want to check out all available functions/classes of the module
sys
, or try the search function
.
Example #1
Source File: modulefinder.py From ironpython2 with Apache License 2.0 | 6 votes |
def find_module(self, name, path, parent=None): if parent is not None: # assert path is not None fullname = parent.__name__+'.'+name else: fullname = name if fullname in self.excludes: self.msgout(3, "find_module -> Excluded", fullname) raise ImportError, name if path is None: if name in sys.builtin_module_names: return (None, None, ("", "", imp.C_BUILTIN)) path = self.path return imp.find_module(name, path)
Example #2
Source File: base_cdm_dbg.py From codimension with GNU General Public License v3.0 | 6 votes |
def storeFrameLocals(self, frmnr=0): """Stores the locals into the frame. Thus an access to frame.f_locals returns the last data """ cf = self.currentFrame while cf is not None and frmnr > 0: cf = cf.f_back frmnr -= 1 try: if '__pypy__' in sys.builtin_module_names: import __pypy__ __pypy__.locals_to_fast(cf) return except Exception: pass ctypes.pythonapi.PyFrame_LocalsToFast(ctypes.py_object(cf), ctypes.c_int(0))
Example #3
Source File: imports.py From NukeToolSet with MIT License | 6 votes |
def _get_module_names(self, search_path=None): """ Get the names of all modules in the search_path. This means file names and not names defined in the files. """ names = [] # add builtin module names if search_path is None: names += [self._generate_name(name) for name in sys.builtin_module_names] if search_path is None: search_path = self._importer.sys_path_with_modifications() for module_loader, name, is_pkg in pkgutil.iter_modules(search_path): names.append(self._generate_name(name)) return names
Example #4
Source File: test_exceptions.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_module_exceptions(self): """verify exceptions in modules are like user defined exception objects, not built-in types.""" # these modules have normal types... normal_types = ['sys', 'clr', 'exceptions', '__builtin__', '_winreg', 'mmap', 'nt', 'posix'] builtins = [x for x in sys.builtin_module_names if x not in normal_types ] for module in builtins: mod = __import__(module) for attrName in dir(mod): val = getattr(mod, attrName) if isinstance(val, type) and issubclass(val, Exception): if "BlockingIOError" not in repr(val): self.assertTrue(repr(val).startswith("<class ")) val.x = 2 self.assertEqual(val.x, 2) else: self.assertTrue(repr(val).startswith("<type "))
Example #5
Source File: ModuleLevelObjectIndex.py From ufora with Apache License 2.0 | 6 votes |
def loadModule(self, modulename, module): if modulename in self.modulesVisited: return self.modulesVisited.add(modulename) #ignore all modules that are not part of the base python installation. #this is a crude way of deciding which modules are going to be available #on both the host and the server. if modulename not in sys.builtin_module_names and ( not hasattr(module, '__file__') or not os.path.abspath(module.__file__).startswith(sys.prefix) ): return if module is not None: d = dict(module.__dict__) for leafItemName, leafItemValue in d.iteritems(): self.module_objects_by_name["modules", modulename, leafItemName] = leafItemValue self.modules_and_names_by_object[id(leafItemValue)] = ("modules", modulename, leafItemName) self.modules_and_names_by_object[id(module)] = ("modules", modulename) self.module_objects_by_name["modules", modulename] = module
Example #6
Source File: modulefinder.py From meddle with MIT License | 6 votes |
def find_module(self, name, path, parent=None): if parent is not None: # assert path is not None fullname = parent.__name__+'.'+name else: fullname = name if fullname in self.excludes: self.msgout(3, "find_module -> Excluded", fullname) raise ImportError, name if path is None: if name in sys.builtin_module_names: return (None, None, ("", "", imp.C_BUILTIN)) path = self.path return imp.find_module(name, path)
Example #7
Source File: verifier.py From teleport with Apache License 2.0 | 6 votes |
def _locate_engine_class(ffi, force_generic_engine): if _FORCE_GENERIC_ENGINE: force_generic_engine = True if not force_generic_engine: if '__pypy__' in sys.builtin_module_names: force_generic_engine = True else: try: import _cffi_backend except ImportError: _cffi_backend = '?' if ffi._backend is not _cffi_backend: force_generic_engine = True if force_generic_engine: from . import vengine_gen return vengine_gen.VGenericEngine else: from . import vengine_cpy return vengine_cpy.VCPythonEngine # ____________________________________________________________
Example #8
Source File: verifier.py From teleport with Apache License 2.0 | 6 votes |
def _locate_engine_class(ffi, force_generic_engine): if _FORCE_GENERIC_ENGINE: force_generic_engine = True if not force_generic_engine: if '__pypy__' in sys.builtin_module_names: force_generic_engine = True else: try: import _cffi_backend except ImportError: _cffi_backend = '?' if ffi._backend is not _cffi_backend: force_generic_engine = True if force_generic_engine: from . import vengine_gen return vengine_gen.VGenericEngine else: from . import vengine_cpy return vengine_cpy.VCPythonEngine # ____________________________________________________________
Example #9
Source File: import_analyzer.py From msticpy with MIT License | 6 votes |
def _check_stdlib_path(module, mod_name, stdlib_paths): if ( not module or mod_name in sys.builtin_module_names or not hasattr(module, "__file__") ): # an import sentinel, built-in module or not a real module, really return mod_name # Test the path fname = module.__file__ if fname.endswith(("__init__.py", "__init__.pyc", "__init__.pyo")): fname = Path(fname).parent if "site-packages" in str(fname).lower(): return None # step up the module path while Path(fname) != Path(fname).parent: if str(fname).lower() in stdlib_paths: # stdlib path, skip return mod_name fname = Path(fname).parent return None
Example #10
Source File: verifier.py From bioforum with MIT License | 6 votes |
def _locate_engine_class(ffi, force_generic_engine): if _FORCE_GENERIC_ENGINE: force_generic_engine = True if not force_generic_engine: if '__pypy__' in sys.builtin_module_names: force_generic_engine = True else: try: import _cffi_backend except ImportError: _cffi_backend = '?' if ffi._backend is not _cffi_backend: force_generic_engine = True if force_generic_engine: from . import vengine_gen return vengine_gen.VGenericEngine else: from . import vengine_cpy return vengine_cpy.VCPythonEngine # ____________________________________________________________
Example #11
Source File: modulefinder.py From BinderFilter with MIT License | 6 votes |
def find_module(self, name, path, parent=None): if parent is not None: # assert path is not None fullname = parent.__name__+'.'+name else: fullname = name if fullname in self.excludes: self.msgout(3, "find_module -> Excluded", fullname) raise ImportError, name if path is None: if name in sys.builtin_module_names: return (None, None, ("", "", imp.C_BUILTIN)) path = self.path return imp.find_module(name, path)
Example #12
Source File: modulefinder.py From Computable with MIT License | 6 votes |
def find_module(self, name, path, parent=None): if parent is not None: # assert path is not None fullname = parent.__name__+'.'+name else: fullname = name if fullname in self.excludes: self.msgout(3, "find_module -> Excluded", fullname) raise ImportError, name if path is None: if name in sys.builtin_module_names: return (None, None, ("", "", imp.C_BUILTIN)) path = self.path return imp.find_module(name, path)
Example #13
Source File: verifier.py From SwiftKitten with MIT License | 6 votes |
def _locate_engine_class(ffi, force_generic_engine): if _FORCE_GENERIC_ENGINE: force_generic_engine = True if not force_generic_engine: if '__pypy__' in sys.builtin_module_names: force_generic_engine = True else: try: import _cffi_backend except ImportError: _cffi_backend = '?' if ffi._backend is not _cffi_backend: force_generic_engine = True if force_generic_engine: from . import vengine_gen return vengine_gen.VGenericEngine else: from . import vengine_cpy return vengine_cpy.VCPythonEngine # ____________________________________________________________
Example #14
Source File: modulefinder.py From oss-ftp with MIT License | 6 votes |
def find_module(self, name, path, parent=None): if parent is not None: # assert path is not None fullname = parent.__name__+'.'+name else: fullname = name if fullname in self.excludes: self.msgout(3, "find_module -> Excluded", fullname) raise ImportError, name if path is None: if name in sys.builtin_module_names: return (None, None, ("", "", imp.C_BUILTIN)) path = self.path return imp.find_module(name, path)
Example #15
Source File: verifier.py From oss-ftp with MIT License | 6 votes |
def _locate_engine_class(ffi, force_generic_engine): if _FORCE_GENERIC_ENGINE: force_generic_engine = True if not force_generic_engine: if '__pypy__' in sys.builtin_module_names: force_generic_engine = True else: try: import _cffi_backend except ImportError: _cffi_backend = '?' if ffi._backend is not _cffi_backend: force_generic_engine = True if force_generic_engine: from . import vengine_gen return vengine_gen.VGenericEngine else: from . import vengine_cpy return vengine_cpy.VCPythonEngine # ____________________________________________________________
Example #16
Source File: verifier.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 6 votes |
def _locate_engine_class(ffi, force_generic_engine): if _FORCE_GENERIC_ENGINE: force_generic_engine = True if not force_generic_engine: if '__pypy__' in sys.builtin_module_names: force_generic_engine = True else: try: import _cffi_backend except ImportError: _cffi_backend = '?' if ffi._backend is not _cffi_backend: force_generic_engine = True if force_generic_engine: from . import vengine_gen return vengine_gen.VGenericEngine else: from . import vengine_cpy return vengine_cpy.VCPythonEngine # ____________________________________________________________
Example #17
Source File: mf27.py From pydeps with BSD 2-Clause "Simplified" License | 6 votes |
def find_module(self, name, path, parent=None): if parent is not None: # assert path is not None fullname = parent.__name__ + '.' + name else: fullname = name if fullname in self.excludes: self.msgout(3, "find_module -> Excluded", fullname) raise ImportError(name) if path is None: if name in sys.builtin_module_names: return (None, None, ("", "", imp.C_BUILTIN)) path = self.path return imp.find_module(name, path)
Example #18
Source File: test_zipimport.py From oss-ftp with MIT License | 5 votes |
def testAFakeZlib(self): # # This could cause a stack overflow before: importing zlib.py # from a compressed archive would cause zlib to be imported # which would find zlib.py in the archive, which would... etc. # # This test *must* be executed first: it must be the first one # to trigger zipimport to import zlib (zipimport caches the # zlib.decompress function object, after which the problem being # tested here wouldn't be a problem anymore... # (Hence the 'A' in the test method name: to make it the first # item in a list sorted by name, like unittest.makeSuite() does.) # # This test fails on platforms on which the zlib module is # statically linked, but the problem it tests for can't # occur in that case (builtin modules are always found first), # so we'll simply skip it then. Bug #765456. # if "zlib" in sys.builtin_module_names: return if "zlib" in sys.modules: del sys.modules["zlib"] files = {"zlib.py": (NOW, test_src)} try: self.doTest(".py", files, "zlib") except ImportError: if self.compression != ZIP_DEFLATED: self.fail("expected test to not raise ImportError") else: if self.compression != ZIP_STORED: self.fail("expected test to raise ImportError")
Example #19
Source File: pydevd_save_locals.py From PyDev.Debugger with Eclipse Public License 1.0 | 5 votes |
def make_save_locals_impl(): """ Factory for the 'save_locals_impl' method. This may seem like a complicated pattern but it is essential that the method is created at module load time. Inner imports after module load time would cause an occasional debugger deadlock due to the importer lock and debugger lock being taken in different order in different threads. """ try: if '__pypy__' in sys.builtin_module_names: import __pypy__ # @UnresolvedImport save_locals = __pypy__.locals_to_fast except: pass else: if '__pypy__' in sys.builtin_module_names: def save_locals_pypy_impl(frame): save_locals(frame) return save_locals_pypy_impl try: import ctypes locals_to_fast = ctypes.pythonapi.PyFrame_LocalsToFast except: pass else: def save_locals_ctypes_impl(frame): locals_to_fast(ctypes.py_object(frame), ctypes.c_int(0)) return save_locals_ctypes_impl return None
Example #20
Source File: pydoc.py From Computable with MIT License | 5 votes |
def run(self, callback, key=None, completer=None, onerror=None): if key: key = lower(key) self.quit = False seen = {} for modname in sys.builtin_module_names: if modname != '__main__': seen[modname] = 1 if key is None: callback(None, modname, '') else: desc = split(__import__(modname).__doc__ or '', '\n')[0] if find(lower(modname + ' - ' + desc), key) >= 0: callback(None, modname, desc) for importer, modname, ispkg in pkgutil.walk_packages(onerror=onerror): if self.quit: break if key is None: callback(None, modname, '') else: loader = importer.find_module(modname) if hasattr(loader,'get_source'): import StringIO desc = source_synopsis( StringIO.StringIO(loader.get_source(modname)) ) or '' if hasattr(loader,'get_filename'): path = loader.get_filename(modname) else: path = None else: module = loader.load_module(modname) desc = (module.__doc__ or '').splitlines()[0] path = getattr(module,'__file__',None) if find(lower(modname + ' - ' + desc), key) >= 0: callback(path, modname, desc) if completer: completer()
Example #21
Source File: pydoc.py From Computable with MIT License | 5 votes |
def describe(thing): """Produce a short description of the given thing.""" if inspect.ismodule(thing): if thing.__name__ in sys.builtin_module_names: return 'built-in module ' + thing.__name__ if hasattr(thing, '__path__'): return 'package ' + thing.__name__ else: return 'module ' + thing.__name__ if inspect.isbuiltin(thing): return 'built-in function ' + thing.__name__ if inspect.isgetsetdescriptor(thing): return 'getset descriptor %s.%s.%s' % ( thing.__objclass__.__module__, thing.__objclass__.__name__, thing.__name__) if inspect.ismemberdescriptor(thing): return 'member descriptor %s.%s.%s' % ( thing.__objclass__.__module__, thing.__objclass__.__name__, thing.__name__) if inspect.isclass(thing): return 'class ' + thing.__name__ if inspect.isfunction(thing): return 'function ' + thing.__name__ if inspect.ismethod(thing): return 'method ' + thing.__name__ if type(thing) is types.InstanceType: return 'instance of ' + thing.__class__.__name__ return type(thing).__name__
Example #22
Source File: __init__.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def is_py2_stdlib_module(m): """ Tries to infer whether the module m is from the Python 2 standard library. This may not be reliable on all systems. """ if PY3: return False if not 'stdlib_path' in is_py2_stdlib_module.__dict__: stdlib_files = [contextlib.__file__, os.__file__, copy.__file__] stdlib_paths = [os.path.split(f)[0] for f in stdlib_files] if not len(set(stdlib_paths)) == 1: # This seems to happen on travis-ci.org. Very strange. We'll try to # ignore it. flog.warn('Multiple locations found for the Python standard ' 'library: %s' % stdlib_paths) # Choose the first one arbitrarily is_py2_stdlib_module.stdlib_path = stdlib_paths[0] if m.__name__ in sys.builtin_module_names: return True if hasattr(m, '__file__'): modpath = os.path.split(m.__file__) if (modpath[0].startswith(is_py2_stdlib_module.stdlib_path) and 'site-packages' not in modpath[0]): return True return False
Example #23
Source File: completerlib.py From Computable with MIT License | 5 votes |
def get_root_modules(): """ Returns a list containing the names of all the modules available in the folders of the pythonpath. ip.db['rootmodules_cache'] maps sys.path entries to list of modules. """ ip = get_ipython() rootmodules_cache = ip.db.get('rootmodules_cache', {}) rootmodules = list(sys.builtin_module_names) start_time = time() store = False for path in sys.path: try: modules = rootmodules_cache[path] except KeyError: modules = module_list(path) try: modules.remove('__init__') except ValueError: pass if path not in ('', '.'): # cwd modules should not be cached rootmodules_cache[path] = modules if time() - start_time > TIMEOUT_STORAGE and not store: store = True print("\nCaching the list of root modules, please wait!") print("(This will only be done once - type '%rehashx' to " "reset cache!)\n") sys.stdout.flush() if time() - start_time > TIMEOUT_GIVEUP: print("This is taking too long, we give up.\n") return [] rootmodules.extend(modules) if store: ip.db['rootmodules_cache'] = rootmodules_cache rootmodules = list(set(rootmodules)) return rootmodules
Example #24
Source File: __init__.py From kgsgo-dataset-preprocessor with Mozilla Public License 2.0 | 5 votes |
def is_py2_stdlib_module(m): """ Tries to infer whether the module m is from the Python 2 standard library. This may not be reliable on all systems. """ if PY3: return False if not 'stdlib_path' in is_py2_stdlib_module.__dict__: stdlib_files = [contextlib.__file__, os.__file__, copy.__file__] stdlib_paths = [os.path.split(f)[0] for f in stdlib_files] if not len(set(stdlib_paths)) == 1: # This seems to happen on travis-ci.org. Very strange. We'll try to # ignore it. flog.warn('Multiple locations found for the Python standard ' 'library: %s' % stdlib_paths) # Choose the first one arbitrarily is_py2_stdlib_module.stdlib_path = stdlib_paths[0] if m.__name__ in sys.builtin_module_names: return True if hasattr(m, '__file__'): modpath = os.path.split(m.__file__) if (modpath[0].startswith(is_py2_stdlib_module.stdlib_path) and 'site-packages' not in modpath[0]): return True return False
Example #25
Source File: imputil.py From BinderFilter with MIT License | 5 votes |
def _os_bootstrap(): "Set up 'os' module replacement functions for use during import bootstrap." names = sys.builtin_module_names join = None if 'posix' in names: sep = '/' from posix import stat elif 'nt' in names: sep = '\\' from nt import stat elif 'dos' in names: sep = '\\' from dos import stat elif 'os2' in names: sep = '\\' from os2 import stat else: raise ImportError, 'no os specific module found' if join is None: def join(a, b, sep=sep): if a == '': return b lastchar = a[-1:] if lastchar == '/' or lastchar == sep: return a + b return a + sep + b global _os_stat _os_stat = stat global _os_path_join _os_path_join = join
Example #26
Source File: test_c.py From SwiftKitten with MIT License | 5 votes |
def _setup_path(): import os, sys if '__pypy__' in sys.builtin_module_names: py.test.skip("_cffi_backend.c: not tested on top of pypy, " "use pypy/module/_cffi_backend/test/ instead.") sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
Example #27
Source File: test_zipimport.py From BinderFilter with MIT License | 5 votes |
def testAFakeZlib(self): # # This could cause a stack overflow before: importing zlib.py # from a compressed archive would cause zlib to be imported # which would find zlib.py in the archive, which would... etc. # # This test *must* be executed first: it must be the first one # to trigger zipimport to import zlib (zipimport caches the # zlib.decompress function object, after which the problem being # tested here wouldn't be a problem anymore... # (Hence the 'A' in the test method name: to make it the first # item in a list sorted by name, like unittest.makeSuite() does.) # # This test fails on platforms on which the zlib module is # statically linked, but the problem it tests for can't # occur in that case (builtin modules are always found first), # so we'll simply skip it then. Bug #765456. # if "zlib" in sys.builtin_module_names: return if "zlib" in sys.modules: del sys.modules["zlib"] files = {"zlib.py": (NOW, test_src)} try: self.doTest(".py", files, "zlib") except ImportError: if self.compression != ZIP_DEFLATED: self.fail("expected test to not raise ImportError") else: if self.compression != ZIP_STORED: self.fail("expected test to raise ImportError")
Example #28
Source File: test_version.py From SwiftKitten with MIT License | 5 votes |
def setup_module(mod): if '_cffi_backend' in sys.builtin_module_names: py.test.skip("this is embedded version") #BACKEND_VERSIONS = { # '0.4.2': '0.4', # did not change # '0.7.1': '0.7', # did not change # '0.7.2': '0.7', # did not change # '0.8.1': '0.8', # did not change (essentially) # '0.8.4': '0.8.3', # did not change # }
Example #29
Source File: pydoc.py From BinderFilter with MIT License | 5 votes |
def run(self, callback, key=None, completer=None, onerror=None): if key: key = lower(key) self.quit = False seen = {} for modname in sys.builtin_module_names: if modname != '__main__': seen[modname] = 1 if key is None: callback(None, modname, '') else: desc = split(__import__(modname).__doc__ or '', '\n')[0] if find(lower(modname + ' - ' + desc), key) >= 0: callback(None, modname, desc) for importer, modname, ispkg in pkgutil.walk_packages(onerror=onerror): if self.quit: break if key is None: callback(None, modname, '') else: loader = importer.find_module(modname) if hasattr(loader,'get_source'): import StringIO desc = source_synopsis( StringIO.StringIO(loader.get_source(modname)) ) or '' if hasattr(loader,'get_filename'): path = loader.get_filename(modname) else: path = None else: module = loader.load_module(modname) desc = (module.__doc__ or '').splitlines()[0] path = getattr(module,'__file__',None) if find(lower(modname + ' - ' + desc), key) >= 0: callback(path, modname, desc) if completer: completer()
Example #30
Source File: __init__.py From misp42splunk with GNU Lesser General Public License v3.0 | 5 votes |
def is_py2_stdlib_module(m): """ Tries to infer whether the module m is from the Python 2 standard library. This may not be reliable on all systems. """ if PY3: return False if not 'stdlib_path' in is_py2_stdlib_module.__dict__: stdlib_files = [contextlib.__file__, os.__file__, copy.__file__] stdlib_paths = [os.path.split(f)[0] for f in stdlib_files] if not len(set(stdlib_paths)) == 1: # This seems to happen on travis-ci.org. Very strange. We'll try to # ignore it. flog.warn('Multiple locations found for the Python standard ' 'library: %s' % stdlib_paths) # Choose the first one arbitrarily is_py2_stdlib_module.stdlib_path = stdlib_paths[0] if m.__name__ in sys.builtin_module_names: return True if hasattr(m, '__file__'): modpath = os.path.split(m.__file__) if (modpath[0].startswith(is_py2_stdlib_module.stdlib_path) and 'site-packages' not in modpath[0]): return True return False