From 64e40a0a80c26ad3438f419e193c1314be7dc6e1 Mon Sep 17 00:00:00 2001 From: Vincent Le Gallic Date: Wed, 29 Jan 2014 00:31:55 +0100 Subject: [PATCH] =?UTF-8?q?[client]=20On=20ne=20crashe=20pas=20lamentablem?= =?UTF-8?q?ent=20=C3=A0=20cause=20des=20allemands?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit La doc de GPG prétend que --with-colons output de l'UTF-8 regardless of any --display-charset. Eh bah c'est faux. Je provide même un working example : gpg --list-key --with-colons 095D9EC8C995AB203DC260FEECAA37C45C7E48CE --- client.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/client.py b/client.py index 81ed7f3..eb79567 100755 --- a/client.py +++ b/client.py @@ -92,6 +92,8 @@ def gpg(options, command, args=None): else: stderr = subprocess.PIPE full_command.extend(['--debug-level=1']) + if options.verbose: + print(" ".join(full_command)) proc = subprocess.Popen(full_command, stdin = subprocess.PIPE, stdout = subprocess.PIPE, @@ -171,7 +173,15 @@ def parse_keys(gpgout, debug=False): current_sub = init_value for line in iter(gpgout.readline, ''): # La doc dit que l'output est en UTF-8 «regardless of any --display-charset setting» - line = line.decode("utf-8") + try: + line = line.decode("utf-8") + except UnicodeDecodeError: + try: + line = line.decode("iso8859-1") + except UnicodeDecodeError: + line = line.decode("iso8859-1", "ignore") + if not options.quiet: + print("gpg raconte de la merde, c'est ni de l'ISO-8859-1 ni de l'UTF-8, je droppe, ça risque de foirer plus tard.", sys.stderr) line = line.split(":") field = line[0] if field in GPG_PARSERS.keys():