-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
[WIP] URL dispatcher API. #5034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
7e85510
URL dispatcher API -- initial commit.
knbk 152896c
Added basic URL object.
knbk 2372282
Extended URL with several useful methods.
knbk 07af4d6
URL pre-nuke.
knbk 2d8b720
URL post-nuke.
knbk 40588eb
A few more tests for URL.
knbk d549fae
Added Constraint, RegexPattern.
knbk 0b0e21c
Added BaseResolver, Resolver and ResolverEndpoint.
knbk 2b737aa
Basic namespace handling.
knbk 440c5bc
Added support for passing a module/string reference to Resolver or a …
knbk 2271424
Lazy compilation for the regex in RegexPattern. Fixed args/kwargs
knbk 0af4fb2
Renamed urls to urls_tests.
knbk 06c120c
Lots of changes.
knbk 60f70d4
I should commit more often.
knbk ef17a24
Added repr to resolvers, fixed some tests.
knbk 285a349
Renamed url argument to path.
knbk 7839136
Resolved remaining test failures.
knbk 7c87c7d
Fixed test failures after rebase.
knbk c8b028f
Fixed some test failures on Python 2.
knbk 56cbdef
Moved resolve_error_handler outside the Resolver. Changed some of the
knbk cccaba1
Miscellaneous changes.
knbk c8fdec2
Flake8, isort, and moving some code.
knbk c6bf237
Deprecated django.core.urlresolvers in favour of django.core.urls.
knbk d702485
Removed django.core.urlresolvers references in the test suite.
knbk 1c8d49c
Moved URL to django.core.urls.utils.
knbk 7ec5094
Additional tests; flake8.
knbk e2ff966
Doc layout.
knbk cf2af51
Added request parameter to calls to resolve(). Added request parameter
knbk 0a35b16
Moved django.core.urls to django.urls.
knbk c0189bb
Fixed test failures on py2.
knbk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,13 +2,15 @@ | |
from importlib import import_module | ||
|
||
from django.core.exceptions import ImproperlyConfigured | ||
from django.core.urlresolvers import ( | ||
LocaleRegexURLResolver, RegexURLPattern, RegexURLResolver, | ||
from django.urls import ( | ||
BaseResolver, LocalePrefix, LocalizedRegexPattern, RegexPattern, Resolver, | ||
ResolverEndpoint, | ||
) | ||
from django.utils import six | ||
from django.utils.deprecation import ( | ||
RemovedInDjango20Warning, RemovedInDjango110Warning, | ||
) | ||
from django.utils.functional import Promise | ||
|
||
__all__ = ['handler400', 'handler403', 'handler404', 'handler500', 'include', 'patterns', 'url'] | ||
|
||
|
@@ -66,10 +68,10 @@ def include(arg, namespace=None, app_name=None): | |
# Make sure we can iterate through the patterns (without this, some | ||
# testcases will break). | ||
if isinstance(patterns, (list, tuple)): | ||
for url_pattern in patterns: | ||
for name, resolver in patterns: | ||
# Test if the LocaleRegexURLResolver is used within the include; | ||
# this should throw an error since this is not allowed! | ||
if isinstance(url_pattern, LocaleRegexURLResolver): | ||
if any(isinstance(constraint, LocalePrefix) for constraint in resolver.constraints): | ||
raise ImproperlyConfigured( | ||
'Using i18n_patterns in an included URLconf is not allowed.') | ||
|
||
|
@@ -86,28 +88,35 @@ def patterns(prefix, *args): | |
pattern_list = [] | ||
for t in args: | ||
if isinstance(t, (list, tuple)): | ||
t = url(prefix=prefix, *t) | ||
elif isinstance(t, RegexURLPattern): | ||
t.add_prefix(prefix) | ||
if len(t) != 2 or not isinstance(t[1], BaseResolver): | ||
t = url(prefix=prefix, *t) | ||
elif len(t) == 2 and isinstance(t[1], ResolverEndpoint): | ||
t[1].add_prefix(prefix) | ||
pattern_list.append(t) | ||
return pattern_list | ||
|
||
|
||
def url(regex, view, kwargs=None, name=None, prefix=''): | ||
def url(constraints, view, kwargs=None, name=None, prefix='', decorators=None): | ||
if isinstance(constraints, six.string_types): | ||
constraints = RegexPattern(constraints) | ||
elif isinstance(constraints, Promise): | ||
constraints = LocalizedRegexPattern(constraints) | ||
if not isinstance(constraints, (list, tuple)): | ||
constraints = [constraints] | ||
|
||
if isinstance(view, (list, tuple)): | ||
# For include(...) processing. | ||
urlconf_module, app_name, namespace = view | ||
return RegexURLResolver(regex, urlconf_module, kwargs, app_name=app_name, namespace=namespace) | ||
resolvers, app_name, namespace = view | ||
return namespace, Resolver(resolvers, app_name, constraints=constraints, kwargs=kwargs, decorators=decorators) | ||
else: | ||
if isinstance(view, six.string_types): | ||
warnings.warn( | ||
'Support for string view arguments to url() is deprecated and ' | ||
'will be removed in Django 1.10 (got %s). Pass the callable ' | ||
'will be removed in Django 2.0 (got %s). Pass the callable ' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. bad merge conflict resolution? 1.10->2.0 |
||
'instead.' % view, | ||
RemovedInDjango110Warning, stacklevel=2 | ||
) | ||
if not view: | ||
raise ImproperlyConfigured('Empty URL pattern view name not permitted (for pattern %r)' % regex) | ||
raise ImproperlyConfigured('Empty URL pattern view name not permitted (for pattern %r)' % constraints) | ||
if prefix: | ||
view = prefix + '.' + view | ||
return RegexURLPattern(regex, view, kwargs, name) | ||
return None, ResolverEndpoint(view, name, constraints=constraints, kwargs=kwargs, decorators=decorators) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The previous
if/elif
convertsconstraints
into either aRegexPattern
orLocalizedRegexPattern
but then immediately has to re-convert it into a list containing one of said objects. Would it make sense to have lines 100 & 103 both be wrapped into[]
?