mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +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:
		| @@ -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. | ||||
|   | ||||
| @@ -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. | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
| @@ -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() | ||||
|   | ||||
| @@ -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. | ||||
|   | ||||
		Reference in New Issue
	
	Block a user