From patchwork Mon Nov 9 03:36:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1396491 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=HH9mHJQ6; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CTxWz5JDjz9sRK for ; Mon, 9 Nov 2020 14:37:35 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id DEE2982535; Mon, 9 Nov 2020 04:36:43 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="HH9mHJQ6"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BD342824C4; Mon, 9 Nov 2020 04:36:36 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 6A2B88239B for ; Mon, 9 Nov 2020 04:36:28 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x142.google.com with SMTP id a20so6994887ilk.13 for ; Sun, 08 Nov 2020 19:36:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=eNCbptMH2jNRM9QNtNCUTUnBa8BmmZ2J8C+7I6bj77M=; b=HH9mHJQ6tsRONgWlAeKjTkjbKiq2crgys05AFpSIqttDXAO6fG+3kn3FLdWVQDmjxC OyJuMrh71QcBcOrURbYinRezMmXETp1fdgBDSVIGgMvfjMA46vHU9seZf6/wcTMnmOus RqCbMLN5FTCPJQ09VfeMB8kT7BRV0O9+a1Ct0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=eNCbptMH2jNRM9QNtNCUTUnBa8BmmZ2J8C+7I6bj77M=; b=OmT+tSWiVevLrRpbIxPTJqTE+/IXC9P6uLDPwef5DsjBKMX4bi2mTMaDFH/VA98RMa NRZLHq+zKJgFT2GGktHtcmkbgNxFhyaw6jRWfQ//jbjoJ6NNgyNWl4AfDb/O/q5DttSr VQDxNrDC7Q9+p/Q+yveNDwylqWrusexdWYTKLErLb+9qpCI3LH7Suk+o9m+fG8bkgOF9 XMpGbFIJKht80gj0z+j7WUDidr4uon0ZVRr+p5tgPvEkWQskG61NAEduM2O0iwJri7Zd MLXskE1aKNdzh477WyH9rHcnU/7AVnDXPPJgXJ740AoqNcxfvH8+ipf0DKxAkyxuGpi+ HkBw== X-Gm-Message-State: AOAM531WbLeZ8+k0AD7U4FfJDHjCLNLotethXKWkt8KiGOVxLVQ785+V lWizN3Q7ulyuSdlYQyabHJGZQYrvY0XN+w== X-Google-Smtp-Source: ABdhPJwEE0ewPZVjqXGoNjcMt7dJQG6l9m/WLSuxQhrkpeID1xjVEWmUAsBuUzd6OxXHD0MLV+Q22A== X-Received: by 2002:a05:6e02:80b:: with SMTP id u11mr306692ilm.290.1604892987255; Sun, 08 Nov 2020 19:36:27 -0800 (PST) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id e13sm6080868ili.67.2020.11.08.19.36.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Nov 2020 19:36:26 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Bin Meng , Walter Lozano Subject: [PATCH 2/5] patman: Drop unicode helper functions Date: Sun, 8 Nov 2020 20:36:18 -0700 Message-Id: <20201108203544.2.I14edc75f7d509655401981c521f068452970cce5@changeid> X-Mailer: git-send-email 2.29.2.222.g5d2a92d10f8-goog In-Reply-To: <20201109033621.1859598-1-sjg@chromium.org> References: <20201109033621.1859598-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean We don't need these now that everything uses Python 3. Remove them and the extra code in GetBytes() and ToBytes() too. Signed-off-by: Simon Glass Signed-off-by: Simon Glass --- tools/binman/etype/fmap.py | 2 +- tools/binman/fmap_util.py | 3 +-- tools/dtoc/dtb_platdata.py | 3 ++- tools/patman/func_test.py | 16 +++++-------- tools/patman/gitutil.py | 3 +-- tools/patman/series.py | 4 +--- tools/patman/settings.py | 5 ++-- tools/patman/tools.py | 47 +++----------------------------------- 8 files changed, 17 insertions(+), 66 deletions(-) diff --git a/tools/binman/etype/fmap.py b/tools/binman/etype/fmap.py index 3e9b815d119..fe81c6f64a5 100644 --- a/tools/binman/etype/fmap.py +++ b/tools/binman/etype/fmap.py @@ -52,7 +52,7 @@ class Entry_fmap(Entry): if pos is not None: pos -= entry.section.GetRootSkipAtStart() areas.append(fmap_util.FmapArea(pos or 0, entry.size or 0, - tools.FromUnicode(entry.name), 0)) + entry.name, 0)) entries = self.GetImage().GetEntries() areas = [] diff --git a/tools/binman/fmap_util.py b/tools/binman/fmap_util.py index 25fe60a9cc3..b03fc28fbb4 100644 --- a/tools/binman/fmap_util.py +++ b/tools/binman/fmap_util.py @@ -111,8 +111,7 @@ def EncodeFmap(image_size, name, areas): ConvertName(names, params) return struct.pack(fmt, *params) - values = FmapHeader(FMAP_SIGNATURE, 1, 0, 0, image_size, - tools.FromUnicode(name), len(areas)) + values = FmapHeader(FMAP_SIGNATURE, 1, 0, 0, image_size, name, len(areas)) blob = _FormatBlob(FMAP_HEADER_FORMAT, FMAP_HEADER_NAMES, values) for area in areas: blob += _FormatBlob(FMAP_AREA_FORMAT, FMAP_AREA_NAMES, area) diff --git a/tools/dtoc/dtb_platdata.py b/tools/dtoc/dtb_platdata.py index 7926fe3a792..ee98010423c 100644 --- a/tools/dtoc/dtb_platdata.py +++ b/tools/dtoc/dtb_platdata.py @@ -109,7 +109,8 @@ def get_value(ftype, value): if ftype == fdt.Type.INT: return '%#x' % fdt_util.fdt32_to_cpu(value) elif ftype == fdt.Type.BYTE: - return '%#x' % tools.ToByte(value[0]) + ch = value[0] + return '%#x' % ord(ch) if type(ch) == str else ch elif ftype == fdt.Type.STRING: # Handle evil ACPI backslashes by adding another backslash before them. # So "\\_SB.GPO0" in the device tree effectively stays like that in C diff --git a/tools/patman/func_test.py b/tools/patman/func_test.py index 810af9c6042..3a229be1ba8 100644 --- a/tools/patman/func_test.py +++ b/tools/patman/func_test.py @@ -199,17 +199,14 @@ class TestFunctional(unittest.TestCase): while 'Cc:' in lines[line]: line += 1 self.assertEqual('To: u-boot@lists.denx.de', lines[line]) - self.assertEqual('Cc: %s' % tools.FromUnicode(stefan), - lines[line + 1]) + self.assertEqual('Cc: %s' % stefan, lines[line + 1]) self.assertEqual('Version: 3', lines[line + 2]) self.assertEqual('Prefix:\t RFC', lines[line + 3]) self.assertEqual('Cover: 4 lines', lines[line + 4]) line += 5 self.assertEqual(' Cc: %s' % fred, lines[line + 0]) - self.assertEqual(' Cc: %s' % tools.FromUnicode(ed), - lines[line + 1]) - self.assertEqual(' Cc: %s' % tools.FromUnicode(mel), - lines[line + 2]) + self.assertEqual(' Cc: %s' % ed, lines[line + 1]) + self.assertEqual(' Cc: %s' % mel, lines[line + 2]) self.assertEqual(' Cc: %s' % rick, lines[line + 3]) expected = ('Git command: git send-email --annotate ' '--in-reply-to="%s" --to "u-boot@lists.denx.de" ' @@ -217,12 +214,11 @@ class TestFunctional(unittest.TestCase): % (in_reply_to, stefan, sys.argv[0], cc_file, cover_fname, ' '.join(args))) line += 4 - self.assertEqual(expected, tools.ToUnicode(lines[line])) + self.assertEqual(expected, lines[line]) - self.assertEqual(('%s %s\0%s' % (args[0], rick, stefan)), - tools.ToUnicode(cc_lines[0])) + self.assertEqual(('%s %s\0%s' % (args[0], rick, stefan)), cc_lines[0]) self.assertEqual(('%s %s\0%s\0%s\0%s' % (args[1], fred, ed, rick, - stefan)), tools.ToUnicode(cc_lines[1])) + stefan)), cc_lines[1]) expected = ''' This is a test of how the cover diff --git a/tools/patman/gitutil.py b/tools/patman/gitutil.py index 27a0a9fbc1f..1ac5a6aacda 100644 --- a/tools/patman/gitutil.py +++ b/tools/patman/gitutil.py @@ -379,7 +379,6 @@ def BuildEmailList(in_list, tag=None, alias=None, raise_on_error=True): raw += LookupEmail(item, alias, raise_on_error=raise_on_error) result = [] for item in raw: - item = tools.FromUnicode(item) if not item in result: result.append(item) if tag: @@ -490,7 +489,7 @@ def EmailPatches(series, cover_fname, args, dry_run, raise_on_error, cc_fname, if smtp_server: cmd.append('--smtp-server=%s' % smtp_server) if in_reply_to: - cmd.append('--in-reply-to="%s"' % tools.FromUnicode(in_reply_to)) + cmd.append('--in-reply-to="%s"' % in_reply_to) if thread: cmd.append('--thread') diff --git a/tools/patman/series.py b/tools/patman/series.py index 9f885c89873..76a21683e55 100644 --- a/tools/patman/series.py +++ b/tools/patman/series.py @@ -268,7 +268,6 @@ class Series(dict): for x in set(cc) & set(settings.bounces): print(col.Color(col.YELLOW, 'Skipping "%s"' % x)) cc = set(cc) - set(settings.bounces) - cc = [tools.FromUnicode(m) for m in cc] if limit is not None: cc = cc[:limit] all_ccs += cc @@ -277,11 +276,10 @@ class Series(dict): if cover_fname: cover_cc = gitutil.BuildEmailList(self.get('cover_cc', '')) - cover_cc = [tools.FromUnicode(m) for m in cover_cc] cover_cc = list(set(cover_cc + all_ccs)) if limit is not None: cover_cc = cover_cc[:limit] - cc_list = '\0'.join([tools.ToUnicode(x) for x in sorted(cover_cc)]) + cc_list = '\0'.join([x for x in sorted(cover_cc)]) print(cover_fname, cc_list, file=fd) fd.close() diff --git a/tools/patman/settings.py b/tools/patman/settings.py index 732bd401067..a8fb805793a 100644 --- a/tools/patman/settings.py +++ b/tools/patman/settings.py @@ -111,7 +111,7 @@ class _ProjectConfigParser(ConfigParser.SafeConfigParser): val = ConfigParser.SafeConfigParser.get( self, section, option, *args, **kwargs ) - return tools.ToUnicode(val) + return val def items(self, section, *args, **kwargs): """Extend SafeConfigParser to add project_section to section. @@ -146,8 +146,7 @@ class _ProjectConfigParser(ConfigParser.SafeConfigParser): item_dict = dict(top_items) item_dict.update(project_items) - return {(tools.ToUnicode(item), tools.ToUnicode(val)) - for item, val in item_dict.items()} + return {(item, val) for item, val in item_dict.items()} def ReadGitAliases(fname): """Read a git alias file. This is in the form used by git: diff --git a/tools/patman/tools.py b/tools/patman/tools.py index bbb157da873..55ba1e9c985 100644 --- a/tools/patman/tools.py +++ b/tools/patman/tools.py @@ -414,8 +414,6 @@ def WriteFile(fname, data, binary=True): def GetBytes(byte, size): """Get a string of bytes of a given size - This handles the unfortunate different between Python 2 and Python 2. - Args: byte: Numeric byte value to use size: Size of bytes/string to return @@ -423,43 +421,7 @@ def GetBytes(byte, size): Returns: A bytes type with 'byte' repeated 'size' times """ - if sys.version_info[0] >= 3: - data = bytes([byte]) * size - else: - data = chr(byte) * size - return data - -def ToUnicode(val): - """Make sure a value is a unicode string - - This allows some amount of compatibility between Python 2 and Python3. For - the former, it returns a unicode object. - - Args: - val: string or unicode object - - Returns: - unicode version of val - """ - if sys.version_info[0] >= 3: - return val - return val if isinstance(val, unicode) else val.decode('utf-8') - -def FromUnicode(val): - """Make sure a value is a non-unicode string - - This allows some amount of compatibility between Python 2 and Python3. For - the former, it converts a unicode object to a string. - - Args: - val: string or unicode object - - Returns: - non-unicode version of val - """ - if sys.version_info[0] >= 3: - return val - return val if isinstance(val, str) else val.encode('utf-8') + return bytes([byte]) * size def ToByte(ch): """Convert a character to an ASCII value @@ -506,12 +468,9 @@ def ToBytes(string): string: string to convert Returns: - Python 3: A bytes type - Python 2: A string type + A bytes type """ - if sys.version_info[0] >= 3: - return string.encode('utf-8') - return string + return string.encode('utf-8') def ToString(bval): """Convert a bytes type into a str type