On 2019/10/04 23:24, Stuart Henderson wrote:
> Sending this port out now as there was some interest in arouteserver, I
> haven't got it working yet though and won't have time to look at it much
> for a few days (and then I doubt I know enough of Python to figure it out).
So it turns out this is from the code where it substitutes ${FOO} with the
contents of the environment variable FOO (this was added in
https://github.com/pierky/arouteserver/commit/a184b428)
def expand_env_vars(doc):
res = doc
for v in os.environ:
res = re.sub("\$\{" + v + "\}", os.environ[v], res)
res = re.sub("\$\{[A-Za-z0-9_]+\}", "", res)
return res
if the environment contains e.g.
PS1=<\u@\h:\w:!>\$
then this triggers the bug:
> :Traceback (most recent call last):
> : File "/usr/local/lib/python3.7/sre_parse.py", line 1021, in parse_template
> : this = chr(ESCAPES[this][1])
> :KeyError: '\\u'
> :
> :During handling of the above exception, another exception occurred:
> :
> :Traceback (most recent call last):
> : File "/usr/local/bin/arouteserver", line 64, in <module>
> : if main():
> : File "/usr/local/bin/arouteserver", line 53, in main
> : return cmd.run()
> : File "/usr/local/lib/python3.7/site-packages/pierky/arouteserver/commands/tpl_rendering.py", line 175, in run
> : builder = builder_class(**self.cfg_builder_params)
> : File "/usr/local/lib/python3.7/site-packages/pierky/arouteserver/builder.py", line 390, in __init__
> : "general")
> : File "/usr/local/lib/python3.7/site-packages/pierky/arouteserver/builder.py", line 104, in _get_cfg
> : obj.load(path)
> : File "/usr/local/lib/python3.7/site-packages/pierky/arouteserver/config/base.py", line 114, in load
> : self._load_from_yaml_file(cfg_path)
> : File "/usr/local/lib/python3.7/site-packages/pierky/arouteserver/config/base.py", line 111, in _load_from_yaml_file
> : self._load_from_yaml(f.read())
> : File "/usr/local/lib/python3.7/site-packages/pierky/arouteserver/config/base.py", line 87, in _load_from_yaml
> : expanded_doc = expand_env_vars(expanded_doc)
> : File "/usr/local/lib/python3.7/site-packages/pierky/arouteserver/config/base.py", line 81, in expand_env_vars
> : res = re.sub("\$\{" + v + "\}", os.environ[v], res)
> : File "/usr/local/lib/python3.7/re.py", line 192, in sub
> : return _compile(pattern, flags).sub(repl, string, count)
> : File "/usr/local/lib/python3.7/re.py", line 309, in _subx
> : template = _compile_repl(template, pattern)
> : File "/usr/local/lib/python3.7/re.py", line 300, in _compile_repl
> : return sre_parse.parse_template(repl, pattern)
> : File "/usr/local/lib/python3.7/sre_parse.py", line 1024, in parse_template
> : raise s.error('bad escape %s' % this, len(this))
> :re.error: bad escape \u at position 1
Python people - do you have any suggestions how to deal with this please?
No comments:
Post a Comment