From 5f8438697ac3c3af3a709b5d2da37135662d921c Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Thu, 9 Nov 2017 10:12:16 -0500 Subject: [PATCH 1/5] Reenable flake8 on compat, cleanup style/imports --- rest_framework/compat.py | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/rest_framework/compat.py b/rest_framework/compat.py index 67531948ee..9c649215c2 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -3,7 +3,6 @@ versions of Django/Python, and compatibility wrappers around optional packages. """ -# flake8: noqa from __future__ import unicode_literals import inspect @@ -11,15 +10,9 @@ 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 @@ def _resolve_model(obj): guardian = None try: if 'guardian' in settings.INSTALLED_APPS: - import guardian + import guardian # noqa except ImportError: pass @@ -229,7 +222,7 @@ def pygments_css(style): 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 @@ def repl(m): 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 @@ def md_filter_add_syntax_highlight(md): 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) - From dd628cc176187a8674952371cde623e77df58f1a Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Thu, 9 Nov 2017 10:12:57 -0500 Subject: [PATCH 2/5] Cleanup compat urls imports --- rest_framework/compat.py | 12 +++++++----- rest_framework/relations.py | 4 +--- rest_framework/reverse.py | 4 ++-- rest_framework/routers.py | 2 +- rest_framework/templatetags/rest_framework.py | 6 ++---- rest_framework/utils/breadcrumbs.py | 2 +- tests/test_permissions.py | 3 ++- tests/test_reverse.py | 2 +- tests/test_urlpatterns.py | 3 ++- tests/utils.py | 3 +-- 10 files changed, 20 insertions(+), 21 deletions(-) diff --git a/rest_framework/compat.py b/rest_framework/compat.py index 9c649215c2..fc42108ff4 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -17,13 +17,15 @@ from django.views.generic import View try: - from django.urls import ( - NoReverseMatch, URLPattern as RegexURLPattern, URLResolver as RegexURLResolver, ResolverMatch, Resolver404, get_script_prefix, reverse, reverse_lazy, resolve + from django.urls import ( # noqa + URLPattern as RegexURLPattern, + URLResolver as RegexURLResolver, ) - except ImportError: - from django.core.urlresolvers import ( # Will be removed in Django 2.0 - NoReverseMatch, RegexURLPattern, RegexURLResolver, ResolverMatch, Resolver404, get_script_prefix, reverse, reverse_lazy, resolve + # Will be removed in Django 2.0 + from django.urls import ( # noqa + RegexURLPattern, + RegexURLResolver, ) diff --git a/rest_framework/relations.py b/rest_framework/relations.py index 4d3bdba1dc..22078e64a4 100644 --- a/rest_framework/relations.py +++ b/rest_framework/relations.py @@ -6,6 +6,7 @@ from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist from django.db.models import Manager from django.db.models.query import QuerySet +from django.urls import NoReverseMatch, Resolver404, get_script_prefix, resolve from django.utils import six from django.utils.encoding import ( python_2_unicode_compatible, smart_text, uri_to_iri @@ -13,9 +14,6 @@ from django.utils.six.moves.urllib import parse as urlparse from django.utils.translation import ugettext_lazy as _ -from rest_framework.compat import ( - NoReverseMatch, Resolver404, get_script_prefix, resolve -) from rest_framework.fields import ( Field, empty, get_attribute, is_simple_callable, iter_options ) diff --git a/rest_framework/reverse.py b/rest_framework/reverse.py index fd418dcca0..54c4635538 100644 --- a/rest_framework/reverse.py +++ b/rest_framework/reverse.py @@ -3,11 +3,11 @@ """ from __future__ import unicode_literals +from django.urls import reverse as django_reverse +from django.urls import NoReverseMatch from django.utils import six from django.utils.functional import lazy -from rest_framework.compat import reverse as django_reverse -from rest_framework.compat import NoReverseMatch from rest_framework.settings import api_settings from rest_framework.utils.urls import replace_query_param diff --git a/rest_framework/routers.py b/rest_framework/routers.py index 1ed3b930e9..2010a11384 100644 --- a/rest_framework/routers.py +++ b/rest_framework/routers.py @@ -20,9 +20,9 @@ from django.conf.urls import url from django.core.exceptions import ImproperlyConfigured +from django.urls import NoReverseMatch from rest_framework import views -from rest_framework.compat import NoReverseMatch from rest_framework.response import Response from rest_framework.reverse import reverse from rest_framework.schemas import SchemaGenerator diff --git a/rest_framework/templatetags/rest_framework.py b/rest_framework/templatetags/rest_framework.py index 20e0f7a67e..bc38c0a343 100644 --- a/rest_framework/templatetags/rest_framework.py +++ b/rest_framework/templatetags/rest_framework.py @@ -5,14 +5,12 @@ from django import template from django.template import loader +from django.urls import NoReverseMatch, reverse from django.utils import six from django.utils.encoding import force_text, iri_to_uri from django.utils.html import escape, format_html, smart_urlquote from django.utils.safestring import SafeData, mark_safe - -from rest_framework.compat import ( - NoReverseMatch, apply_markdown, pygments_highlight, reverse -) +from rest_framework.compat import apply_markdown, pygments_highlight from rest_framework.renderers import HTMLFormRenderer from rest_framework.utils.urls import replace_query_param diff --git a/rest_framework/utils/breadcrumbs.py b/rest_framework/utils/breadcrumbs.py index 22f0d8a3bc..4915eb978e 100644 --- a/rest_framework/utils/breadcrumbs.py +++ b/rest_framework/utils/breadcrumbs.py @@ -1,6 +1,6 @@ from __future__ import unicode_literals -from rest_framework.compat import get_script_prefix, resolve +from django.urls import get_script_prefix, resolve def get_breadcrumbs(url, request=None): diff --git a/tests/test_permissions.py b/tests/test_permissions.py index 7ccd436139..5d7cb20eaa 100644 --- a/tests/test_permissions.py +++ b/tests/test_permissions.py @@ -6,12 +6,13 @@ from django.contrib.auth.models import Group, Permission, User from django.db import models from django.test import TestCase +from django.urls import ResolverMatch from rest_framework import ( HTTP_HEADER_ENCODING, authentication, generics, permissions, serializers, status, views ) -from rest_framework.compat import ResolverMatch, guardian +from rest_framework.compat import guardian from rest_framework.filters import DjangoObjectPermissionsFilter from rest_framework.routers import DefaultRouter from rest_framework.test import APIRequestFactory diff --git a/tests/test_reverse.py b/tests/test_reverse.py index 47eda256ec..145b1a54f3 100644 --- a/tests/test_reverse.py +++ b/tests/test_reverse.py @@ -2,8 +2,8 @@ from django.conf.urls import url from django.test import TestCase, override_settings +from django.urls import NoReverseMatch -from rest_framework.compat import NoReverseMatch from rest_framework.reverse import reverse from rest_framework.test import APIRequestFactory diff --git a/tests/test_urlpatterns.py b/tests/test_urlpatterns.py index 7320de4793..e844651411 100644 --- a/tests/test_urlpatterns.py +++ b/tests/test_urlpatterns.py @@ -4,8 +4,9 @@ from django.conf.urls import include, url from django.test import TestCase +from django.urls import Resolver404 -from rest_framework.compat import Resolver404, make_url_resolver +from rest_framework.compat import make_url_resolver from rest_framework.test import APIRequestFactory from rest_framework.urlpatterns import format_suffix_patterns diff --git a/tests/utils.py b/tests/utils.py index 0ef37016dd..509e6a1027 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -1,6 +1,5 @@ from django.core.exceptions import ObjectDoesNotExist - -from rest_framework.compat import NoReverseMatch +from django.urls import NoReverseMatch class MockObject(object): From c01d9d63ee62e132c091084c5f2197bc8fceb9e2 Mon Sep 17 00:00:00 2001 From: Ryan P Kilby Date: Thu, 9 Nov 2017 10:20:02 -0500 Subject: [PATCH 3/5] Refactor compat url pattern/resolver imports --- rest_framework/compat.py | 12 ++++++------ rest_framework/schemas/generators.py | 6 +++--- rest_framework/urlpatterns.py | 4 ++-- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/rest_framework/compat.py b/rest_framework/compat.py index fc42108ff4..58f03eb553 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -18,14 +18,14 @@ try: from django.urls import ( # noqa - URLPattern as RegexURLPattern, - URLResolver as RegexURLResolver, + URLPattern, + URLResolver, ) except ImportError: # Will be removed in Django 2.0 from django.urls import ( # noqa - RegexURLPattern, - RegexURLResolver, + RegexURLPattern as URLPattern, + RegexURLResolver as URLResolver, ) @@ -42,11 +42,11 @@ def make_url_resolver(regex, urlpatterns): try: # Django 2.0 from django.urls.resolvers import RegexPattern - return RegexURLResolver(RegexPattern(regex), urlpatterns) + return URLResolver(RegexPattern(regex), urlpatterns) except ImportError: # Django < 2.0 - return RegexURLResolver(regex, urlpatterns) + return URLResolver(regex, urlpatterns) def unicode_repr(instance): diff --git a/rest_framework/schemas/generators.py b/rest_framework/schemas/generators.py index b28797b0bb..2fe4927d83 100644 --- a/rest_framework/schemas/generators.py +++ b/rest_framework/schemas/generators.py @@ -15,7 +15,7 @@ from rest_framework import exceptions from rest_framework.compat import ( - RegexURLPattern, RegexURLResolver, coreapi, coreschema, get_regex_pattern + URLPattern, URLResolver, coreapi, coreschema, get_regex_pattern ) from rest_framework.request import clone_request from rest_framework.settings import api_settings @@ -165,7 +165,7 @@ def get_api_endpoints(self, patterns=None, prefix=''): for pattern in patterns: path_regex = prefix + get_regex_pattern(pattern) - if isinstance(pattern, RegexURLPattern): + if isinstance(pattern, URLPattern): path = self.get_path_from_regex(path_regex) callback = pattern.callback if self.should_include_endpoint(path, callback): @@ -173,7 +173,7 @@ def get_api_endpoints(self, patterns=None, prefix=''): endpoint = (path, method, callback) api_endpoints.append(endpoint) - elif isinstance(pattern, RegexURLResolver): + elif isinstance(pattern, URLResolver): nested_endpoints = self.get_api_endpoints( patterns=pattern.url_patterns, prefix=path_regex diff --git a/rest_framework/urlpatterns.py b/rest_framework/urlpatterns.py index 293897b944..4aabc7f144 100644 --- a/rest_framework/urlpatterns.py +++ b/rest_framework/urlpatterns.py @@ -2,14 +2,14 @@ from django.conf.urls import include, url -from rest_framework.compat import RegexURLResolver, get_regex_pattern +from rest_framework.compat import URLResolver, get_regex_pattern from rest_framework.settings import api_settings def apply_suffix_patterns(urlpatterns, suffix_pattern, suffix_required): ret = [] for urlpattern in urlpatterns: - if isinstance(urlpattern, RegexURLResolver): + if isinstance(urlpattern, URLResolver): # Set of included URL patterns regex = get_regex_pattern(urlpattern) namespace = urlpattern.namespace From 6c4cf2c646bcfa9cb92eab080026c266964c2896 Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Fri, 10 Nov 2017 09:22:19 +0100 Subject: [PATCH 4/5] Add comment re dropping pytz compat ... when dropping Django 1.10 --- rest_framework/compat.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/rest_framework/compat.py b/rest_framework/compat.py index 58f03eb553..f34cdcc548 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -248,8 +248,9 @@ def md_filter_add_syntax_highlight(md): def md_filter_add_syntax_highlight(md): return False +# pytz is required from Django 1.11. Remove when dropping Django 1.10 support. try: - import pytz # noqa + import pytz # noqa from pytz.exceptions import InvalidTimeError except ImportError: InvalidTimeError = Exception From 5b152b2541b2fa7b8a34d90ca0ab2ea8ffa7e60f Mon Sep 17 00:00:00 2001 From: Carlton Gibson Date: Fri, 10 Nov 2017 09:31:16 +0100 Subject: [PATCH 5/5] Strip whitespace MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Grrr. GitHub web editor 😡 --- rest_framework/compat.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest_framework/compat.py b/rest_framework/compat.py index f34cdcc548..75a840ad59 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -248,7 +248,7 @@ def md_filter_add_syntax_highlight(md): def md_filter_add_syntax_highlight(md): return False -# pytz is required from Django 1.11. Remove when dropping Django 1.10 support. +# pytz is required from Django 1.11. Remove when dropping Django 1.10 support. try: import pytz # noqa from pytz.exceptions import InvalidTimeError pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy