diff --git a/rest_framework/compat.py b/rest_framework/compat.py
index 67531948e..9c649215c 100644
--- a/rest_framework/compat.py
+++ b/rest_framework/compat.py
@@ -3,7 +3,6 @@ The `compat` module provides support for backwards compatibility with older
versions of Django/Python, and compatibility wrappers around optional packages.
"""
-# flake8: noqa
from __future__ import unicode_literals
import inspect
@@ -11,15 +10,9 @@ import inspect
import django
from django.apps import apps
from django.conf import settings
-from django.core.exceptions import ImproperlyConfigured, ValidationError
-from django.core.validators import \
- MaxLengthValidator as DjangoMaxLengthValidator
-from django.core.validators import MaxValueValidator as DjangoMaxValueValidator
-from django.core.validators import \
- MinLengthValidator as DjangoMinLengthValidator
-from django.core.validators import MinValueValidator as DjangoMinValueValidator
+from django.core import validators
+from django.core.exceptions import ImproperlyConfigured
from django.db import connection, models, transaction
-from django.template import Context, RequestContext, Template
from django.utils import six
from django.views.generic import View
@@ -152,7 +145,7 @@ except ImportError:
guardian = None
try:
if 'guardian' in settings.INSTALLED_APPS:
- import guardian
+ import guardian # noqa
except ImportError:
pass
@@ -229,7 +222,7 @@ if markdown is not None and pygments is not None:
class CodeBlockPreprocessor(Preprocessor):
pattern = re.compile(
- r'^\s*``` *([^\n]+)\n(.+?)^\s*```', re.M|re.S)
+ r'^\s*``` *([^\n]+)\n(.+?)^\s*```', re.M | re.S)
formatter = HtmlFormatter()
@@ -239,9 +232,9 @@ if markdown is not None and pygments is not None:
lexer = get_lexer_by_name(m.group(1))
except (ValueError, NameError):
lexer = TextLexer()
- code = m.group(2).replace('\t',' ')
+ code = m.group(2).replace('\t', ' ')
code = pygments.highlight(code, lexer, self.formatter)
- code = code.replace('\n\n', '\n \n').replace('\n', '
').replace('\\@','@')
+ code = code.replace('\n\n', '\n \n').replace('\n', '
').replace('\\@', '@')
return '\n\n%s\n\n' % code
ret = self.pattern.sub(repl, "\n".join(lines))
return ret.split("\n")
@@ -254,7 +247,7 @@ else:
return False
try:
- import pytz
+ import pytz # noqa
from pytz.exceptions import InvalidTimeError
except ImportError:
InvalidTimeError = Exception
@@ -279,22 +272,28 @@ class CustomValidatorMessage(object):
Ref: https://github.com/encode/django-rest-framework/pull/5452
"""
+
def __init__(self, *args, **kwargs):
self.message = kwargs.pop('message', self.message)
super(CustomValidatorMessage, self).__init__(*args, **kwargs)
-class MinValueValidator(CustomValidatorMessage, DjangoMinValueValidator):
+
+class MinValueValidator(CustomValidatorMessage, validators.MinValueValidator):
pass
-class MaxValueValidator(CustomValidatorMessage, DjangoMaxValueValidator):
+
+class MaxValueValidator(CustomValidatorMessage, validators.MaxValueValidator):
pass
-class MinLengthValidator(CustomValidatorMessage, DjangoMinLengthValidator):
+
+class MinLengthValidator(CustomValidatorMessage, validators.MinLengthValidator):
pass
-class MaxLengthValidator(CustomValidatorMessage, DjangoMaxLengthValidator):
+
+class MaxLengthValidator(CustomValidatorMessage, validators.MaxLengthValidator):
pass
+
def set_rollback():
if hasattr(transaction, 'set_rollback'):
if connection.settings_dict.get('ATOMIC_REQUESTS', False):
@@ -318,4 +317,3 @@ def authenticate(request=None, **credentials):
return authenticate(**credentials)
else:
return authenticate(request=request, **credentials)
-