From patchwork Thu Jan 10 23:23:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Pfaff X-Patchwork-Id: 1023273 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ovn.org Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 43bMX504CTz9s7h for ; Fri, 11 Jan 2019 10:24:21 +1100 (AEDT) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id DFBCA13A8; Thu, 10 Jan 2019 23:23:58 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 32DD113A5 for ; Thu, 10 Jan 2019 23:23:57 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 099BF823 for ; Thu, 10 Jan 2019 23:23:55 +0000 (UTC) X-Originating-IP: 208.91.3.26 Received: from sigabrt.benpfaff.org (unknown [208.91.3.26]) (Authenticated sender: blp@ovn.org) by relay3-d.mail.gandi.net (Postfix) with ESMTPSA id 4E67D60003; Thu, 10 Jan 2019 23:23:52 +0000 (UTC) From: Ben Pfaff To: dev@openvswitch.org Date: Thu, 10 Jan 2019 15:23:45 -0800 Message-Id: <20190110232347.6574-2-blp@ovn.org> X-Mailer: git-send-email 2.16.1 In-Reply-To: <20190110232347.6574-1-blp@ovn.org> References: <20190110232347.6574-1-blp@ovn.org> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Cc: Ben Pfaff Subject: [ovs-dev] [PATCH v2 1/3] python: Fix invalid escape sequences. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org It appears that Python silently treats invalid escape sequences in strings as literals, e.g. "\." is the same as "\\.". Newer versions of checkpatch complain, and it does seem reasonable to me to fix these. Signed-off-by: Ben Pfaff --- python/build/nroff.py | 4 ++-- python/ovs/db/schema.py | 2 +- python/ovs/json.py | 4 ++-- python/ovs/unixctl/__init__.py | 2 +- python/ovs/util.py | 2 +- python/ovs/vlog.py | 2 +- tests/test-ovsdb.py | 2 +- utilities/checkpatch.py | 24 ++++++++++++------------ utilities/ovs-dev.py | 2 +- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/python/build/nroff.py b/python/build/nroff.py index 73353061cccc..74a3f08ca40e 100644 --- a/python/build/nroff.py +++ b/python/build/nroff.py @@ -274,7 +274,7 @@ def diagram_to_nroff(nodes, para): text_s = '.br\n'.join(["\\fL%s\n" % s for s in text if s != ""]) return para + """ .\\" check if in troff mode (TTY) -.if t \{ +.if t \\{ .PS boxht = .2 textht = 1/6 @@ -283,7 +283,7 @@ fillval = .2 .PE \\} .\\" check if in nroff mode: -.if n \{ +.if n \\{ .nf """ + text_s + """\ .fi diff --git a/python/ovs/db/schema.py b/python/ovs/db/schema.py index 55c8ae7f3531..44b030757ef7 100644 --- a/python/ovs/db/schema.py +++ b/python/ovs/db/schema.py @@ -73,7 +73,7 @@ class DbSchema(object): parser.finish() if (version is not None and - not re.match('[0-9]+\.[0-9]+\.[0-9]+$', version)): + not re.match(r'[0-9]+\.[0-9]+\.[0-9]+$', version)): raise error.Error('schema version "%s" not in format x.y.z' % version) diff --git a/python/ovs/json.py b/python/ovs/json.py index e84063fc2ed1..94c8e30f365d 100644 --- a/python/ovs/json.py +++ b/python/ovs/json.py @@ -177,7 +177,7 @@ class Parser(object): return False __number_re = re.compile("(-)?(0|[1-9][0-9]*)" - "(?:\.([0-9]+))?(?:[eE]([-+]?[0-9]+))?$") + r"(?:\.([0-9]+))?(?:[eE]([-+]?[0-9]+))?$") def __lex_finish_number(self): s = self.buffer @@ -234,7 +234,7 @@ class Parser(object): self.__error("leading zeros not allowed") elif re.match("-([^0-9]|$)", s): self.__error("'-' must be followed by digit") - elif re.match("-?(0|[1-9][0-9]*)\.([^0-9]|$)", s): + elif re.match(r"-?(0|[1-9][0-9]*)\.([^0-9]|$)", s): self.__error("decimal point must be followed by digit") elif re.search("e[-+]?([^0-9]|$)", s): self.__error("exponent must contain at least one digit") diff --git a/python/ovs/unixctl/__init__.py b/python/ovs/unixctl/__init__.py index 025da2a90dac..c2e5aca8d6ff 100644 --- a/python/ovs/unixctl/__init__.py +++ b/python/ovs/unixctl/__init__.py @@ -73,7 +73,7 @@ def command_register(name, usage, min_args, max_args, callback, aux): def socket_name_from_target(target): assert isinstance(target, strtypes) - """ On Windows an absolute path contains ':' ( i.e: C:\ ) """ + """ On Windows an absolute path contains ':' ( i.e: C:\\ ) """ if target.startswith('/') or target.find(':') > -1: return 0, target diff --git a/python/ovs/util.py b/python/ovs/util.py index 411ac99c85a4..3dba022f8e27 100644 --- a/python/ovs/util.py +++ b/python/ovs/util.py @@ -31,7 +31,7 @@ def abs_file_name(dir_, file_name): This differs from os.path.abspath() in that it will never change the meaning of a file name. - On Windows an absolute path contains ':' ( i.e: C:\ ) """ + On Windows an absolute path contains ':' ( i.e: C:\\ ) """ if file_name.startswith('/') or file_name.find(':') > -1: return file_name else: diff --git a/python/ovs/vlog.py b/python/ovs/vlog.py index e3cf76dcd9e2..5b478fc541f7 100644 --- a/python/ovs/vlog.py +++ b/python/ovs/vlog.py @@ -142,7 +142,7 @@ class Vlog(object): return re.sub(match, replace, tmp) def _format_time(self, tmp): - date_regex = re.compile('(%(0?[1-9]?[dD])(\{(.*)\})?)') + date_regex = re.compile(r'(%(0?[1-9]?[dD])(\{(.*)\})?)') match = date_regex.search(tmp) if match is None: diff --git a/tests/test-ovsdb.py b/tests/test-ovsdb.py index c03476c7ffaf..01c1f379c5e7 100644 --- a/tests/test-ovsdb.py +++ b/tests/test-ovsdb.py @@ -167,7 +167,7 @@ def get_simple_printable_row_string(row, columns): s += "%s=%s " % (column, value) s = s.strip() s = re.sub('""|,|u?\'', "", s) - s = re.sub('UUID\(([^)]+)\)', r'\1', s) + s = re.sub(r'UUID\(([^)]+)\)', r'\1', s) s = re.sub('False', 'false', s) s = re.sub('True', 'true', s) s = re.sub(r'(ba)=([^[][^ ]*) ', r'\1=[\2] ', s) diff --git a/utilities/checkpatch.py b/utilities/checkpatch.py index 41676adab375..d8bd34b1f19b 100755 --- a/utilities/checkpatch.py +++ b/utilities/checkpatch.py @@ -518,38 +518,38 @@ checks = [ 'check': lambda x: trailing_whitespace_or_crlf(x), 'print': lambda: print_warning("Line has trailing whitespace")}, - {'regex': '(\.c|\.h)(\.in)?$', 'match_name': None, + {'regex': r'(\.c|\.h)(\.in)?$', 'match_name': None, 'prereq': lambda x: not is_comment_line(x), 'check': lambda x: not if_and_for_whitespace_checks(x), 'print': lambda: print_error("Improper whitespace around control block")}, - {'regex': '(\.c|\.h)(\.in)?$', 'match_name': None, + {'regex': r'(\.c|\.h)(\.in)?$', 'match_name': None, 'prereq': lambda x: not is_comment_line(x), 'check': lambda x: not if_and_for_end_with_bracket_check(x), 'print': lambda: print_error("Inappropriate bracing around statement")}, - {'regex': '(\.c|\.h)(\.in)?$', 'match_name': None, + {'regex': r'(\.c|\.h)(\.in)?$', 'match_name': None, 'prereq': lambda x: not is_comment_line(x), 'check': lambda x: pointer_whitespace_check(x), 'print': lambda: print_error("Inappropriate spacing in pointer declaration")}, - {'regex': '(\.c|\.h)(\.in)?$', 'match_name': None, + {'regex': r'(\.c|\.h)(\.in)?$', 'match_name': None, 'prereq': lambda x: not is_comment_line(x), 'check': lambda x: trailing_operator(x), 'print': lambda: print_error("Line has '?' or ':' operator at end of line")}, - {'regex': '(\.c|\.h)(\.in)?$', 'match_name': None, + {'regex': r'(\.c|\.h)(\.in)?$', 'match_name': None, 'prereq': lambda x: has_comment(x), 'check': lambda x: has_xxx_mark(x), 'print': lambda: print_warning("Comment with 'xxx' marker")}, - {'regex': '(\.c|\.h)(\.in)?$', 'match_name': None, + {'regex': r'(\.c|\.h)(\.in)?$', 'match_name': None, 'prereq': lambda x: has_comment(x), 'check': lambda x: check_comment_spelling(x)}, - {'regex': '(\.c|\.h)(\.in)?$', 'match_name': None, + {'regex': r'(\.c|\.h)(\.in)?$', 'match_name': None, 'check': lambda x: empty_return_with_brace(x), 'interim_line': True, 'print': @@ -584,7 +584,7 @@ std_functions = [ ('error', 'Use ovs_error() in place of error()'), ] checks += [ - {'regex': '(\.c|\.h)(\.in)?$', + {'regex': r'(\.c|\.h)(\.in)?$', 'match_name': None, 'prereq': lambda x: not is_comment_line(x), 'check': regex_function_factory(function_name), @@ -601,11 +601,11 @@ infix_operators = \ [re.escape(op) for op in ['%', '<<', '>>', '<=', '>=', '==', '!=', '^', '|', '&&', '||', '?:', '=', '+=', '-=', '*=', '/=', '%=', '&=', '^=', '|=', '<<=', '>>=']] \ - + ['[^<" ]<[^=" ]', '[^->" ]>[^=" ]', '[^ !()/"]\*[^/]', '[^ !&()"]&', - '[^" +(]\+[^"+;]', '[^" -(]-[^"->;]', '[^" <>=!^|+\-*/%&]=[^"=]', + + ['[^<" ]<[^=" ]', '[^->" ]>[^=" ]', r'[^ !()/"]\*[^/]', '[^ !&()"]&', + r'[^" +(]\+[^"+;]', '[^" -(]-[^"->;]', r'[^" <>=!^|+\-*/%&]=[^"=]', '[^* ]/[^* ]'] checks += [ - {'regex': '(\.c|\.h)(\.in)?$', 'match_name': None, + {'regex': r'(\.c|\.h)(\.in)?$', 'match_name': None, 'prereq': lambda x: not is_comment_line(x), 'check': regex_operator_factory(operator), 'print': lambda: print_warning("Line lacks whitespace around operator")} @@ -694,7 +694,7 @@ def ovs_checkpatch_parse(text, filename, author=None, committer=None): current_file = filename if checking_file else '' previous_file = '' seppatch = re.compile(r'^---([\w]*| \S+)$') - hunks = re.compile('^(---|\+\+\+) (\S+)') + hunks = re.compile(r'^(---|\+\+\+) (\S+)') hunk_differences = re.compile( r'^@@ ([0-9-+]+),([0-9-+]+) ([0-9-+]+),([0-9-+]+) @@') is_author = re.compile(r'^(Author|From): (.*)$', re.I | re.M | re.S) diff --git a/utilities/ovs-dev.py b/utilities/ovs-dev.py index 9ce0f04c7d8a..248d22ab9a7e 100755 --- a/utilities/ovs-dev.py +++ b/utilities/ovs-dev.py @@ -325,7 +325,7 @@ def modinst(): _sh("modprobe", "openvswitch") _sh("dmesg | grep openvswitch | tail -1") - _sh("find /lib/modules/%s/ -iname vport-*.ko -exec insmod '{}' \;" + _sh("find /lib/modules/%s/ -iname vport-*.ko -exec insmod '{}' \\;" % uname())