mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-03 20:10:10 +03:00
Refactor compat url pattern/resolver imports
This commit is contained in:
parent
dd628cc176
commit
c01d9d63ee
|
@ -18,14 +18,14 @@ from django.views.generic import View
|
|||
|
||||
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):
|
||||
|
|
|
@ -15,7 +15,7 @@ from django.utils import six
|
|||
|
||||
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 @@ class EndpointEnumerator(object):
|
|||
|
||||
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 @@ class EndpointEnumerator(object):
|
|||
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
|
||||
|
|
|
@ -2,14 +2,14 @@ from __future__ import unicode_literals
|
|||
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue
Block a user