Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4132945imm; Mon, 17 Sep 2018 08:40:54 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYlBGr4VGtTcpYnzFpcUM4qWFcsirRowetNNaIPFz+JKkbmxwBse5pRIx1S3+FtqSa8dWKK X-Received: by 2002:a63:ed07:: with SMTP id d7-v6mr24318165pgi.429.1537198854024; Mon, 17 Sep 2018 08:40:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537198854; cv=none; d=google.com; s=arc-20160816; b=jzNQLff+x2LgZmlrFwiyA3ZLu8ri0GW8bRa0e2axjPfBHDEoXafDsyAgvNvOLEu8xb LBmxK2BPRBxfmb1PNSWbjnot33DxHhlmfP9NF/PHYZh8vOqoNHxGWd0xsPKMoXf4S4Ga ADaSt6XyrH5ER3CR4Owcx7JLJIy0Ty/Pbg7Xfkh+3IcXKLwhEPwb1qaPb6NvyaZJWQnL 9ri6v97GqnEV713C3aSAr2Mmz1meM9H8Ogrj3mZE4mYU1mmFOYQCU5rzjfHXE2o25kZY XJzJxMJH5tPcueC9jPoq0OEnAUEXDTjynqQryoWKE3caFG/+pxu/K/akmACWRG7fDCzF VMVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:to:subject; bh=WZATakcOap+awYFzt0+dqnWwZqXbwzqMuHmhbB75MHs=; b=HQNEK5SjHKv+cWt0dfzVKURWswMdhIT+DMyMt5Kp4TlPhAsdGmBT5Ud2vgprF1XFxf Yw7xN/YWtQFKOvsgpb7wZx1XNFRvgH6Pw/4cvqCwPB/MMPMptGEWo9lrSXEVgkt34+2p RVvr+7ElIOe10ktwjkkEgZOMDTsT5hsgm9i0UuqwXaT/bUIFG1Usm/kDuX89KLVwjUnM mrNpzXP5Te/pwZkp1s6gpqeafC6L8mDKHYXUJZ5LcGxaguQHE7+FaQ8BXfeVLHSQeQK/ uw5c0pR74CJk2nYZGuHM9IppbBoS1iEycqGGoDHwGo9PCvx3VrBPszGL4hsES04izk4H GCVw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y25-v6si16331009pga.39.2018.09.17.08.40.38; Mon, 17 Sep 2018 08:40:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729300AbeIQVI1 (ORCPT + 99 others); Mon, 17 Sep 2018 17:08:27 -0400 Received: from mail-qt0-f181.google.com ([209.85.216.181]:33576 "EHLO mail-qt0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728542AbeIQVI1 (ORCPT ); Mon, 17 Sep 2018 17:08:27 -0400 Received: by mail-qt0-f181.google.com with SMTP id r37-v6so15713857qtc.0 for ; Mon, 17 Sep 2018 08:40:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:openpgp:autocrypt :message-id:date:user-agent:mime-version:in-reply-to :content-language:content-transfer-encoding; bh=WZATakcOap+awYFzt0+dqnWwZqXbwzqMuHmhbB75MHs=; b=nineCanApZ0ByExGoDMNiZ4X8iMGZYiYsp2VHsGjjJOhiYkbo7x4jmRn8Z9CO7SMWD 3XJcjWzh9XOnV7GpvT2tjOW6gJdWPYzvY4T6iPlW4gafpRy+gNU/Qzs8DG98Zs8Z9rYe ItnydpSAhgkOAGhoUAkiGMrsKufyLTKBqH/GfiEgODqRVoPFVMZ9qHr/roOe32kTwUub q1hHpe2XGsb+3+AIhERRVOnGzmm1wG2rbIvhWhdZOC/rDx6/5aTCWbZqxTwsXvPf6QCO 9M6/CXe7NjOq6nNss+Em4F8yvrNm/U8kNp4CDSU+TpZadqMESIFEVVw7hcItbRwRE68u kJqw== X-Gm-Message-State: APzg51DUHcVm/W2sQ0wdPFYrhLrNrUljuKhWASwgcOp7Ib0wGUc3g16/ tt5c71jR2aaHqeEMmsCPrm1ZYRTfKd0= X-Received: by 2002:a0c:bf09:: with SMTP id m9-v6mr18062990qvi.2.1537198833323; Mon, 17 Sep 2018 08:40:33 -0700 (PDT) Received: from laptop.jcline.org ([66.187.232.65]) by smtp.gmail.com with ESMTPSA id p4-v6sm10915658qkl.41.2018.09.17.08.40.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 17 Sep 2018 08:40:32 -0700 (PDT) Subject: Re: [PATCH] scripts/spdxcheck.py: improve Python 3 compat To: =?UTF-8?Q?Thomas_Wei=c3=9fschuh?= , Thomas Gleixner , Andrew Morton , Jonathan Corbet , Joe Perches , linux-kernel@vger.kernel.org References: <20180916211241.7836-1-linux@weissschuh.net> From: Jeremy Cline Openpgp: preference=signencrypt Autocrypt: addr=jcline@redhat.com; keydata= xsFNBFThCPYBEACx9hl05pMfpVKVjm8Yrmd2I3sm9Jw7EIGfn1tmncSnzfveN7UcIjYI23Gw DE11Hf70tMZKXhNmQqDqoftEDwLbTuzBdgJXFZmfEwrcQHGiR5CZ4IQ3U7SF0a701lyYtuNs WndEO8CCaWHUYybiEl1yRZhwyzAA1j/izilD7FckOaEsTM1sFVDs74qWsNGIdJXYQ5dz/iV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AAKCRDGyJ0h8ZTGQi1bD/wMbSCnreanQFYTTgzC 6i/dtsWrd3DvJzaxKdUrSjioP1tK6YLpS7SSc5khYUjVp7xdsu9vCazsLspzBYbQOV02xtI5 CTLwMzh4hYE1/66K899++0v2dP9m9DEKu/R4vqW4axTfWIbR/ygd1bh2a/7NpAT6qiJg8vha Qkf/fVKZ9xM7EDHmfFJscqC6JyYNdYvz8wJ0aa9Z6zvnNUzjAntj62kJV8b8m5diUQDUI8dp r9crk+XxOTNpYid6p8mlNTcX54LTy1eEL7BYG1S3ezcLZC9/78MTdTJbxQMz7/zQXOABfMDy +otLuhEBxi5hl+COIsiRotTOBNPNr1UmV4fQjXz2K6cfgaO/9NilQaEU6zpsMcAOi5lLxlzD GRyPO2a0QQFZ7FmH9dRWw/6mmspQMBNRr5CrQdIBiWDcJGNPl8iX9TqwP62dZgwANT6+FR7K If4axm/gJQMSUCon3eLJhi8b5qZp4vZn7Xj4hCswrO9eExmT9IjpRVcHLYti36m99WRvItDy dVvrvIQi5qah3PrQjtwSJ61ExSZTOpBQGC60yQf+GG0TISIeeXX8CK2e1PIDt7/l+d0onCmU /98IQsNgR/9sifmdPeh3nKsxe2vsa3HNeElQU2ko6ZHMrE0gSyel5vaqRLQQwekBx1mr/7Ll X/87hZ4pdW/aOXUAgQ== Message-ID: <09f9d069-d82f-5ce5-d8c6-f9d691e630fb@redhat.com> Date: Mon, 17 Sep 2018 11:40:31 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: <20180916211241.7836-1-linux@weissschuh.net> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 09/16/2018 05:12 PM, Thomas Weißschuh wrote: > When reading lines from a text-mode fd strings are returned. > These can not be decoded again into strings, breaking the logic in > parser. > Just make sure all files are opened in binary mode on Python 3, so the > current logic keeps working. > > This remains compatible with Python 2 and should have no functional > change. > > Signed-off-by: Thomas Weißschuh > --- > scripts/spdxcheck.py | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/scripts/spdxcheck.py b/scripts/spdxcheck.py > index 839e190bbd7a..8f472f995d70 100755 > --- a/scripts/spdxcheck.py > +++ b/scripts/spdxcheck.py > @@ -250,12 +250,15 @@ if __name__ == '__main__': > > try: > if len(args.path) and args.path[0] == '-': > - parser.parse_lines(sys.stdin, args.maxlines, '-') > + parser.parse_lines( > + # always get the binary fd > + getattr(sys.stdin, 'buffer', sys.stdin), > + args.maxlines, '-') I think a slightly more "Pythonic" way to do this would be: try: parser.parse_lines(sys.stdin.buffer, args.maxlines, '-') except AttributeError: # Python 2 doesn't have a binary buffer interface on stdin parser.parse_lines(sys.stdin, args.maxlines, '-') but they're equivalent so it's completely personal preference. > else: > if args.path: > for p in args.path: > if os.path.isfile(p): > - parser.parse_lines(open(p), args.maxlines, p) > + parser.parse_lines(open(p, 'rb'), args.maxlines, p) > elif os.path.isdir(p): > scan_git_subtree(repo.head.reference.commit.tree, p) > else: > For what it's worth: Reviewed-by: Jeremy Cline