1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

[py3] Renamed next to __next__ in iterators.

See PEP 3114. `next` is retained as an alias for Python 2.
This commit is contained in:
Aymeric Augustin
2012-08-09 14:36:05 +02:00
parent 96a6912ec5
commit 5c09c59bc7
5 changed files with 24 additions and 8 deletions

View File

@@ -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.

View File

@@ -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.