本文整理匯總了Python中sys.builtin_module_names方法的典型用法代碼示例。如果您正苦於以下問題:Python sys.builtin_module_names方法的具體用法?Python sys.builtin_module_names怎麽用?Python sys.builtin_module_names使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類sys
的用法示例。
在下文中一共展示了sys.builtin_module_names方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: storeFrameLocals
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import builtin_module_names [as 別名]
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))
示例2: find_module
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import builtin_module_names [as 別名]
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)
示例3: test_module_exceptions
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import builtin_module_names [as 別名]
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 "))
示例4: _check_stdlib_path
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import builtin_module_names [as 別名]
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
示例5: _locate_engine_class
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import builtin_module_names [as 別名]
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
# ____________________________________________________________
示例6: find_module
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import builtin_module_names [as 別名]
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)
示例7: loadModule
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import builtin_module_names [as 別名]
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
示例8: _get_module_names
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import builtin_module_names [as 別名]
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
示例9: describe
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import builtin_module_names [as 別名]
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__
return type(thing).__name__
示例10: is_py2_stdlib_module
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import builtin_module_names [as 別名]
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
示例11: find_module
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import builtin_module_names [as 別名]
def find_module(self, fullname, unused_path=None):
if (fullname in sys.builtin_module_names and
fullname not in _WHITE_LIST_C_MODULES):
return self
return None
示例12: StubModuleExists
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import builtin_module_names [as 別名]
def StubModuleExists(self, name):
"""Check if the named module has a stub replacement."""
if name in sys.builtin_module_names:
name = 'py_%s' % name
if self._config and self._config.runtime == 'python27':
if name in dist27.MODULE_OVERRIDES:
return True
else:
if name in dist.__all__:
return True
return False
示例13: ImportStubModule
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import builtin_module_names [as 別名]
def ImportStubModule(self, name):
"""Import the stub module replacement for the specified module."""
if name in sys.builtin_module_names:
name = 'py_%s' % name
providing_dist = dist
if self._config and self._config.runtime == 'python27':
if name in dist27.__all__:
providing_dist = dist27
fullname = '%s.%s' % (providing_dist.__name__, name)
__import__(fullname, {}, {})
return sys.modules[fullname]
示例14: updateThreadList
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import builtin_module_names [as 別名]
def updateThreadList(self):
"""Updates the list of running threads"""
frames = sys._current_frames()
for threadId, frame in frames.items():
# skip our own timer thread
if frame.f_code.co_name == '__eventPollTimer':
continue
# Unknown thread
if threadId not in self.threads:
newThread = DebugBase(self)
name = 'Thread-{0}'.format(self.threadNumber)
self.threadNumber += 1
newThread.id = threadId
newThread.name = name
self.threads[threadId] = newThread
# adjust current frame
if "__pypy__" not in sys.builtin_module_names:
# Don't update with None
currentFrame = self.getExecutedFrame(frame)
if (currentFrame is not None and
self.threads[threadId].isBroken is False):
self.threads[threadId].currentFrame = currentFrame
# Clean up obsolet because terminated threads
self.threads = {id_: thrd for id_, thrd in self.threads.items()
if id_ in frames}
# find_module(self, fullname, path=None)
示例15: collect_stdlib_distributions
# 需要導入模塊: import sys [as 別名]
# 或者: from sys import builtin_module_names [as 別名]
def collect_stdlib_distributions():
"""Yield a conventional spec and the names of all top_level standard library modules."""
distribution_spec = 'Python==%d.%d.%d' % sys.version_info[:3]
stdlib_path = sysconfig.get_python_lib(standard_lib=True)
distribution_top_level = [name for _, name, _ in pkgutil.iter_modules(path=[stdlib_path])]
distribution_top_level += list(sys.builtin_module_names)
yield distribution_spec, distribution_top_level