本文整理汇总了Python中types.ModuleType.__init__方法的典型用法代码示例。如果您正苦于以下问题:Python ModuleType.__init__方法的具体用法?Python ModuleType.__init__怎么用?Python ModuleType.__init__使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类types.ModuleType
的用法示例。
在下文中一共展示了ModuleType.__init__方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __init__ [as 别名]
def __init__(self, name, modulenames):
module.__init__(self)
self.__name__ = name
if isinstance(modulenames, str):
modulenames = [modulenames]
self.__modulenames = modulenames
self.__modules = None
示例2: __init__
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __init__ [as 别名]
def __init__(self, module, locals):
ModuleType.__init__(self, locals['__name__'])
self._imports = {}
ns = self.__dict__
ns.update(locals)
ns['__module__'] = self
lazy_symbols = {}
for symbol in module._get_symbol_names():
lazy_symbols[symbol] = ns[symbol] = _marker
ns.update(__dict__=LazyDict(self),
__bases__=(ModuleType,),
add_submodule=self.add_submodule)
def __getattribute__(_, name):
v = ns.get(name, _marker)
if v is not _marker:
return v
if name in lazy_symbols:
s = module._get_symbol(ns, name)
return s
elif name in self._imports:
m = __import__(self._imports[name], {}, {}, ' ')
ns[name] = m
return m
raise AttributeError(name)
LazyNamespace.__getattribute__ = __getattribute__
示例3: __init__
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __init__ [as 别名]
def __init__(self, module, deferred, **attributes):
ModuleType.__init__(self, module.__name__, module.__doc__ or None)
self.__dict__.update(attributes)
self.__shadowing = module
self.__all__ = []
self.__pushed_up = {}
self.__file__ = module.__file__
self.__path__ = module.__path__
for submodule, pushed_up in six.iteritems(deferred):
self.__all__.append(submodule)
if pushed_up:
for member in pushed_up:
self.__pushed_up[member] = submodule
self.__all__.extend(pushed_up)
示例4: __init__
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __init__ [as 别名]
def __init__(self, name, scope):
ModuleType.__init__(self, scope.__name__)
modclass = type(self)
class Module(type(self)):
def __getattribute__(self, name):
if name in ['__class__', '__path__']:
return modclass.__getattribute__(self, name)
return getattr(scope, name)
def __repr__(self):
return "<%s for %s>" % (modclass.__name__, repr(scope))
self.__class__ = Module
示例5: _hacky_make_metamodule
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __init__ [as 别名]
def _hacky_make_metamodule(orig_module, class_):
# Construct the new module instance by hand, calling only ModuleType
# methods, so as to simulate what happens in the __class__ assignment
# path.
new_module = ModuleType.__new__(class_)
ModuleType.__init__(new_module, orig_module.__name__, orig_module.__doc__)
# Now we jump through hoops to get at the module object guts...
import ctypes
# These are the only fields in the module object in CPython 1.0
# through 2.7.
fields = [
("PyObject_HEAD", ctypes.c_byte * object.__basicsize__),
("md_dict", ctypes.c_void_p),
]
data_fields = ["md_dict"]
# 3.0 adds PEP 3121 stuff:
if (3,) <= sys.version_info:
fields += [("md_def", ctypes.c_void_p),
("md_state", ctypes.c_void_p),
]
data_fields += ["md_def", "md_state"]
# 3.4 adds md_weaklist and md_name
if (3, 4) <= sys.version_info:
fields += [("md_weaklist", ctypes.c_void_p),
("md_name", ctypes.c_void_p),
]
# don't try to mess with md_weaklist, that seems unlikely to end
# well.
data_fields += ["md_name"]
if (3, 5) <= sys.version_info:
raise RuntimeError("Sorry, I can't read the future!")
class CModule(ctypes.Structure):
_fields_ = fields
corig_module = ctypes.cast(id(orig_module), ctypes.POINTER(CModule))
cnew_module = ctypes.cast(id(new_module), ctypes.POINTER(CModule))
# And now we swap the two module's internal data fields. This makes
# reference counting easier, plus prevents the destruction of orig_module
# from cleaning up the objects we are still using.
for data_field in data_fields:
_swap_attr(corig_module.contents, cnew_module.contents, data_field)
return new_module
示例6: __init__
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __init__ [as 别名]
def __init__(
self, name, __all__=None,
aliases=None, deprecated_aliases=None,
__getitem__=None, __iter__=None, __call__=None
):
"""
Wraps a package module given by `name`.
Original package module object is replaced in ``sys.modules`` and
stored in :attr:``.__module__``
Optional `__all__` list defines the package API
Optional `aliases` and `deprecated_aliases` map alternative names to
API names
`__getitem__`, `__iter__`, and `__call__` features can be added to the
package wrapper by providing handler functions or other callable
objects (which are not called with a ``self`` argument)
"""
mod = sys.modules[name]
ModuleType.__init__(self, name, mod.__doc__)
self.__name__ = name
self.__module__ = mod
sys.modules[name] = self
self.__dict__['__all__'] = api \
= dict.fromkeys(__all__) if __all__ is not None else {}
if aliases is not None:
api.update(aliases)
if deprecated_aliases is not None:
api.update((deprecated(alias), name)
for alias, name in dict(deprecated_aliases).items())
# if api is not None:
# for submodname, members in dict(__all__).items():
# self.__dict__['__all__'].update(
# (name, submodname) for name in members)
cls = type(self)
cls.__getitem__.funcs[self] = __getitem__
cls.__iter__.funcs[self] = __iter__
cls.__call__.funcs[self] = __call__
示例7: __new__
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __init__ [as 别名]
def __new__(cls, name):
"""Returns a namespace with a given name, creating it if needed.
Adds standard imports to a module without clojure.core.
clojure.core is special-cased: being the first created module, some
specific Vars must be added "by hand" (currently: *ns*,
*command-line-args*).
"""
if isinstance(name, Symbol):
name = name.name
if not sys.modules.get(name):
mod = ModuleType.__new__(cls)
ModuleType.__init__(mod, name)
mod.__file__ = "<interactive namespace>"
for i in dir(stdimps):
if i.startswith("_"):
continue
setattr(mod, i, getattr(stdimps, i))
if mod.__name__ == "clojure.core":
setattr(mod, "*ns*", Var(mod, "*ns*", mod).setDynamic())
setattr(mod, "*command-line-args*",
Var(mod, "*command-line-args*", None).setDynamic())
sys.modules[name] = mod
return sys.modules[name]
示例8: __init__
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __init__ [as 别名]
def __init__(self, name, system_import):
ModuleType.__init__(self, name)
self._system_import = system_import
self.enabled = True
示例9: __init__
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __init__ [as 别名]
def __init__(self, name, attrmap, proxy=None):
ModuleType.__init__(self, name)
self.__attrmap = attrmap
self.__proxy = proxy
self.__log = logging.getLogger(name)
示例10: __init__
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __init__ [as 别名]
def __init__(self, name, system_import):
ModuleType.__init__(self, name)
self._system_import = system_import
self._modules_to_patch = {}
self.inside_activation = False
示例11: __init__
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __init__ [as 别名]
def __init__(self, name):
ModuleType.__init__(self, name)
_proxy.ModelProxy.__init__(self, name)
示例12: __init__
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __init__ [as 别名]
def __init__(self, name):
ModuleType.__init__(self, name)
#self.__dict__ = GlassDict()
#self.mod_dict = self.__dict__
print "GnuModule of name %r created, dict is %r." % (name, id(self.__dict__))
示例13: __init__
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __init__ [as 别名]
def __init__(self, name):
ModuleType.__init__(self, name, __doc__)
self.__file__ = None
self.__package__ = ".".join(name.split(".")[:-1])
示例14: __init__
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __init__ [as 别名]
def __init__(self, name, system_import):
ModuleType.__init__(self, name)
self._system_import = system_import
self._modules_to_patch = {}
示例15: __init__
# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __init__ [as 别名]
def __init__(self, name):
ModuleType.__init__(self, name)
object.__setattr__(self, "__module", None)