emmett-framework / emmett

The web framework for inventors
BSD 3-Clause "New" or "Revised" License
1.06k stars 71 forks source link

Python 3.7 compat issue with re? #227

Closed gcmurphy closed 6 years ago

gcmurphy commented 6 years ago

The re module doesn't seem to like Python 3.7. This error happens on the most simple @app.route('/example').

python proxy.py
Traceback (most recent call last):
  File "/Users/grantmurphy/.local/share/virtualenvs/elastic_proxy-jpNTIbJ1/lib/python3.7/sre_parse.py", line 1021, in parse_template
    this = chr(ESCAPES[this][1])
KeyError: '\\d'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "proxy.py", line 22, in <module>
    @app.route(u'/sitemap')
  File "/Users/grantmurphy/.local/share/virtualenvs/elastic_proxy-jpNTIbJ1/lib/python3.7/site-packages/weppy/expose.py", line 188, in __call__
    routeobj = Route(self, path, idx)
  File "/Users/grantmurphy/.local/share/virtualenvs/elastic_proxy-jpNTIbJ1/lib/python3.7/site-packages/weppy/expose.py", line 295, in __init__
    self.schemes, self.hostname, self.methods, self.path)
  File "/Users/grantmurphy/.local/share/virtualenvs/elastic_proxy-jpNTIbJ1/lib/python3.7/site-packages/weppy/expose.py", line 115, in build_regex
    path = cls.REGEX_INT.sub('(?P<\g<1>>\d+)', path)
  File "/Users/grantmurphy/.local/share/virtualenvs/elastic_proxy-jpNTIbJ1/lib/python3.7/re.py", line 309, in _subx
    template = _compile_repl(template, pattern)
  File "/Users/grantmurphy/.local/share/virtualenvs/elastic_proxy-jpNTIbJ1/lib/python3.7/re.py", line 300, in _compile_repl
    return sre_parse.parse_template(repl, pattern)
  File "/Users/grantmurphy/.local/share/virtualenvs/elastic_proxy-jpNTIbJ1/lib/python3.7/sre_parse.py", line 1024, in parse_template
    raise s.error('bad escape %s' % this, len(this))
re.error: bad escape \d at position 10
(elastic_proxy-jpNTIbJ1) 

Managed to fix this by:

  1. pip install regex
  2. Adding import regex as re to the weppy/expose.py

There's more than likely a 'more correct' fix for this.

gi0baro commented 6 years ago

@gcmurphy oh. That sucks. I need to inspect what's changed in re module. This may take a while.

gi0baro commented 6 years ago

@gcmurphy current master should be fixed due to 244aab0

gcmurphy commented 6 years ago

Thanks.