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

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

@vrobertbaruch

Description

@vrobertbaruch

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'

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions