[ovs-git] [openvswitch/ovs] 716935: python: Escape backslashes while formatting logs.

GitHub noreply at github.com
Tue Jan 15 17:12:34 UTC 2019


  Branch: refs/heads/branch-2.10
  Home:   https://github.com/openvswitch/ovs
  Commit: 7169350a010073ab8428b33bef34734820ab7f2a
      https://github.com/openvswitch/ovs/commit/7169350a010073ab8428b33bef34734820ab7f2a
  Author: Ilya Maximets <i.maximets at samsung.com>
  Date:   2019-01-15 (Tue, 15 Jan 2019)

  Changed paths:
    M python/ovs/vlog.py

  Log Message:
  -----------
  python: Escape backslashes while formatting logs.

Since python version 3.7 (and some 3.6+ versions) regexp engine
changed to treat the wrong escape sequences as errors. Previously,
if the replace string had something like '\u0000', '\u' was
qualified as a bad escape sequence and treated just as a sequence
of characters '\' and 'u'. But know this triggers an error:

  Traceback (most recent call last):
    File "/usr/lib/python3.7/sre_parse.py", line 1021, in parse_template
      this = chr(ESCAPES[this][1])
  KeyError: '\\u'

>From the documentation [1]:

  Unknown escapes consisting of '\' and an ASCII letter in replacement
  templates for re.sub() were deprecated in Python 3.5, and will now
  cause an error.

[1] https://docs.python.org/3/whatsnew/3.7.html#api-and-feature-removals

We need to escape the backslash by another one to keep regexp engine
from errors. In case of '\\u000', '\\' is a valid escape sequence
and the 'u' is a simple character.

To be 100% safe we need to use 're.escape(replace)', but it escapes
too many characters making the logs hard to read.

This change fixes Python 3 tests on systems with python 3.7.
Should be backward compatible.

Reported-by: Ben Pfaff <blp at ovn.org>
Signed-off-by: Ilya Maximets <i.maximets at samsung.com>
Signed-off-by: Ben Pfaff <blp at ovn.org>



      **NOTE:** This service has been marked for deprecation: https://developer.github.com/changes/2018-04-25-github-services-deprecation/

      Functionality will be removed from GitHub.com on January 31st, 2019.


More information about the git mailing list