-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathcompat.py
33 lines (27 loc) · 871 Bytes
/
compat.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
try:
from django.urls import (
URLPattern,
URLResolver,
)
except ImportError:
# Will be removed in Django 2.0
from django.urls import (
RegexURLPattern as URLPattern,
RegexURLResolver as URLResolver,
)
# This is from the similarly named compat.py file of django-rest-framework 3.7
def get_regex_pattern(urlpattern):
"""
Get the raw regex out of the urlpattern's RegexPattern or RoutePattern.
This is always a regular expression, unlike get_original_route above.
"""
if hasattr(urlpattern, 'pattern'):
# Django 2.0
return urlpattern.pattern.regex.pattern
else:
# Django < 2.0
return urlpattern.regex.pattern
def is_url_resolver(instance):
return isinstance(instance, URLResolver)
def is_url_pattern(instance):
return isinstance(instance, URLPattern)