[py3] Applied minor fixes so the test suite starts

This commit is contained in:
Aymeric Augustin 2012-07-21 10:01:46 +02:00
parent c5ef65bcf3
commit a8b3ddec5f
4 changed files with 30 additions and 27 deletions

View File

@ -6,7 +6,6 @@ be executed through ``django-admin.py`` or ``manage.py``).
import os
import sys
from io import BytesIO
from optparse import make_option, OptionParser
import traceback
@ -14,6 +13,7 @@ import django
from django.core.exceptions import ImproperlyConfigured
from django.core.management.color import color_style
from django.utils.encoding import smart_str
from django.utils.six import StringIO
class CommandError(Exception):
@ -273,7 +273,7 @@ class BaseCommand(object):
"""
from django.core.management.validation import get_validation_errors
s = BytesIO()
s = StringIO()
num_errors = get_validation_errors(s, app)
if num_errors:
s.seek(0)

View File

@ -28,6 +28,30 @@ from django.utils import six
from django.utils.text import get_text_list, capfirst
def subclass_exception(name, parents, module, attached_to=None):
"""
Create exception subclass. Used by ModelBase below.
If 'attached_to' is supplied, the exception will be created in a way that
allows it to be pickled, assuming the returned exception class will be added
as an attribute to the 'attached_to' class.
"""
class_dict = {'__module__': module}
if attached_to is not None:
def __reduce__(self):
# Exceptions are special - they've got state that isn't
# in self.__dict__. We assume it is all in self.args.
return (unpickle_inner_exception, (attached_to, name), self.args)
def __setstate__(self, args):
self.args = args
class_dict['__reduce__'] = __reduce__
class_dict['__setstate__'] = __setstate__
return type(name, parents, class_dict)
class ModelBase(type):
"""
Metaclass for all models.
@ -929,29 +953,6 @@ def model_unpickle(model, attrs):
return cls.__new__(cls)
model_unpickle.__safe_for_unpickle__ = True
def subclass_exception(name, parents, module, attached_to=None):
"""
Create exception subclass.
If 'attached_to' is supplied, the exception will be created in a way that
allows it to be pickled, assuming the returned exception class will be added
as an attribute to the 'attached_to' class.
"""
class_dict = {'__module__': module}
if attached_to is not None:
def __reduce__(self):
# Exceptions are special - they've got state that isn't
# in self.__dict__. We assume it is all in self.args.
return (unpickle_inner_exception, (attached_to, name), self.args)
def __setstate__(self, args):
self.args = args
class_dict['__reduce__'] = __reduce__
class_dict['__setstate__'] = __setstate__
return type(name, parents, class_dict)
def unpickle_inner_exception(klass, exception_name):
# Get the exception class from the class it is attached to:
exception = getattr(klass, exception_name)

View File

@ -135,6 +135,8 @@ class Field(object):
return self.creation_counter < other.creation_counter
return NotImplemented
__hash__ = object.__hash__
def __deepcopy__(self, memodict):
# We don't have to deepcopy very much here, since most things are not
# intended to be altered after initial creation.

View File

@ -196,7 +196,7 @@ class RequestFactory(object):
'SERVER_PROTOCOL': 'HTTP/1.1',
'wsgi.version': (1, 0),
'wsgi.url_scheme': 'http',
'wsgi.input': FakePayload(''),
'wsgi.input': FakePayload(b''),
'wsgi.errors': self.errors,
'wsgi.multiprocess': True,
'wsgi.multithread': False,