Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Docs for webapp2.Router.__init__() and add() misleading #135

Open
vrobertbaruch opened this issue May 18, 2018 · 1 comment
Open

Docs for webapp2.Router.__init__() and add() misleading #135

vrobertbaruch opened this issue May 18, 2018 · 1 comment

Comments

@vrobertbaruch
Copy link

The docs for webapp2.Router.__init__() and add() are misleading:

Parameters: | routes – A sequence of Route instances or, for simple routes, tuples (regex, handler).

In fact, a simple route tuple is of the form (template, handler). It does not take a regex, as in something returned by re.compile().

The documentation for simple route is also misleading:

The simplest form of URI route in webapp2 is a tuple (regex, handler), where regex is a regular expression to match the requested URI path and handler is a callable to handle the request.

This is not true. regex is, in fact, a template, not a Python regex.

This is what happens if you try to use a Python regex as the regex part of the tuple:

Traceback (most recent call last):
  File "/base/alloc/tmpfs/dynamic_runtimes/python27/277b61042b697c7a_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 267, in Handle
    result = handler(dict(self._environ), self._StartResponse)
  File "/base/alloc/tmpfs/dynamic_runtimes/python27/277b61042b697c7a_unzipped/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1519, in __call__
    response = self._internal_error(e)
  File "/base/alloc/tmpfs/dynamic_runtimes/python27/277b61042b697c7a_unzipped/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1511, in __call__
    rv = self.handle_exception(request, response, e)
  File "/base/alloc/tmpfs/dynamic_runtimes/python27/277b61042b697c7a_unzipped/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1505, in __call__
    rv = self.router.dispatch(request, response)
  File "/base/alloc/tmpfs/dynamic_runtimes/python27/277b61042b697c7a_unzipped/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1240, in default_dispatcher
    route, args, kwargs = rv = self.match(request)
  File "/base/alloc/tmpfs/dynamic_runtimes/python27/277b61042b697c7a_unzipped/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 1180, in default_matcher
    match = route.match(request)
  File "/base/alloc/tmpfs/dynamic_runtimes/python27/277b61042b697c7a_unzipped/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 825, in match
    match = self.regex.match(urllib.unquote(request.path))
  File "/base/alloc/tmpfs/dynamic_runtimes/python27/277b61042b697c7a_unzipped/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 701, in __get__
    value = self.func(obj)
  File "/base/alloc/tmpfs/dynamic_runtimes/python27/277b61042b697c7a_unzipped/python27_lib/versions/third_party/webapp2-2.3/webapp2.py", line 812, in regex
    if not self.template.startswith('^'):
AttributeError: '_sre.SRE_Pattern' object has no attribute 'startswith'
@theacodes
Copy link
Contributor

Thanks for filing @vrobertbaruch! This project is completely community supported, so if you want to see this fixed please send a pull request!

@GoogleCloudPlatform GoogleCloudPlatform deleted a comment from user2589 Oct 9, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants