Below is the file 'genproxy.py' from this revision. You can also download the file.

#!/usr/bin/env python

# Copyright (C) 2005 Grahame Bowland <grahame@angrygoats.net>
#
# This program is made available under the GNU GPL version 2.0 or
# greater. See the accompanying file COPYING for details.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
# PURPOSE.

class GeneratorProxy(object):
    def __init__(self, generator):
        self.generator = generator
    def __iter__(self):
        return self
    def next(self):
        return self.generator.next()

class Seedy(GeneratorProxy):
    def __del__(self):
        print "testing"

def test():
    yield 2
    yield 3
    yield 4

if __name__ == '__main__':
    a = test()
    b = Seedy(test())
    for i in b:
        print i


###
### vi:expandtab:sw=4:ts=4
###