mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
Fixed #18963 -- Used a subclass-friendly pattern
for Python 2 object model compatibility methods.
This commit is contained in:
@@ -28,7 +28,9 @@ class File(FileProxyMixin):
|
||||
|
||||
def __bool__(self):
|
||||
return bool(self.name)
|
||||
__nonzero__ = __bool__ # Python 2
|
||||
|
||||
def __nonzero__(self): # Python 2 compatibility
|
||||
return type(self).__bool__(self)
|
||||
|
||||
def __len__(self):
|
||||
return self.size
|
||||
@@ -142,7 +144,9 @@ class ContentFile(File):
|
||||
|
||||
def __bool__(self):
|
||||
return True
|
||||
__nonzero__ = __bool__ # Python 2
|
||||
|
||||
def __nonzero__(self): # Python 2 compatibility
|
||||
return type(self).__bool__(self)
|
||||
|
||||
def open(self, mode=None):
|
||||
self.seek(0)
|
||||
|
||||
@@ -112,7 +112,7 @@ class Serializer(object):
|
||||
if callable(getattr(self.stream, 'getvalue', None)):
|
||||
return self.stream.getvalue()
|
||||
|
||||
class Deserializer(object):
|
||||
class Deserializer(six.Iterator):
|
||||
"""
|
||||
Abstract base deserializer class.
|
||||
"""
|
||||
@@ -138,8 +138,6 @@ class Deserializer(object):
|
||||
"""Iteration iterface -- return the next item in the stream"""
|
||||
raise NotImplementedError
|
||||
|
||||
next = __next__ # Python 2 compatibility
|
||||
|
||||
class DeserializedObject(object):
|
||||
"""
|
||||
A deserialized model.
|
||||
|
||||
@@ -161,8 +161,6 @@ class Deserializer(base.Deserializer):
|
||||
return self._handle_object(node)
|
||||
raise StopIteration
|
||||
|
||||
next = __next__ # Python 2 compatibility
|
||||
|
||||
def _handle_object(self, node):
|
||||
"""
|
||||
Convert an <object> node to a DeserializedObject.
|
||||
|
||||
Reference in New Issue
Block a user