routes.py Python 3 regex error

87 views
Skip to first unread message

Bryan Chance

unread,
Sep 28, 2018, 1:20:19 PM9/28/18
to web2py-users
I'm working to switch my web2py application to Python 3. However, I now get errors when loading due to my routes.py:

  File "/usr/lib/python3.6/sre_parse.py", line 401, in _escape
    raise source.error("bad escape %s" % escape, len(escape))
sre_constants.error: bad escape \g at position 35


My routes.py is posted below, and the idea behind it is that myurl.com/client_name gets routed to myurl.com/myappname?client=client_name:

routes_app = ((r'/(?P<app>admin|app)\b.*', r'\\g<app>'),
              (
              r'/(?P<app>app_to_be_excluded)\b.*',
              r'\g<app>')
              )

routes_in = [
    # make sure you do not break admin
    ('/admin', '/admin'),
    ('/admin/$anything', '/admin/$anything'),
    # make sure you do not break appadmin
    ('/$app/appadmin', '/$app/appadmin'),
    ('/$app/appadmin/$anything', '/$app/appadmin/$anything'),
    ('/static/$anything', '/myappname/static/$anything'),
    ('/$domain(?P<rest>.*)$', '/myappname\\g<rest>?client=$domain'),
]

routes_out = [(a, b) for (b, a) in routes_in]

Does anyone have any ideas how I can update this regex to work?

Bryan Chance

unread,
Sep 28, 2018, 1:23:39 PM9/28/18
to web...@googlegroups.com
one correction, the \\g's are actually \g

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Leonel Câmara

unread,
Sep 28, 2018, 1:32:16 PM9/28/18
to web2py-users
You probably need to use raw strings in routes_in too if that \\g is indeed just \g

Bryan Chance

unread,
Sep 28, 2018, 2:29:14 PM9/28/18
to web...@googlegroups.com
Added those, but the underlying issue is still there.

On Fri, Sep 28, 2018 at 12:32 PM Leonel Câmara <leonel...@gmail.com> wrote:
You probably need to use raw strings in routes_in too if that \\g is indeed just \g

--
Reply all
Reply to author
Forward
0 new messages