Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[py3] Renamed `next` to `__next__` in iterators.

See PEP 3114. `next` is retained as an alias for Python 2.
  • Loading branch information...
commit 5c09c59bc76510a5388623259b3827ee894cd66b 1 parent 96a6912
@aaugustin aaugustin authored
View
4 django/core/serializers/base.py
@@ -136,10 +136,12 @@ def __init__(self, stream_or_string, **options):
def __iter__(self):
return self
- def next(self):
+ def __next__(self):
"""Iteration iterface -- return the next item in the stream"""
raise NotImplementedError
+ next = __next__ # Python 2 compatibility
+
class DeserializedObject(object):
"""
A deserialized model.
View
4 django/core/serializers/xml_serializer.py
@@ -154,13 +154,15 @@ def __init__(self, stream_or_string, **options):
self.event_stream = pulldom.parse(self.stream)
self.db = options.pop('using', DEFAULT_DB_ALIAS)
- def next(self):
+ def __next__(self):
for event, node in self.event_stream:
if event == "START_ELEMENT" and node.nodeName == "object":
self.event_stream.expandNode(node)
return self._handle_object(node)
raise StopIteration
+ next = __next__ # Python 2 compatibility
+
def _handle_object(self, node):
"""
Convert an <object> node to a DeserializedObject.
View
4 django/db/backends/oracle/base.py
@@ -774,9 +774,11 @@ def __init__(self, cursor):
def __iter__(self):
return self
- def next(self):
+ def __next__(self):
return _rowfactory(next(self.iter), self.cursor)
+ next = __next__ # Python 2 compatibility
+
def _rowfactory(row, cursor):
# Cast numeric values as the appropriate Python type based upon the
View
4 django/http/__init__.py
@@ -669,12 +669,14 @@ def __iter__(self):
self._iterator = iter(self._container)
return self
- def next(self):
+ def __next__(self):
chunk = next(self._iterator)
if isinstance(chunk, six.text_type):
chunk = chunk.encode(self._charset)
return str(chunk)
+ next = __next__ # Python 2 compatibility
+
def close(self):
if hasattr(self._container, 'close'):
self._container.close()
View
16 django/http/multipartparser.py
@@ -305,7 +305,7 @@ def parts():
out = b''.join(parts())
return out
- def next(self):
+ def __next__(self):
"""
Used when the exact number of bytes to read is unimportant.
@@ -322,6 +322,8 @@ def next(self):
self.position += len(output)
return output
+ next = __next__ # Python 2 compatibility
+
def close(self):
"""
Used to invalidate/disable this lazy stream.
@@ -376,7 +378,7 @@ def __init__(self, flo, chunk_size=64 * 1024):
self.flo = flo
self.chunk_size = chunk_size
- def next(self):
+ def __next__(self):
try:
data = self.flo.read(self.chunk_size)
except InputStreamExhausted:
@@ -386,6 +388,8 @@ def next(self):
else:
raise StopIteration()
+ next = __next__ # Python 2 compatibility
+
def __iter__(self):
return self
@@ -400,12 +404,14 @@ def __init__(self, stream, boundary):
def __iter__(self):
return self
- def next(self):
+ def __next__(self):
try:
return LazyStream(BoundaryIter(self._stream, self._boundary))
except InputStreamExhausted:
raise StopIteration()
+ next = __next__ # Python 2 compatibility
+
class BoundaryIter(object):
"""
A Producer that is sensitive to boundaries.
@@ -441,7 +447,7 @@ def __init__(self, stream, boundary):
def __iter__(self):
return self
- def next(self):
+ def __next__(self):
if self._done:
raise StopIteration()
@@ -482,6 +488,8 @@ def next(self):
stream.unget(chunk[-rollback:])
return chunk[:-rollback]
+ next = __next__ # Python 2 compatibility
+
def _find_boundary(self, data, eof = False):
"""
Finds a multipart boundary in data.
Please sign in to comment.
Something went wrong with that request. Please try again.