mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Thomas Weißschuh" <linux@weissschuh.net>
To: Thomas Gleixner <tglx@linutronix.de>,
	Andrew Morton <akpm@linux-foundation.org>,
	Jonathan Corbet <corbet@lwn.net>, Joe Perches <joe@perches.com>,
	Jeremy Cline <jcline@redhat.com>,
	linux-kernel@vger.kernel.org
Cc: "Thomas Weißschuh" <linux@weissschuh.net>
Subject: [PATCH] scripts/spdxcheck.py: improve Python 3 compat
Date: Sun, 16 Sep 2018 23:12:41 +0200	[thread overview]
Message-ID: <20180916211241.7836-1-linux@weissschuh.net> (raw)

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 <linux@weissschuh.net>
---
 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, '-')
         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:
-- 
2.18.0


             reply	other threads:[~2018-09-16 21:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-09-16 21:12 Thomas Weißschuh [this message]
2018-09-17 15:40 ` Jeremy Cline

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180916211241.7836-1-linux@weissschuh.net \
    --to=linux@weissschuh.net \
    --cc=akpm@linux-foundation.org \
    --cc=corbet@lwn.net \
    --cc=jcline@redhat.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®