From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id B498D139694 for ; Wed, 22 Feb 2017 08:37:35 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id DF2D621C038; Wed, 22 Feb 2017 08:37:34 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id ACC5121C038 for ; Wed, 22 Feb 2017 08:37:34 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id A3D86341301 for ; Wed, 22 Feb 2017 08:37:33 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id A39065077 for ; Wed, 22 Feb 2017 08:37:31 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1487750904.3e82d2e09f124f3b77d1b913c945b93341ee4053.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: repoman/pym/repoman/modules/scan/ebuild/ X-VCS-Repository: proj/portage X-VCS-Files: repoman/pym/repoman/modules/scan/ebuild/checks.py X-VCS-Directories: repoman/pym/repoman/modules/scan/ebuild/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 3e82d2e09f124f3b77d1b913c945b93341ee4053 X-VCS-Branch: master Date: Wed, 22 Feb 2017 08:37:31 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 8d6b9cc6-62da-4ce2-8259-ef51f0d6858f X-Archives-Hash: 55d8919a7ae3385e76541269b8606259 commit: 3e82d2e09f124f3b77d1b913c945b93341ee4053 Author: Zac Medico gentoo org> AuthorDate: Wed Feb 22 00:17:37 2017 +0000 Commit: Zac Medico gentoo org> CommitDate: Wed Feb 22 08:08:24 2017 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=3e82d2e0 repoman: use regular expression to detect line continuations (bug 610414) Use a regular expression to detect line continuations, instead of the unicode_escape codec, since the unicode_escape codec is not really intended to be used this way. This solves an issue with python3.6, where a DeprecationWarning is triggered by ebuilds containing escape sequences, like this warning triggered by a sed expression in the dev-db/sqlite ebuilds: DeprecationWarning: invalid escape sequence '\[' X-Gentoo-Bug: 610414 X-Gentoo-Bug-Url: https://bugs.gentoo.org/show_bug.cgi?id=610414 Acked-by: Brian Dolbec gentoo.org> repoman/pym/repoman/modules/scan/ebuild/checks.py | 28 +++++++---------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/repoman/pym/repoman/modules/scan/ebuild/checks.py b/repoman/pym/repoman/modules/scan/ebuild/checks.py index 15e225156..d21bf0cb2 100644 --- a/repoman/pym/repoman/modules/scan/ebuild/checks.py +++ b/repoman/pym/repoman/modules/scan/ebuild/checks.py @@ -8,8 +8,8 @@ and correctness of an ebuild.""" from __future__ import unicode_literals -import codecs from itertools import chain +import operator import re import time @@ -923,11 +923,10 @@ def checks_init(experimental_inherit=False): _here_doc_re = re.compile(r'.*<<[-]?(\w+)\s*(>\s*\S+\s*)?$') _ignore_comment_re = re.compile(r'^\s*#') +_continuation_re = re.compile(r'(\\)*$') def run_checks(contents, pkg): - unicode_escape_codec = codecs.lookup('unicode_escape') - unicode_escape = lambda x: unicode_escape_codec.decode(x)[0] if _constant_checks is None: checks_init() checks = _constant_checks @@ -957,32 +956,21 @@ def run_checks(contents, pkg): # cow # This will merge these lines like so: # inherit foo bar moo cow - try: - # A normal line will end in the two bytes: <\> <\n>. So decoding - # that will result in python thinking the <\n> is being escaped - # and eat the single <\> which makes it hard for us to detect. - # Instead, strip the newline (which we know all lines have), and - # append a <0>. Then when python escapes it, if the line ended - # in a <\>, we'll end up with a <\0> marker to key off of. This - # shouldn't be a problem with any valid ebuild ... - line_escaped = unicode_escape(line.rstrip('\n') + '0') - except SystemExit: - raise - except: - # Who knows what kind of crazy crap an ebuild will have - # in it -- don't allow it to kill us. - line_escaped = line + # A line ending with an even number of backslashes does not count, + # because the last backslash is escaped. Therefore, search for an + # odd number of backslashes. + line_escaped = operator.sub(*_continuation_re.search(line).span()) % 2 == 1 if multiline: # Chop off the \ and \n bytes from the previous line. multiline = multiline[:-2] + line - if not line_escaped.endswith('\0'): + if not line_escaped: line = multiline num = multinum multiline = None else: continue else: - if line_escaped.endswith('\0'): + if line_escaped: multinum = num multiline = line continue