Fixed #2109 -- Convert old-style classes to new-style classes throughout Django. Thanks, Nicola Larosa
git-svn-id: http://code.djangoproject.com/svn/django/trunk@3113 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
5edd1335b2
commit
2abfd5dd58
|
@ -12,7 +12,7 @@ from django.conf import global_settings
|
||||||
|
|
||||||
ENVIRONMENT_VARIABLE = "DJANGO_SETTINGS_MODULE"
|
ENVIRONMENT_VARIABLE = "DJANGO_SETTINGS_MODULE"
|
||||||
|
|
||||||
class LazySettings:
|
class LazySettings(object):
|
||||||
"""
|
"""
|
||||||
A lazy proxy for either global Django settings or a custom settings object.
|
A lazy proxy for either global Django settings or a custom settings object.
|
||||||
The user can manually configure settings prior to using them. Otherwise,
|
The user can manually configure settings prior to using them. Otherwise,
|
||||||
|
@ -67,7 +67,7 @@ class LazySettings:
|
||||||
setattr(holder, name, value)
|
setattr(holder, name, value)
|
||||||
self._target = holder
|
self._target = holder
|
||||||
|
|
||||||
class Settings:
|
class Settings(object):
|
||||||
def __init__(self, settings_module):
|
def __init__(self, settings_module):
|
||||||
# update this dict from global settings (but only for ALL_CAPS settings)
|
# update this dict from global settings (but only for ALL_CAPS settings)
|
||||||
for setting in dir(global_settings):
|
for setting in dir(global_settings):
|
||||||
|
@ -112,7 +112,7 @@ class Settings:
|
||||||
def get_all_members(self):
|
def get_all_members(self):
|
||||||
return dir(self)
|
return dir(self)
|
||||||
|
|
||||||
class UserSettingsHolder:
|
class UserSettingsHolder(object):
|
||||||
"""
|
"""
|
||||||
Holder for user configured settings.
|
Holder for user configured settings.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -12,7 +12,7 @@ class LazyUser(object):
|
||||||
self._user = AnonymousUser()
|
self._user = AnonymousUser()
|
||||||
return self._user
|
return self._user
|
||||||
|
|
||||||
class AuthenticationMiddleware:
|
class AuthenticationMiddleware(object):
|
||||||
def process_request(self, request):
|
def process_request(self, request):
|
||||||
assert hasattr(request, 'session'), "The Django authentication middleware requires session middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'django.contrib.sessions.middleware.SessionMiddleware'."
|
assert hasattr(request, 'session'), "The Django authentication middleware requires session middleware to be installed. Edit your MIDDLEWARE_CLASSES setting to insert 'django.contrib.sessions.middleware.SessionMiddleware'."
|
||||||
request.__class__.user = LazyUser()
|
request.__class__.user = LazyUser()
|
||||||
|
|
|
@ -2,7 +2,7 @@ from django.contrib.flatpages.views import flatpage
|
||||||
from django.http import Http404
|
from django.http import Http404
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
class FlatpageFallbackMiddleware:
|
class FlatpageFallbackMiddleware(object):
|
||||||
def process_response(self, request, response):
|
def process_response(self, request, response):
|
||||||
if response.status_code != 404:
|
if response.status_code != 404:
|
||||||
return response # No need to check for a flatpage for non-404 responses.
|
return response # No need to check for a flatpage for non-404 responses.
|
||||||
|
|
|
@ -2,7 +2,7 @@ from django.contrib.redirects.models import Redirect
|
||||||
from django import http
|
from django import http
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
class RedirectFallbackMiddleware:
|
class RedirectFallbackMiddleware(object):
|
||||||
def process_response(self, request, response):
|
def process_response(self, request, response):
|
||||||
if response.status_code != 404:
|
if response.status_code != 404:
|
||||||
return response # No need to check for a redirect for non-404 responses.
|
return response # No need to check for a redirect for non-404 responses.
|
||||||
|
|
|
@ -64,7 +64,7 @@ class SessionWrapper(object):
|
||||||
|
|
||||||
_session = property(_get_session)
|
_session = property(_get_session)
|
||||||
|
|
||||||
class SessionMiddleware:
|
class SessionMiddleware(object):
|
||||||
def process_request(self, request):
|
def process_request(self, request):
|
||||||
request.session = SessionWrapper(request.COOKIES.get(settings.SESSION_COOKIE_NAME, None))
|
request.session = SessionWrapper(request.COOKIES.get(settings.SESSION_COOKIE_NAME, None))
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ def add_domain(domain, url):
|
||||||
class FeedDoesNotExist(ObjectDoesNotExist):
|
class FeedDoesNotExist(ObjectDoesNotExist):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class Feed:
|
class Feed(object):
|
||||||
item_pubdate = None
|
item_pubdate = None
|
||||||
item_enclosure_url = None
|
item_enclosure_url = None
|
||||||
feed_type = feedgenerator.DefaultFeed
|
feed_type = feedgenerator.DefaultFeed
|
||||||
|
|
|
@ -5,7 +5,7 @@ from django.core.exceptions import ImproperlyConfigured
|
||||||
class InvalidCacheBackendError(ImproperlyConfigured):
|
class InvalidCacheBackendError(ImproperlyConfigured):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class BaseCache:
|
class BaseCache(object):
|
||||||
def __init__(self, params):
|
def __init__(self, params):
|
||||||
timeout = params.get('timeout', 300)
|
timeout = params.get('timeout', 300)
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -48,7 +48,7 @@ def request(request):
|
||||||
# PermWrapper and PermLookupDict proxy the permissions system into objects that
|
# PermWrapper and PermLookupDict proxy the permissions system into objects that
|
||||||
# the template system can understand.
|
# the template system can understand.
|
||||||
|
|
||||||
class PermLookupDict:
|
class PermLookupDict(object):
|
||||||
def __init__(self, user, module_name):
|
def __init__(self, user, module_name):
|
||||||
self.user, self.module_name = user, module_name
|
self.user, self.module_name = user, module_name
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
@ -58,7 +58,7 @@ class PermLookupDict:
|
||||||
def __nonzero__(self):
|
def __nonzero__(self):
|
||||||
return self.user.has_module_perms(self.module_name)
|
return self.user.has_module_perms(self.module_name)
|
||||||
|
|
||||||
class PermWrapper:
|
class PermWrapper(object):
|
||||||
def __init__(self, user):
|
def __init__(self, user):
|
||||||
self.user = user
|
self.user = user
|
||||||
def __getitem__(self, module_name):
|
def __getitem__(self, module_name):
|
||||||
|
|
|
@ -3,7 +3,7 @@ from django.dispatch import dispatcher
|
||||||
from django import http
|
from django import http
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
class BaseHandler:
|
class BaseHandler(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._request_middleware = self._view_middleware = self._response_middleware = self._exception_middleware = None
|
self._request_middleware = self._view_middleware = self._response_middleware = self._exception_middleware = None
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@ from math import ceil
|
||||||
class InvalidPage(Exception):
|
class InvalidPage(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class ObjectPaginator:
|
class ObjectPaginator(object):
|
||||||
"""
|
"""
|
||||||
This class makes pagination easy. Feed it a QuerySet, plus the number of
|
This class makes pagination easy. Feed it a QuerySet, plus the number of
|
||||||
objects you want on each page. Then read the hits and pages properties to
|
objects you want on each page. Then read the hits and pages properties to
|
||||||
|
|
|
@ -21,7 +21,7 @@ software_version = server_version + ' ' + sys_version
|
||||||
class WSGIServerException(Exception):
|
class WSGIServerException(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class FileWrapper:
|
class FileWrapper(object):
|
||||||
"""Wrapper to convert file-like objects to iterables"""
|
"""Wrapper to convert file-like objects to iterables"""
|
||||||
|
|
||||||
def __init__(self, filelike, blksize=8192):
|
def __init__(self, filelike, blksize=8192):
|
||||||
|
@ -63,7 +63,7 @@ def _formatparam(param, value=None, quote=1):
|
||||||
else:
|
else:
|
||||||
return param
|
return param
|
||||||
|
|
||||||
class Headers:
|
class Headers(object):
|
||||||
"""Manage a collection of HTTP response headers"""
|
"""Manage a collection of HTTP response headers"""
|
||||||
def __init__(self,headers):
|
def __init__(self,headers):
|
||||||
if type(headers) is not ListType:
|
if type(headers) is not ListType:
|
||||||
|
@ -218,7 +218,7 @@ def is_hop_by_hop(header_name):
|
||||||
"""Return true if 'header_name' is an HTTP/1.1 "Hop-by-Hop" header"""
|
"""Return true if 'header_name' is an HTTP/1.1 "Hop-by-Hop" header"""
|
||||||
return _hoppish(header_name.lower())
|
return _hoppish(header_name.lower())
|
||||||
|
|
||||||
class ServerHandler:
|
class ServerHandler(object):
|
||||||
"""Manage the invocation of a WSGI application"""
|
"""Manage the invocation of a WSGI application"""
|
||||||
|
|
||||||
# Configuration parameters; can override per-subclass or per-instance
|
# Configuration parameters; can override per-subclass or per-instance
|
||||||
|
@ -591,7 +591,7 @@ class WSGIRequestHandler(BaseHTTPRequestHandler):
|
||||||
return
|
return
|
||||||
sys.stderr.write("[%s] %s\n" % (self.log_date_time_string(), format % args))
|
sys.stderr.write("[%s] %s\n" % (self.log_date_time_string(), format % args))
|
||||||
|
|
||||||
class AdminMediaHandler:
|
class AdminMediaHandler(object):
|
||||||
"""
|
"""
|
||||||
WSGI middleware that intercepts calls to the admin media directory, as
|
WSGI middleware that intercepts calls to the admin media directory, as
|
||||||
defined by the ADMIN_MEDIA_PREFIX setting, and serves those images.
|
defined by the ADMIN_MEDIA_PREFIX setting, and serves those images.
|
||||||
|
|
|
@ -83,7 +83,7 @@ class MatchChecker(object):
|
||||||
raise NoReverseMatch("Value %r didn't match regular expression %r" % (value, test_regex))
|
raise NoReverseMatch("Value %r didn't match regular expression %r" % (value, test_regex))
|
||||||
return str(value) # TODO: Unicode?
|
return str(value) # TODO: Unicode?
|
||||||
|
|
||||||
class RegexURLPattern:
|
class RegexURLPattern(object):
|
||||||
def __init__(self, regex, callback, default_args=None):
|
def __init__(self, regex, callback, default_args=None):
|
||||||
# regex is a string representing a regular expression.
|
# regex is a string representing a regular expression.
|
||||||
# callback is something like 'foo.views.news.stories.story_detail',
|
# callback is something like 'foo.views.news.stories.story_detail',
|
||||||
|
|
|
@ -237,7 +237,7 @@ def hasNoProfanities(field_data, all_data):
|
||||||
"Watch your mouth! The words %s are not allowed here.", plural) % \
|
"Watch your mouth! The words %s are not allowed here.", plural) % \
|
||||||
get_text_list(['"%s%s%s"' % (i[0], '-'*(len(i)-2), i[-1]) for i in words_seen], 'and')
|
get_text_list(['"%s%s%s"' % (i[0], '-'*(len(i)-2), i[-1]) for i in words_seen], 'and')
|
||||||
|
|
||||||
class AlwaysMatchesOtherField:
|
class AlwaysMatchesOtherField(object):
|
||||||
def __init__(self, other_field_name, error_message=None):
|
def __init__(self, other_field_name, error_message=None):
|
||||||
self.other = other_field_name
|
self.other = other_field_name
|
||||||
self.error_message = error_message or lazy_inter(gettext_lazy("This field must match the '%s' field."), self.other)
|
self.error_message = error_message or lazy_inter(gettext_lazy("This field must match the '%s' field."), self.other)
|
||||||
|
@ -247,7 +247,7 @@ class AlwaysMatchesOtherField:
|
||||||
if field_data != all_data[self.other]:
|
if field_data != all_data[self.other]:
|
||||||
raise ValidationError, self.error_message
|
raise ValidationError, self.error_message
|
||||||
|
|
||||||
class ValidateIfOtherFieldEquals:
|
class ValidateIfOtherFieldEquals(object):
|
||||||
def __init__(self, other_field, other_value, validator_list):
|
def __init__(self, other_field, other_value, validator_list):
|
||||||
self.other_field, self.other_value = other_field, other_value
|
self.other_field, self.other_value = other_field, other_value
|
||||||
self.validator_list = validator_list
|
self.validator_list = validator_list
|
||||||
|
@ -258,7 +258,7 @@ class ValidateIfOtherFieldEquals:
|
||||||
for v in self.validator_list:
|
for v in self.validator_list:
|
||||||
v(field_data, all_data)
|
v(field_data, all_data)
|
||||||
|
|
||||||
class RequiredIfOtherFieldNotGiven:
|
class RequiredIfOtherFieldNotGiven(object):
|
||||||
def __init__(self, other_field_name, error_message=gettext_lazy("Please enter something for at least one field.")):
|
def __init__(self, other_field_name, error_message=gettext_lazy("Please enter something for at least one field.")):
|
||||||
self.other, self.error_message = other_field_name, error_message
|
self.other, self.error_message = other_field_name, error_message
|
||||||
self.always_test = True
|
self.always_test = True
|
||||||
|
@ -267,7 +267,7 @@ class RequiredIfOtherFieldNotGiven:
|
||||||
if not all_data.get(self.other, False) and not field_data:
|
if not all_data.get(self.other, False) and not field_data:
|
||||||
raise ValidationError, self.error_message
|
raise ValidationError, self.error_message
|
||||||
|
|
||||||
class RequiredIfOtherFieldsGiven:
|
class RequiredIfOtherFieldsGiven(object):
|
||||||
def __init__(self, other_field_names, error_message=gettext_lazy("Please enter both fields or leave them both empty.")):
|
def __init__(self, other_field_names, error_message=gettext_lazy("Please enter both fields or leave them both empty.")):
|
||||||
self.other, self.error_message = other_field_names, error_message
|
self.other, self.error_message = other_field_names, error_message
|
||||||
self.always_test = True
|
self.always_test = True
|
||||||
|
@ -282,7 +282,7 @@ class RequiredIfOtherFieldGiven(RequiredIfOtherFieldsGiven):
|
||||||
def __init__(self, other_field_name, error_message=gettext_lazy("Please enter both fields or leave them both empty.")):
|
def __init__(self, other_field_name, error_message=gettext_lazy("Please enter both fields or leave them both empty.")):
|
||||||
RequiredIfOtherFieldsGiven.__init__(self, [other_field_name], error_message)
|
RequiredIfOtherFieldsGiven.__init__(self, [other_field_name], error_message)
|
||||||
|
|
||||||
class RequiredIfOtherFieldEquals:
|
class RequiredIfOtherFieldEquals(object):
|
||||||
def __init__(self, other_field, other_value, error_message=None):
|
def __init__(self, other_field, other_value, error_message=None):
|
||||||
self.other_field = other_field
|
self.other_field = other_field
|
||||||
self.other_value = other_value
|
self.other_value = other_value
|
||||||
|
@ -294,7 +294,7 @@ class RequiredIfOtherFieldEquals:
|
||||||
if all_data.has_key(self.other_field) and all_data[self.other_field] == self.other_value and not field_data:
|
if all_data.has_key(self.other_field) and all_data[self.other_field] == self.other_value and not field_data:
|
||||||
raise ValidationError(self.error_message)
|
raise ValidationError(self.error_message)
|
||||||
|
|
||||||
class RequiredIfOtherFieldDoesNotEqual:
|
class RequiredIfOtherFieldDoesNotEqual(object):
|
||||||
def __init__(self, other_field, other_value, error_message=None):
|
def __init__(self, other_field, other_value, error_message=None):
|
||||||
self.other_field = other_field
|
self.other_field = other_field
|
||||||
self.other_value = other_value
|
self.other_value = other_value
|
||||||
|
@ -306,7 +306,7 @@ class RequiredIfOtherFieldDoesNotEqual:
|
||||||
if all_data.has_key(self.other_field) and all_data[self.other_field] != self.other_value and not field_data:
|
if all_data.has_key(self.other_field) and all_data[self.other_field] != self.other_value and not field_data:
|
||||||
raise ValidationError(self.error_message)
|
raise ValidationError(self.error_message)
|
||||||
|
|
||||||
class IsLessThanOtherField:
|
class IsLessThanOtherField(object):
|
||||||
def __init__(self, other_field_name, error_message):
|
def __init__(self, other_field_name, error_message):
|
||||||
self.other, self.error_message = other_field_name, error_message
|
self.other, self.error_message = other_field_name, error_message
|
||||||
|
|
||||||
|
@ -314,7 +314,7 @@ class IsLessThanOtherField:
|
||||||
if field_data > all_data[self.other]:
|
if field_data > all_data[self.other]:
|
||||||
raise ValidationError, self.error_message
|
raise ValidationError, self.error_message
|
||||||
|
|
||||||
class UniqueAmongstFieldsWithPrefix:
|
class UniqueAmongstFieldsWithPrefix(object):
|
||||||
def __init__(self, field_name, prefix, error_message):
|
def __init__(self, field_name, prefix, error_message):
|
||||||
self.field_name, self.prefix = field_name, prefix
|
self.field_name, self.prefix = field_name, prefix
|
||||||
self.error_message = error_message or gettext_lazy("Duplicate values are not allowed.")
|
self.error_message = error_message or gettext_lazy("Duplicate values are not allowed.")
|
||||||
|
@ -324,7 +324,7 @@ class UniqueAmongstFieldsWithPrefix:
|
||||||
if field_name != self.field_name and value == field_data:
|
if field_name != self.field_name and value == field_data:
|
||||||
raise ValidationError, self.error_message
|
raise ValidationError, self.error_message
|
||||||
|
|
||||||
class IsAPowerOf:
|
class IsAPowerOf(object):
|
||||||
"""
|
"""
|
||||||
>>> v = IsAPowerOf(2)
|
>>> v = IsAPowerOf(2)
|
||||||
>>> v(4, None)
|
>>> v(4, None)
|
||||||
|
@ -342,7 +342,7 @@ class IsAPowerOf:
|
||||||
if val != int(val):
|
if val != int(val):
|
||||||
raise ValidationError, gettext("This value must be a power of %s.") % self.power_of
|
raise ValidationError, gettext("This value must be a power of %s.") % self.power_of
|
||||||
|
|
||||||
class IsValidFloat:
|
class IsValidFloat(object):
|
||||||
def __init__(self, max_digits, decimal_places):
|
def __init__(self, max_digits, decimal_places):
|
||||||
self.max_digits, self.decimal_places = max_digits, decimal_places
|
self.max_digits, self.decimal_places = max_digits, decimal_places
|
||||||
|
|
||||||
|
@ -359,7 +359,7 @@ class IsValidFloat:
|
||||||
raise ValidationError, ngettext("Please enter a valid decimal number with at most %s decimal place.",
|
raise ValidationError, ngettext("Please enter a valid decimal number with at most %s decimal place.",
|
||||||
"Please enter a valid decimal number with at most %s decimal places.", self.decimal_places) % self.decimal_places
|
"Please enter a valid decimal number with at most %s decimal places.", self.decimal_places) % self.decimal_places
|
||||||
|
|
||||||
class HasAllowableSize:
|
class HasAllowableSize(object):
|
||||||
"""
|
"""
|
||||||
Checks that the file-upload field data is a certain size. min_size and
|
Checks that the file-upload field data is a certain size. min_size and
|
||||||
max_size are measurements in bytes.
|
max_size are measurements in bytes.
|
||||||
|
@ -379,7 +379,7 @@ class HasAllowableSize:
|
||||||
if self.max_size is not None and len(content) > self.max_size:
|
if self.max_size is not None and len(content) > self.max_size:
|
||||||
raise ValidationError, self.max_error_message
|
raise ValidationError, self.max_error_message
|
||||||
|
|
||||||
class MatchesRegularExpression:
|
class MatchesRegularExpression(object):
|
||||||
"""
|
"""
|
||||||
Checks that the field matches the given regular-expression. The regex
|
Checks that the field matches the given regular-expression. The regex
|
||||||
should be in string format, not already compiled.
|
should be in string format, not already compiled.
|
||||||
|
@ -392,7 +392,7 @@ class MatchesRegularExpression:
|
||||||
if not self.regexp.search(field_data):
|
if not self.regexp.search(field_data):
|
||||||
raise ValidationError(self.error_message)
|
raise ValidationError(self.error_message)
|
||||||
|
|
||||||
class AnyValidator:
|
class AnyValidator(object):
|
||||||
"""
|
"""
|
||||||
This validator tries all given validators. If any one of them succeeds,
|
This validator tries all given validators. If any one of them succeeds,
|
||||||
validation passes. If none of them succeeds, the given message is thrown
|
validation passes. If none of them succeeds, the given message is thrown
|
||||||
|
@ -416,7 +416,7 @@ class AnyValidator:
|
||||||
pass
|
pass
|
||||||
raise ValidationError(self.error_message)
|
raise ValidationError(self.error_message)
|
||||||
|
|
||||||
class URLMimeTypeCheck:
|
class URLMimeTypeCheck(object):
|
||||||
"Checks that the provided URL points to a document with a listed mime type"
|
"Checks that the provided URL points to a document with a listed mime type"
|
||||||
class CouldNotRetrieve(ValidationError):
|
class CouldNotRetrieve(ValidationError):
|
||||||
pass
|
pass
|
||||||
|
@ -441,7 +441,7 @@ class URLMimeTypeCheck:
|
||||||
raise URLMimeTypeCheck.InvalidContentType, gettext("The URL %(url)s returned the invalid Content-Type header '%(contenttype)s'.") % {
|
raise URLMimeTypeCheck.InvalidContentType, gettext("The URL %(url)s returned the invalid Content-Type header '%(contenttype)s'.") % {
|
||||||
'url': field_data, 'contenttype': content_type}
|
'url': field_data, 'contenttype': content_type}
|
||||||
|
|
||||||
class RelaxNGCompact:
|
class RelaxNGCompact(object):
|
||||||
"Validate against a Relax NG compact schema"
|
"Validate against a Relax NG compact schema"
|
||||||
def __init__(self, schema_path, additional_root_element=None):
|
def __init__(self, schema_path, additional_root_element=None):
|
||||||
self.schema_path = schema_path
|
self.schema_path = schema_path
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import datetime
|
import datetime
|
||||||
from time import time
|
from time import time
|
||||||
|
|
||||||
class CursorDebugWrapper:
|
class CursorDebugWrapper(object):
|
||||||
def __init__(self, cursor, db):
|
def __init__(self, cursor, db):
|
||||||
self.cursor = cursor
|
self.cursor = cursor
|
||||||
self.db = db
|
self.db = db
|
||||||
|
|
|
@ -15,7 +15,7 @@ from django.utils.text import capfirst
|
||||||
# Admin stages.
|
# Admin stages.
|
||||||
ADD, CHANGE, BOTH = 1, 2, 3
|
ADD, CHANGE, BOTH = 1, 2, 3
|
||||||
|
|
||||||
class LazyDate:
|
class LazyDate(object):
|
||||||
"""
|
"""
|
||||||
Use in limit_choices_to to compare the field to dates calculated at run time
|
Use in limit_choices_to to compare the field to dates calculated at run time
|
||||||
instead of when the model is loaded. For example::
|
instead of when the model is loaded. For example::
|
||||||
|
|
|
@ -535,7 +535,7 @@ class FileField(Field):
|
||||||
if not self.blank:
|
if not self.blank:
|
||||||
if rel:
|
if rel:
|
||||||
# This validator makes sure FileFields work in a related context.
|
# This validator makes sure FileFields work in a related context.
|
||||||
class RequiredFileField:
|
class RequiredFileField(object):
|
||||||
def __init__(self, other_field_names, other_file_field_name):
|
def __init__(self, other_field_names, other_file_field_name):
|
||||||
self.other_field_names = other_field_names
|
self.other_field_names = other_field_names
|
||||||
self.other_file_field_name = other_file_field_name
|
self.other_file_field_name = other_file_field_name
|
||||||
|
|
|
@ -667,7 +667,7 @@ class ManyToManyField(RelatedField, Field):
|
||||||
def set_attributes_from_rel(self):
|
def set_attributes_from_rel(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class ManyToOneRel:
|
class ManyToOneRel(object):
|
||||||
def __init__(self, to, field_name, num_in_admin=3, min_num_in_admin=None,
|
def __init__(self, to, field_name, num_in_admin=3, min_num_in_admin=None,
|
||||||
max_num_in_admin=None, num_extra_on_change=1, edit_inline=False,
|
max_num_in_admin=None, num_extra_on_change=1, edit_inline=False,
|
||||||
related_name=None, limit_choices_to=None, lookup_overrides=None, raw_id_admin=False):
|
related_name=None, limit_choices_to=None, lookup_overrides=None, raw_id_admin=False):
|
||||||
|
@ -704,7 +704,7 @@ class OneToOneRel(ManyToOneRel):
|
||||||
self.raw_id_admin = raw_id_admin
|
self.raw_id_admin = raw_id_admin
|
||||||
self.multiple = False
|
self.multiple = False
|
||||||
|
|
||||||
class ManyToManyRel:
|
class ManyToManyRel(object):
|
||||||
def __init__(self, to, num_in_admin=0, related_name=None,
|
def __init__(self, to, num_in_admin=0, related_name=None,
|
||||||
filter_interface=None, limit_choices_to=None, raw_id_admin=False, symmetrical=True):
|
filter_interface=None, limit_choices_to=None, raw_id_admin=False, symmetrical=True):
|
||||||
self.to = to
|
self.to = to
|
||||||
|
|
|
@ -15,7 +15,7 @@ DEFAULT_NAMES = ('verbose_name', 'db_table', 'ordering',
|
||||||
'unique_together', 'permissions', 'get_latest_by',
|
'unique_together', 'permissions', 'get_latest_by',
|
||||||
'order_with_respect_to', 'app_label')
|
'order_with_respect_to', 'app_label')
|
||||||
|
|
||||||
class Options:
|
class Options(object):
|
||||||
def __init__(self, meta):
|
def __init__(self, meta):
|
||||||
self.fields, self.many_to_many = [], []
|
self.fields, self.many_to_many = [], []
|
||||||
self.module_name, self.verbose_name = None, None
|
self.module_name, self.verbose_name = None, None
|
||||||
|
@ -195,7 +195,7 @@ class Options:
|
||||||
self._field_types[field_type] = False
|
self._field_types[field_type] = False
|
||||||
return self._field_types[field_type]
|
return self._field_types[field_type]
|
||||||
|
|
||||||
class AdminOptions:
|
class AdminOptions(object):
|
||||||
def __init__(self, fields=None, js=None, list_display=None, list_filter=None,
|
def __init__(self, fields=None, js=None, list_display=None, list_filter=None,
|
||||||
date_hierarchy=None, save_as=False, ordering=None, search_fields=None,
|
date_hierarchy=None, save_as=False, ordering=None, search_fields=None,
|
||||||
save_on_top=False, list_select_related=False, manager=None, list_per_page=100):
|
save_on_top=False, list_select_related=False, manager=None, list_per_page=100):
|
||||||
|
|
|
@ -546,7 +546,7 @@ class DateQuerySet(QuerySet):
|
||||||
c._order = self._order
|
c._order = self._order
|
||||||
return c
|
return c
|
||||||
|
|
||||||
class QOperator:
|
class QOperator(object):
|
||||||
"Base class for QAnd and QOr"
|
"Base class for QAnd and QOr"
|
||||||
def __init__(self, *args):
|
def __init__(self, *args):
|
||||||
self.args = args
|
self.args = args
|
||||||
|
|
|
@ -101,7 +101,7 @@ class Manipulator(object):
|
||||||
for field in self.fields:
|
for field in self.fields:
|
||||||
field.convert_post_data(new_data)
|
field.convert_post_data(new_data)
|
||||||
|
|
||||||
class FormWrapper:
|
class FormWrapper(object):
|
||||||
"""
|
"""
|
||||||
A wrapper linking a Manipulator to the template system.
|
A wrapper linking a Manipulator to the template system.
|
||||||
This allows dictionary-style lookups of formfields. It also handles feeding
|
This allows dictionary-style lookups of formfields. It also handles feeding
|
||||||
|
@ -150,7 +150,7 @@ class FormWrapper:
|
||||||
|
|
||||||
fields = property(_get_fields)
|
fields = property(_get_fields)
|
||||||
|
|
||||||
class FormFieldWrapper:
|
class FormFieldWrapper(object):
|
||||||
"A bridge between the template system and an individual form field. Used by FormWrapper."
|
"A bridge between the template system and an individual form field. Used by FormWrapper."
|
||||||
def __init__(self, formfield, data, error_list):
|
def __init__(self, formfield, data, error_list):
|
||||||
self.formfield, self.data, self.error_list = formfield, data, error_list
|
self.formfield, self.data, self.error_list = formfield, data, error_list
|
||||||
|
@ -211,7 +211,7 @@ class FormFieldCollection(FormFieldWrapper):
|
||||||
def html_combined_error_list(self):
|
def html_combined_error_list(self):
|
||||||
return ''.join([field.html_error_list() for field in self.formfield_dict.values() if hasattr(field, 'errors')])
|
return ''.join([field.html_error_list() for field in self.formfield_dict.values() if hasattr(field, 'errors')])
|
||||||
|
|
||||||
class InlineObjectCollection:
|
class InlineObjectCollection(object):
|
||||||
"An object that acts like a sparse list of form field collections."
|
"An object that acts like a sparse list of form field collections."
|
||||||
def __init__(self, parent_manipulator, rel_obj, data, errors):
|
def __init__(self, parent_manipulator, rel_obj, data, errors):
|
||||||
self.parent_manipulator = parent_manipulator
|
self.parent_manipulator = parent_manipulator
|
||||||
|
@ -269,7 +269,7 @@ class InlineObjectCollection:
|
||||||
self._collections = collections
|
self._collections = collections
|
||||||
|
|
||||||
|
|
||||||
class FormField:
|
class FormField(object):
|
||||||
"""Abstract class representing a form field.
|
"""Abstract class representing a form field.
|
||||||
|
|
||||||
Classes that extend FormField should define the following attributes:
|
Classes that extend FormField should define the following attributes:
|
||||||
|
|
|
@ -3,7 +3,7 @@ from django.core.cache import cache
|
||||||
from django.utils.cache import get_cache_key, learn_cache_key, patch_response_headers
|
from django.utils.cache import get_cache_key, learn_cache_key, patch_response_headers
|
||||||
from django.http import HttpResponseNotModified
|
from django.http import HttpResponseNotModified
|
||||||
|
|
||||||
class CacheMiddleware:
|
class CacheMiddleware(object):
|
||||||
"""
|
"""
|
||||||
Cache middleware. If this is enabled, each Django-powered page will be
|
Cache middleware. If this is enabled, each Django-powered page will be
|
||||||
cached for CACHE_MIDDLEWARE_SECONDS seconds. Cache is based on URLs.
|
cached for CACHE_MIDDLEWARE_SECONDS seconds. Cache is based on URLs.
|
||||||
|
|
|
@ -3,7 +3,7 @@ from django import http
|
||||||
from django.core.mail import mail_managers
|
from django.core.mail import mail_managers
|
||||||
import md5, os
|
import md5, os
|
||||||
|
|
||||||
class CommonMiddleware:
|
class CommonMiddleware(object):
|
||||||
"""
|
"""
|
||||||
"Common" middleware for taking care of some basic operations:
|
"Common" middleware for taking care of some basic operations:
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django import http
|
from django import http
|
||||||
|
|
||||||
class XViewMiddleware:
|
class XViewMiddleware(object):
|
||||||
"""
|
"""
|
||||||
Adds an X-View header to internal HEAD requests -- used by the documentation system.
|
Adds an X-View header to internal HEAD requests -- used by the documentation system.
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -4,7 +4,7 @@ from django.utils.cache import patch_vary_headers
|
||||||
|
|
||||||
re_accepts_gzip = re.compile(r'\bgzip\b')
|
re_accepts_gzip = re.compile(r'\bgzip\b')
|
||||||
|
|
||||||
class GZipMiddleware:
|
class GZipMiddleware(object):
|
||||||
"""
|
"""
|
||||||
This middleware compresses content if the browser allows gzip compression.
|
This middleware compresses content if the browser allows gzip compression.
|
||||||
It sets the Vary header accordingly, so that caches will base their storage
|
It sets the Vary header accordingly, so that caches will base their storage
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
class ConditionalGetMiddleware:
|
class ConditionalGetMiddleware(object):
|
||||||
"""
|
"""
|
||||||
Handles conditional GET operations. If the response has a ETag or
|
Handles conditional GET operations. If the response has a ETag or
|
||||||
Last-Modified header, and the request has If-None-Match or
|
Last-Modified header, and the request has If-None-Match or
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
from django.utils.cache import patch_vary_headers
|
from django.utils.cache import patch_vary_headers
|
||||||
from django.utils import translation
|
from django.utils import translation
|
||||||
|
|
||||||
class LocaleMiddleware:
|
class LocaleMiddleware(object):
|
||||||
"""
|
"""
|
||||||
This is a very simple middleware that parses a request
|
This is a very simple middleware that parses a request
|
||||||
and decides what translation object to install in the current
|
and decides what translation object to install in the current
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import transaction
|
from django.db import transaction
|
||||||
|
|
||||||
class TransactionMiddleware:
|
class TransactionMiddleware(object):
|
||||||
"""
|
"""
|
||||||
Transaction middleware. If this is enabled, each view function will be run
|
Transaction middleware. If this is enabled, each view function will be run
|
||||||
with commit_on_response activated - that way a save() doesn't do a direct
|
with commit_on_response activated - that way a save() doesn't do a direct
|
||||||
|
|
|
@ -134,7 +134,7 @@ class StringOrigin(Origin):
|
||||||
def reload(self):
|
def reload(self):
|
||||||
return self.source
|
return self.source
|
||||||
|
|
||||||
class Template:
|
class Template(object):
|
||||||
def __init__(self, template_string, origin=None):
|
def __init__(self, template_string, origin=None):
|
||||||
"Compilation stage"
|
"Compilation stage"
|
||||||
if settings.TEMPLATE_DEBUG and origin == None:
|
if settings.TEMPLATE_DEBUG and origin == None:
|
||||||
|
@ -158,7 +158,7 @@ def compile_string(template_string, origin):
|
||||||
parser = parser_factory(lexer.tokenize())
|
parser = parser_factory(lexer.tokenize())
|
||||||
return parser.parse()
|
return parser.parse()
|
||||||
|
|
||||||
class Token:
|
class Token(object):
|
||||||
def __init__(self, token_type, contents):
|
def __init__(self, token_type, contents):
|
||||||
"The token_type must be TOKEN_TEXT, TOKEN_VAR or TOKEN_BLOCK"
|
"The token_type must be TOKEN_TEXT, TOKEN_VAR or TOKEN_BLOCK"
|
||||||
self.token_type, self.contents = token_type, contents
|
self.token_type, self.contents = token_type, contents
|
||||||
|
@ -376,7 +376,7 @@ def parser_factory(*args, **kwargs):
|
||||||
else:
|
else:
|
||||||
return Parser(*args, **kwargs)
|
return Parser(*args, **kwargs)
|
||||||
|
|
||||||
class TokenParser:
|
class TokenParser(object):
|
||||||
"""
|
"""
|
||||||
Subclass this and implement the top() method to parse a template line. When
|
Subclass this and implement the top() method to parse a template line. When
|
||||||
instantiating the parser, pass in the line from the Django template parser.
|
instantiating the parser, pass in the line from the Django template parser.
|
||||||
|
@ -654,7 +654,7 @@ def resolve_variable(path, context):
|
||||||
del bits[0]
|
del bits[0]
|
||||||
return current
|
return current
|
||||||
|
|
||||||
class Node:
|
class Node(object):
|
||||||
def render(self, context):
|
def render(self, context):
|
||||||
"Return the node rendered as a string"
|
"Return the node rendered as a string"
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -7,7 +7,7 @@ class ContextPopException(Exception):
|
||||||
"pop() has been called more times than push()"
|
"pop() has been called more times than push()"
|
||||||
pass
|
pass
|
||||||
|
|
||||||
class Context:
|
class Context(object):
|
||||||
"A stack container for variable context"
|
"A stack container for variable context"
|
||||||
def __init__(self, dict_=None):
|
def __init__(self, dict_=None):
|
||||||
dict_ = dict_ or {}
|
dict_ = dict_ or {}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
class MergeDict:
|
class MergeDict(object):
|
||||||
"""
|
"""
|
||||||
A simple class for creating new "virtual" dictionaries that actualy look
|
A simple class for creating new "virtual" dictionaries that actualy look
|
||||||
up values in more than one dictionary, passed in the constructor.
|
up values in more than one dictionary, passed in the constructor.
|
||||||
|
|
|
@ -19,7 +19,7 @@ import re, time
|
||||||
re_formatchars = re.compile(r'(?<!\\)([aABdDfFgGhHiIjlLmMnNOPrsStTUwWyYzZ])')
|
re_formatchars = re.compile(r'(?<!\\)([aABdDfFgGhHiIjlLmMnNOPrsStTUwWyYzZ])')
|
||||||
re_escaped = re.compile(r'\\(.)')
|
re_escaped = re.compile(r'\\(.)')
|
||||||
|
|
||||||
class Formatter:
|
class Formatter(object):
|
||||||
def format(self, formatstr):
|
def format(self, formatstr):
|
||||||
pieces = []
|
pieces = []
|
||||||
for i, piece in enumerate(re_formatchars.split(formatstr)):
|
for i, piece in enumerate(re_formatchars.split(formatstr)):
|
||||||
|
|
|
@ -36,7 +36,7 @@ def get_tag_uri(url, date):
|
||||||
tag = re.sub('#', '/', tag)
|
tag = re.sub('#', '/', tag)
|
||||||
return 'tag:' + tag
|
return 'tag:' + tag
|
||||||
|
|
||||||
class SyndicationFeed:
|
class SyndicationFeed(object):
|
||||||
"Base class for all syndication feeds. Subclasses should provide write()"
|
"Base class for all syndication feeds. Subclasses should provide write()"
|
||||||
def __init__(self, title, link, description, language=None, author_email=None,
|
def __init__(self, title, link, description, language=None, author_email=None,
|
||||||
author_name=None, author_link=None, subtitle=None, categories=None,
|
author_name=None, author_link=None, subtitle=None, categories=None,
|
||||||
|
@ -108,7 +108,7 @@ class SyndicationFeed:
|
||||||
else:
|
else:
|
||||||
return datetime.datetime.now()
|
return datetime.datetime.now()
|
||||||
|
|
||||||
class Enclosure:
|
class Enclosure(object):
|
||||||
"Represents an RSS enclosure"
|
"Represents an RSS enclosure"
|
||||||
def __init__(self, url, length, mime_type):
|
def __init__(self, url, length, mime_type):
|
||||||
"All args are expected to be Python Unicode objects"
|
"All args are expected to be Python Unicode objects"
|
||||||
|
|
|
@ -169,8 +169,7 @@ TEMPLATE_TESTS = {
|
||||||
'comment-tag05': ("foo{% comment %} {% somerandomtag %} {% endcomment %}", {}, "foo"),
|
'comment-tag05': ("foo{% comment %} {% somerandomtag %} {% endcomment %}", {}, "foo"),
|
||||||
|
|
||||||
### CYCLE TAG #############################################################
|
### CYCLE TAG #############################################################
|
||||||
#'cycleXX': ('', {}, ''),
|
'cycle01': ('{% cycle a %}', {}, template.TemplateSyntaxError),
|
||||||
'cycle01': ('{% cycle a, %}', {}, 'a'),
|
|
||||||
'cycle02': ('{% cycle a,b,c as abc %}{% cycle abc %}', {}, 'ab'),
|
'cycle02': ('{% cycle a,b,c as abc %}{% cycle abc %}', {}, 'ab'),
|
||||||
'cycle03': ('{% cycle a,b,c as abc %}{% cycle abc %}{% cycle abc %}', {}, 'abc'),
|
'cycle03': ('{% cycle a,b,c as abc %}{% cycle abc %}{% cycle abc %}', {}, 'abc'),
|
||||||
'cycle04': ('{% cycle a,b,c as abc %}{% cycle abc %}{% cycle abc %}{% cycle abc %}', {}, 'abca'),
|
'cycle04': ('{% cycle a,b,c as abc %}{% cycle abc %}{% cycle abc %}{% cycle abc %}', {}, 'abca'),
|
||||||
|
|
Loading…
Reference in New Issue