Matches an arbitrary URL using a list of URL patterns from an application.
Each URL pattern has an associated URLDispatcher instance and path to the
resource's location on disk. See AddURL for more details. The first pattern
that matches an inputted URL will have its associated values returned by
Match().
def google.appengine.tools.old_dev_appserver.URLMatcher.AddURL |
( |
|
self, |
|
|
|
regex, |
|
|
|
dispatcher, |
|
|
|
path, |
|
|
|
requires_login, |
|
|
|
admin_only, |
|
|
|
auth_fail_action |
|
) |
| |
Adds a URL pattern to the list of patterns.
If the supplied regex starts with a '^' or ends with a '$' an
InvalidAppConfigError exception will be raised. Start and end symbols
and implicitly added to all regexes, meaning we assume that all regexes
consume all input from a URL.
Args:
regex: String containing the regular expression pattern.
dispatcher: Instance of URLDispatcher that should handle requests that
match this regex.
path: Path on disk for the resource. May contain back-references like
r'\1', r'\2', etc, which will be replaced by the corresponding groups
matched by the regex if present.
requires_login: True if the user must be logged-in before accessing this
URL; False if anyone can access this URL.
admin_only: True if the user must be a logged-in administrator to
access the URL; False if anyone can access the URL.
auth_fail_action: either appinfo.AUTH_FAIL_ACTION_REDIRECT (default)
which indicates that the server should redirect to the login page when
an authentication is needed, or appinfo.AUTH_FAIL_ACTION_UNAUTHORIZED
which indicates that the server should just return a 401 Unauthorized
message immediately.
Raises:
TypeError: if dispatcher is not a URLDispatcher sub-class instance.
InvalidAppConfigError: if regex isn't valid.
def google.appengine.tools.old_dev_appserver.URLMatcher.Match |
( |
|
self, |
|
|
|
relative_url, |
|
|
|
split_url = SplitURL |
|
) |
| |
Matches a URL from a request against the list of URL patterns.
The supplied relative_url may include the query string (i.e., the '?'
character and everything following).
Args:
relative_url: Relative URL being accessed in a request.
split_url: Used for dependency injection.
Returns:
Tuple (dispatcher, matched_path, requires_login, admin_only,
auth_fail_action), which are the corresponding values passed to
AddURL when the matching URL pattern was added to this matcher.
The matched_path will have back-references replaced using values
matched by the URL pattern. If no match was found, dispatcher will
be None.