Pylons/webob — Issue #10: Python 3 error in file-example 
Author: garyvdm
Created: 2011-11-15 12:10:04+00:00
State: open

I was following this example with python 3:

http://docs.webob.org/en/latest/file-example.html

And I got this error:

Traceback (most recent call last):
File "/usr/lib/python3.2/wsgiref/handlers.py", line 138, in run
self.finish_response()
File "/usr/lib/python3.2/wsgiref/handlers.py", line 178, in finish_response
for data in self.result:
TypeError: iter() returned non-iterator of type 'FileIterator'

I found that the iter interface for python 3 has changed. An iterator needs a __next__ method in python 3, where in python 2, it needs a next method.

Can we change the example to include:

def next(self):
chunk = self.fileobj.read(self.chunk_size)
if not chunk:
raise StopIteration
return chunk

+ __next__ = next

so that it works in both python 2 and 3.