[py3] Renamed `next` to `__next__` in iterators.
See PEP 3114. `next` is retained as an alias for Python 2.
This commit is contained in:
parent
96a6912ec5
commit
5c09c59bc7
|
@ -136,10 +136,12 @@ class Deserializer(object):
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def next(self):
|
def __next__(self):
|
||||||
"""Iteration iterface -- return the next item in the stream"""
|
"""Iteration iterface -- return the next item in the stream"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
next = __next__ # Python 2 compatibility
|
||||||
|
|
||||||
class DeserializedObject(object):
|
class DeserializedObject(object):
|
||||||
"""
|
"""
|
||||||
A deserialized model.
|
A deserialized model.
|
||||||
|
|
|
@ -154,13 +154,15 @@ class Deserializer(base.Deserializer):
|
||||||
self.event_stream = pulldom.parse(self.stream)
|
self.event_stream = pulldom.parse(self.stream)
|
||||||
self.db = options.pop('using', DEFAULT_DB_ALIAS)
|
self.db = options.pop('using', DEFAULT_DB_ALIAS)
|
||||||
|
|
||||||
def next(self):
|
def __next__(self):
|
||||||
for event, node in self.event_stream:
|
for event, node in self.event_stream:
|
||||||
if event == "START_ELEMENT" and node.nodeName == "object":
|
if event == "START_ELEMENT" and node.nodeName == "object":
|
||||||
self.event_stream.expandNode(node)
|
self.event_stream.expandNode(node)
|
||||||
return self._handle_object(node)
|
return self._handle_object(node)
|
||||||
raise StopIteration
|
raise StopIteration
|
||||||
|
|
||||||
|
next = __next__ # Python 2 compatibility
|
||||||
|
|
||||||
def _handle_object(self, node):
|
def _handle_object(self, node):
|
||||||
"""
|
"""
|
||||||
Convert an <object> node to a DeserializedObject.
|
Convert an <object> node to a DeserializedObject.
|
||||||
|
|
|
@ -774,9 +774,11 @@ class CursorIterator(object):
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def next(self):
|
def __next__(self):
|
||||||
return _rowfactory(next(self.iter), self.cursor)
|
return _rowfactory(next(self.iter), self.cursor)
|
||||||
|
|
||||||
|
next = __next__ # Python 2 compatibility
|
||||||
|
|
||||||
|
|
||||||
def _rowfactory(row, cursor):
|
def _rowfactory(row, cursor):
|
||||||
# Cast numeric values as the appropriate Python type based upon the
|
# Cast numeric values as the appropriate Python type based upon the
|
||||||
|
|
|
@ -669,12 +669,14 @@ class HttpResponse(object):
|
||||||
self._iterator = iter(self._container)
|
self._iterator = iter(self._container)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def next(self):
|
def __next__(self):
|
||||||
chunk = next(self._iterator)
|
chunk = next(self._iterator)
|
||||||
if isinstance(chunk, six.text_type):
|
if isinstance(chunk, six.text_type):
|
||||||
chunk = chunk.encode(self._charset)
|
chunk = chunk.encode(self._charset)
|
||||||
return str(chunk)
|
return str(chunk)
|
||||||
|
|
||||||
|
next = __next__ # Python 2 compatibility
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
if hasattr(self._container, 'close'):
|
if hasattr(self._container, 'close'):
|
||||||
self._container.close()
|
self._container.close()
|
||||||
|
|
|
@ -305,7 +305,7 @@ class LazyStream(object):
|
||||||
out = b''.join(parts())
|
out = b''.join(parts())
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def next(self):
|
def __next__(self):
|
||||||
"""
|
"""
|
||||||
Used when the exact number of bytes to read is unimportant.
|
Used when the exact number of bytes to read is unimportant.
|
||||||
|
|
||||||
|
@ -322,6 +322,8 @@ class LazyStream(object):
|
||||||
self.position += len(output)
|
self.position += len(output)
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
next = __next__ # Python 2 compatibility
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
"""
|
"""
|
||||||
Used to invalidate/disable this lazy stream.
|
Used to invalidate/disable this lazy stream.
|
||||||
|
@ -376,7 +378,7 @@ class ChunkIter(object):
|
||||||
self.flo = flo
|
self.flo = flo
|
||||||
self.chunk_size = chunk_size
|
self.chunk_size = chunk_size
|
||||||
|
|
||||||
def next(self):
|
def __next__(self):
|
||||||
try:
|
try:
|
||||||
data = self.flo.read(self.chunk_size)
|
data = self.flo.read(self.chunk_size)
|
||||||
except InputStreamExhausted:
|
except InputStreamExhausted:
|
||||||
|
@ -386,6 +388,8 @@ class ChunkIter(object):
|
||||||
else:
|
else:
|
||||||
raise StopIteration()
|
raise StopIteration()
|
||||||
|
|
||||||
|
next = __next__ # Python 2 compatibility
|
||||||
|
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
@ -400,12 +404,14 @@ class InterBoundaryIter(object):
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def next(self):
|
def __next__(self):
|
||||||
try:
|
try:
|
||||||
return LazyStream(BoundaryIter(self._stream, self._boundary))
|
return LazyStream(BoundaryIter(self._stream, self._boundary))
|
||||||
except InputStreamExhausted:
|
except InputStreamExhausted:
|
||||||
raise StopIteration()
|
raise StopIteration()
|
||||||
|
|
||||||
|
next = __next__ # Python 2 compatibility
|
||||||
|
|
||||||
class BoundaryIter(object):
|
class BoundaryIter(object):
|
||||||
"""
|
"""
|
||||||
A Producer that is sensitive to boundaries.
|
A Producer that is sensitive to boundaries.
|
||||||
|
@ -441,7 +447,7 @@ class BoundaryIter(object):
|
||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def next(self):
|
def __next__(self):
|
||||||
if self._done:
|
if self._done:
|
||||||
raise StopIteration()
|
raise StopIteration()
|
||||||
|
|
||||||
|
@ -482,6 +488,8 @@ class BoundaryIter(object):
|
||||||
stream.unget(chunk[-rollback:])
|
stream.unget(chunk[-rollback:])
|
||||||
return chunk[:-rollback]
|
return chunk[:-rollback]
|
||||||
|
|
||||||
|
next = __next__ # Python 2 compatibility
|
||||||
|
|
||||||
def _find_boundary(self, data, eof = False):
|
def _find_boundary(self, data, eof = False):
|
||||||
"""
|
"""
|
||||||
Finds a multipart boundary in data.
|
Finds a multipart boundary in data.
|
||||||
|
|
Loading…
Reference in New Issue