当前位置: 首页>>代码示例>>Python>>正文


Python ModuleType.__init__方法代码示例

本文整理汇总了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
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:9,代码来源:compat.py

示例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__
开发者ID:andrewbird,项目名称:vodafone-mobile-connect,代码行数:31,代码来源:_lazyutils.py

示例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)
开发者ID:mbr,项目名称:flatland0,代码行数:17,代码来源:deferred.py

示例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
开发者ID:pombredanne,项目名称:zetup.py,代码行数:17,代码来源:__init__.py

示例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
开发者ID:njsmith,项目名称:metamodule,代码行数:49,代码来源:metamodule.py

示例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__
开发者ID:userzimmermann,项目名称:zetup.py,代码行数:42,代码来源:modules.py

示例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]
开发者ID:khinsen,项目名称:clojure-py,代码行数:26,代码来源:namespace.py

示例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
开发者ID:mitsuhiko,项目名称:pluginbase,代码行数:6,代码来源:pluginbase.py

示例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)
开发者ID:cutso,项目名称:passlib,代码行数:7,代码来源:compat.py

示例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
开发者ID:SeanFarrow,项目名称:intellij-community,代码行数:7,代码来源:pydev_import_hook.py

示例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)
开发者ID:merchise-autrement,项目名称:xoeuf,代码行数:5,代码来源:proxy.py

示例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__))
开发者ID:xanalogica,项目名称:talk-Magic-of-Metaprogramming,代码行数:7,代码来源:module_ro.py

示例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])
开发者ID:RaphaelWimmer,项目名称:plumbum,代码行数:6,代码来源:local_machine.py

示例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 = {}
开发者ID:andrewgu12,项目名称:config,代码行数:6,代码来源:pydev_import_hook.py

示例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)
开发者ID:pombreda,项目名称:nimp,代码行数:5,代码来源:__lazy__.py


注:本文中的types.ModuleType.__init__方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。