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


Python ModuleType.__getattribute__方法代码示例

本文整理汇总了Python中types.ModuleType.__getattribute__方法的典型用法代码示例。如果您正苦于以下问题:Python ModuleType.__getattribute__方法的具体用法?Python ModuleType.__getattribute__怎么用?Python ModuleType.__getattribute__使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在types.ModuleType的用法示例。


在下文中一共展示了ModuleType.__getattribute__方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: proxysuper

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __getattribute__ [as 别名]
def proxysuper():
    if verbose:
        print "Testing super() for a proxy object..."
    class Proxy(object):
        def __init__(self, obj):
            self.__obj = obj
        def __getattribute__(self, name):
            if name.startswith("_Proxy__"):
                return object.__getattribute__(self, name)
            else:
                return getattr(self.__obj, name)

    class B(object):
        def f(self):
            return "B.f"

    class C(B):
        def f(self):
            return super(C, self).f() + "->C.f"

    obj = C()
    p = Proxy(obj)
    vereq(C.__dict__["f"](p), "B.f->C.f") 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:25,代码来源:test_descr.py

示例2: _reset_lazymodule

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __getattribute__ [as 别名]
def _reset_lazymodule(module, cls_attrs):
    """Resets a module's lazy state from cached data.

    """
    modclass = type(module)
    del modclass.__getattribute__
    del modclass.__setattr__
    try:
        del modclass._LOADING
    except AttributeError:
        pass
    for cls_attr in _CLS_ATTRS:
        try:
            setattr(modclass, cls_attr, cls_attrs[cls_attr])
        except KeyError:
            pass
    _reset_lazy_submod_refs(module) 
开发者ID:mnmelo,项目名称:lazy_import,代码行数:19,代码来源:__init__.py

示例3: __getattr__

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __getattribute__ [as 别名]
def __getattr__(self, name):
        if name in object_origins:
            module = __import__(object_origins[name], None, None, [name])
            for extra_name in all_by_module[module.__name__]:
                setattr(self, extra_name, getattr(module, extra_name))
            return getattr(module, name)
        elif name in attribute_modules:
            __import__("werkzeug." + name)
        return ModuleType.__getattribute__(self, name) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:11,代码来源:__init__.py

示例4: __getattr__

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __getattribute__ [as 别名]
def __getattr__(self, name):
        if name in object_origins:
            module = __import__(object_origins[name], None, None, [name])
            for extra_name in all_by_module[module.__name__]:
                setattr(self, extra_name, getattr(module, extra_name))
            return getattr(module, name)
        elif name in attribute_modules:
            __import__('werkzeug.' + name)
        return ModuleType.__getattribute__(self, name) 
开发者ID:jpush,项目名称:jbox,代码行数:11,代码来源:__init__.py

示例5: __getattr__

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __getattribute__ [as 别名]
def __getattr__(self, name):
        if name in _shorcuts.keys():
            submodule = __import__(
                "tempy." + _shorcuts[name], globals(), locals(), [name]
            )
            return getattr(submodule, name)
        r = ModuleType.__getattribute__(self, name)
        return r 
开发者ID:Hrabal,项目名称:TemPy,代码行数:10,代码来源:__init__.py

示例6: pymods

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __getattribute__ [as 别名]
def pymods():
    if verbose: print "Testing Python subclass of module..."
    log = []
    from types import ModuleType as MT
    class MM(MT):
        def __init__(self, name):
            MT.__init__(self, name)
        def __getattribute__(self, name):
            log.append(("getattr", name))
            return MT.__getattribute__(self, name)
        def __setattr__(self, name, value):
            log.append(("setattr", name, value))
            MT.__setattr__(self, name, value)
        def __delattr__(self, name):
            log.append(("delattr", name))
            MT.__delattr__(self, name)
    a = MM("a")
    a.foo = 12
    x = a.foo
    del a.foo
    vereq(log, [("setattr", "foo", 12),
                ("getattr", "foo"),
                ("delattr", "foo")])

    # http://python.org/sf/1174712
    try:
        class Module(types.ModuleType, str):
            pass
    except TypeError:
        pass
    else:
        raise TestFailed("inheriting from ModuleType and str at the "
                          "same time should fail") 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:35,代码来源:test_descr.py

示例7: isinst_isclass

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __getattribute__ [as 别名]
def isinst_isclass():
    if verbose:
        print "Testing proxy isinstance() and isclass()..."
    class Proxy(object):
        def __init__(self, obj):
            self.__obj = obj
        def __getattribute__(self, name):
            if name.startswith("_Proxy__"):
                return object.__getattribute__(self, name)
            else:
                return getattr(self.__obj, name)
    # Test with a classic class
    class C:
        pass
    a = C()
    pa = Proxy(a)
    verify(isinstance(a, C))  # Baseline
    verify(isinstance(pa, C)) # Test
    # Test with a classic subclass
    class D(C):
        pass
    a = D()
    pa = Proxy(a)
    verify(isinstance(a, C))  # Baseline
    verify(isinstance(pa, C)) # Test
    # Test with a new-style class
    class C(object):
        pass
    a = C()
    pa = Proxy(a)
    verify(isinstance(a, C))  # Baseline
    verify(isinstance(pa, C)) # Test
    # Test with a new-style subclass
    class D(C):
        pass
    a = D()
    pa = Proxy(a)
    verify(isinstance(a, C))  # Baseline
    verify(isinstance(pa, C)) # Test 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:41,代码来源:test_descr.py

示例8: __setattr__

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __getattribute__ [as 别名]
def __setattr__(self, attr, value):
        logger.debug("Setting attr {} to value {}, in LazyModule instance "
                     "of {}".format(attr, value, super(LazyModule, self)
                                    .__getattribute__("__name__")))
        _load_module(self)
        return super(LazyModule, self).__setattr__(attr, value) 
开发者ID:mnmelo,项目名称:lazy_import,代码行数:8,代码来源:__init__.py

示例9: _clean_lazymodule

# 需要导入模块: from types import ModuleType [as 别名]
# 或者: from types.ModuleType import __getattribute__ [as 别名]
def _clean_lazymodule(module):
    """Removes all lazy behavior from a module's class, for loading.

    Also removes all module attributes listed under the module's class deletion
    dictionaries. Deletion dictionaries are class attributes with names
    specified in `_DELETION_DICT`.

    Parameters
    ----------
    module: LazyModule 

    Returns
    -------
    dict
        A dictionary of deleted class attributes, that can be used to reset the
        lazy state using :func:`_reset_lazymodule`.
    """
    modclass = type(module)
    _clean_lazy_submod_refs(module)

    modclass.__getattribute__ = ModuleType.__getattribute__
    modclass.__setattr__ = ModuleType.__setattr__
    cls_attrs = {}
    for cls_attr in _CLS_ATTRS:
        try:
            cls_attrs[cls_attr] = getattr(modclass, cls_attr)
            delattr(modclass, cls_attr)
        except AttributeError:
            pass
    return cls_attrs 
开发者ID:mnmelo,项目名称:lazy_import,代码行数:32,代码来源:__init__.py


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