summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-08-09 14:36:05 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-08-09 14:36:05 +0200
commit5c09c59bc76510a5388623259b3827ee894cd66b (patch)
treea9252f998a44c6a78252168332d1a12cd3d9b499
parent96a6912ec5183e2b338bf2e1b655ea10760bfb54 (diff)
[py3] Renamed `next` to `__next__` in iterators.
See PEP 3114. `next` is retained as an alias for Python 2.
-rw-r--r--django/core/serializers/base.py4
-rw-r--r--django/core/serializers/xml_serializer.py4
-rw-r--r--django/db/backends/oracle/base.py4
-rw-r--r--django/http/__init__.py4
-rw-r--r--django/http/multipartparser.py16
5 files changed, 24 insertions, 8 deletions
diff --git a/django/core/serializers/base.py b/django/core/serializers/base.py
index 78a01c7098..bdb43db9f3 100644
--- a/django/core/serializers/base.py
+++ b/django/core/serializers/base.py
@@ -136,10 +136,12 @@ class Deserializer(object):
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.
diff --git a/django/core/serializers/xml_serializer.py b/django/core/serializers/xml_serializer.py
index c4e4dd189e..666587dc77 100644
--- a/django/core/serializers/xml_serializer.py
+++ b/django/core/serializers/xml_serializer.py
@@ -154,13 +154,15 @@ class Deserializer(base.Deserializer):
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.
diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py
index 0f16130477..89cad12b6c 100644
--- a/django/db/backends/oracle/base.py
+++ b/django/db/backends/oracle/base.py
@@ -774,9 +774,11 @@ class CursorIterator(object):
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
diff --git a/django/http/__init__.py b/django/http/__init__.py
index cc138917b9..05824ad1d9 100644
--- a/django/http/__init__.py
+++ b/django/http/__init__.py
@@ -669,12 +669,14 @@ class HttpResponse(object):
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()
diff --git a/django/http/multipartparser.py b/django/http/multipartparser.py
index 1987ee53bc..9c66827cbb 100644
--- a/django/http/multipartparser.py
+++ b/django/http/multipartparser.py
@@ -305,7 +305,7 @@ class LazyStream(object):
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 @@ class LazyStream(object):
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 @@ class ChunkIter(object):
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 @@ class ChunkIter(object):
else:
raise StopIteration()
+ next = __next__ # Python 2 compatibility
+
def __iter__(self):
return self
@@ -400,12 +404,14 @@ class InterBoundaryIter(object):
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 @@ class BoundaryIter(object):
def __iter__(self):
return self
- def next(self):
+ def __next__(self):
if self._done:
raise StopIteration()
@@ -482,6 +488,8 @@ class BoundaryIter(object):
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.