1
0
mirror of https://github.com/django/django.git synced 2025-10-26 23:26:08 +00:00

Fixed #18963 -- Used a subclass-friendly pattern

for Python 2 object model compatibility methods.
This commit is contained in:
Aymeric Augustin
2012-11-03 21:43:11 +01:00
parent 973f539ab8
commit fc10418fba
14 changed files with 61 additions and 50 deletions

View File

@@ -256,7 +256,7 @@ class MultiPartParser(object):
"""Cleanup filename from Internet Explorer full paths."""
return filename and filename[filename.rfind("\\")+1:].strip()
class LazyStream(object):
class LazyStream(six.Iterator):
"""
The LazyStream wrapper allows one to get and "unget" bytes from a stream.
@@ -323,8 +323,6 @@ class LazyStream(object):
self.position += len(output)
return output
next = __next__ # Python 2 compatibility
def close(self):
"""
Used to invalidate/disable this lazy stream.
@@ -369,7 +367,7 @@ class LazyStream(object):
" if there is none, report this to the Django developers."
)
class ChunkIter(object):
class ChunkIter(six.Iterator):
"""
An iterable that will yield chunks of data. Given a file-like object as the
constructor, this object will yield chunks of read operations from that
@@ -389,12 +387,10 @@ class ChunkIter(object):
else:
raise StopIteration()
next = __next__ # Python 2 compatibility
def __iter__(self):
return self
class InterBoundaryIter(object):
class InterBoundaryIter(six.Iterator):
"""
A Producer that will iterate over boundaries.
"""
@@ -411,9 +407,7 @@ class InterBoundaryIter(object):
except InputStreamExhausted:
raise StopIteration()
next = __next__ # Python 2 compatibility
class BoundaryIter(object):
class BoundaryIter(six.Iterator):
"""
A Producer that is sensitive to boundaries.
@@ -489,8 +483,6 @@ 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.

View File

@@ -23,7 +23,7 @@ class BadHeaderError(ValueError):
pass
class HttpResponseBase(object):
class HttpResponseBase(six.Iterator):
"""
An HTTP response base class with dictionary-accessed headers.
@@ -218,8 +218,6 @@ class HttpResponseBase(object):
# Subclasses must define self._iterator for this function.
return self.make_bytes(next(self._iterator))
next = __next__ # Python 2 compatibility
# These methods partially implement the file-like object interface.
# See http://docs.python.org/lib/bltin-file-objects.html