New submission from Graham Dumpleton <>:


Tres said:

Thanks for the report!  I agree that your suggested solution is probably
the correct one, with the exception that I would have it apply 'list()'
only for results which were generators:  hmm, how do I detect that?

Bad call unfortunately as you miss out on a whole class of iterables which 
aren't generators.

For example, will not work with custom iterable:

class _WSGIApplicationIterable(object):

    def __init__(self, transaction, generator):
        self.transaction = transaction
        self.generator = generator

    def __iter__(self):
        for item in self.generator:
            yield item

    def close(self):
            if hasattr(self.generator, 'close'):
            self.transaction.__exit__(None, None, None)

You would need to check for __iter__() for this one. Even this isn't enough 
though as you can also have:

class FileWrapper:

    def __init__(self, filelike, blksize=8192):
        self.filelike = filelike
        self.blksize = blksize
        if hasattr(filelike, 'close'):
            self.close = filelike.close

    def __getitem__(self, key):
        data =
        if data:
            return data
        raise IndexError

Ie., __getitem__() also provides iterable abilities.

If you are concerned about the list([]) case, ie., of doing shallow copy of 
list, then change:

                'app_iter =, start_response); '
                'app_iter = (type(app_iter) is GeneratorType) '
                                 'and list(app_iter) or app_iter',
                globals(), _locals)


                'app_iter =, start_response); '
                'app_iter = (type(app_iter) is not ListType) '
                                 'and list(app_iter) or app_iter',
                globals(), _locals)

Ie., if not a ListType assume is an iterable and convert to list().

messages: 495
nosy: grahamd
priority: bug
status: unread
title: respoze.profile doesn't handle WSGI iterables properly.

Repoze Bugs <>
Repoze-dev mailing list

Reply via email to