Python __future__ 模块,generators() 实例源码

我们从Python开源项目中,提取了以下14个代码示例,用于说明如何使用__future__.generators()

项目:code    作者:ActiveState    | 项目源码 | 文件源码
def enableAttributes(genfunc):
    """Wrapper for generators to enable classlike attribute access.

    The generator definition should specify 'self' as the first parameter.
    Calls to a wrapped generator should ignore the self parameter.
    """
    old = getargspec(genfunc)
    old[0].pop(0)
    new = getargspec(genfunc)
    new[0][0] = 'wrapped'
    specs = {'name': genfunc.func_name,
         'oldargs': formatargspec(*old),
         'newargs': formatargspec(*new)}
    exec(_redefinition % specs, genfunc.func_globals)


#### A minimal, complete example
项目:hakkuframework    作者:4shadoww    | 项目源码 | 文件源码
def transform(self, node, results):
        remove_future_import(u"with_statement", node)
        remove_future_import(u"nested_scopes", node)
        remove_future_import(u"generators", node)
项目:packaging    作者:blockstack    | 项目源码 | 文件源码
def transform(self, node, results):
        remove_future_import(u"with_statement", node)
        remove_future_import(u"nested_scopes", node)
        remove_future_import(u"generators", node)
项目:islam-buddy    作者:hamir    | 项目源码 | 文件源码
def transform(self, node, results):
        remove_future_import(u"with_statement", node)
        remove_future_import(u"nested_scopes", node)
        remove_future_import(u"generators", node)
项目:FightstickDisplay    作者:calexil    | 项目源码 | 文件源码
def transform(self, node, results):
        remove_future_import(u"with_statement", node)
        remove_future_import(u"nested_scopes", node)
        remove_future_import(u"generators", node)
项目:cryptogram    作者:xinmingzhang    | 项目源码 | 文件源码
def transform(self, node, results):
        remove_future_import(u"with_statement", node)
        remove_future_import(u"nested_scopes", node)
        remove_future_import(u"generators", node)
项目:Repobot    作者:Desgard    | 项目源码 | 文件源码
def transform(self, node, results):
        remove_future_import(u"with_statement", node)
        remove_future_import(u"nested_scopes", node)
        remove_future_import(u"generators", node)
项目:rdiff-backup    作者:sol1    | 项目源码 | 文件源码
def testGenerators(self):
        """equals works for generators"""
        def f():
            yield 1
            yield "hello"
        def g():
            yield 1
            yield "hello"
        assert Iter.equal(f(), g())
项目:UMOG    作者:hsab    | 项目源码 | 文件源码
def transform(self, node, results):
        remove_future_import(u"with_statement", node)
        remove_future_import(u"nested_scopes", node)
        remove_future_import(u"generators", node)
项目:blackmamba    作者:zrzka    | 项目源码 | 文件源码
def transform(self, node, results):
        remove_future_import(u"with_statement", node)
        remove_future_import(u"nested_scopes", node)
        remove_future_import(u"generators", node)
项目:beepboop    作者:nicolehe    | 项目源码 | 文件源码
def transform(self, node, results):
        remove_future_import(u"with_statement", node)
        remove_future_import(u"nested_scopes", node)
        remove_future_import(u"generators", node)
项目:python-design-patterns    作者:prateeksan    | 项目源码 | 文件源码
def generate_children(count, parent, life_min, life_max):
    """We are using a generator to randomly seed a sequence of specifications for the
    factory. While this is not strictly part of the Factory Pattern, it can be useful
    for testing the factory or for generating objects based on some pre-defined algorithm.
    It is perfectly acceptable to implement factories without generators (depends on your
    specific use-case)."""

    types = parent.__subclasses__()
    for i in range(count):
        yield { 
            "class_name": random.choice(types).__name__, 
            "lifespan": random.randint(life_min, life_max)
        }
项目:hackathon    作者:vertica    | 项目源码 | 文件源码
def transform(self, node, results):
        remove_future_import(u"with_statement", node)
        remove_future_import(u"nested_scopes", node)
        remove_future_import(u"generators", node)
项目:yatta_reader    作者:sound88    | 项目源码 | 文件源码
def transform(self, node, results):
        remove_future_import(u"with_statement", node)
        remove_future_import(u"nested_scopes", node)
        remove_future_import(u"generators", node)