X-Git-Url: https://git.tld-linux.org/?p=tld-builder.git;a=blobdiff_plain;f=TLD_Builder%2Fgpg.py;h=942cfb54947f1f40923d0fc8c3ce7a27603fd754;hp=b820dcdf3d4821ee7d3acd7edf47e4c26994e2f9;hb=9ea122b00e3a99b16246e1e38576916a2e25c0aa;hpb=b06ac0a74084c2ed513ecead310ea47208344d14 diff --git a/TLD_Builder/gpg.py b/TLD_Builder/gpg.py index b820dcd..942cfb5 100644 --- a/TLD_Builder/gpg.py +++ b/TLD_Builder/gpg.py @@ -4,11 +4,7 @@ import log import subprocess import re import sys -if sys.version_info[0] == 2: - import StringIO -else: - from io import StringIO - +from io import StringIO import util import os import pipeutil @@ -27,7 +23,7 @@ def get_keys(buf): cmd = ['/usr/bin/gpg', '--batch', '--no-tty', '--decrypt'] gpg_run = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) try: - d_stdout, d_stderr = gpg_run.communicate(buf.decode().encode('utf-8')) + d_stdout, d_stderr = gpg_run.communicate(util.to_bytes(buf)) except OSError as e: log.error("gnupg run, does gpg binary exist? : %s" % e) raise @@ -35,7 +31,7 @@ def get_keys(buf): rx = re.compile("^gpg:.*using\s[DR]SA\skey\s(?:ID\s)?(\w+)") keys = [] - for l in d_stderr.decode().split('\n'): + for l in util.to_str(d_stderr).split('\n'): m = rx.match(l) if m: keys.append(m.group(1)) @@ -59,14 +55,14 @@ def verify_sig(buf): cmd = ['/usr/bin/gpg', '--batch', '--no-tty', '--decrypt'] gpg_run = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) try: - d_stdout, d_stderr = gpg_run.communicate(buf.decode().encode('utf-8')) + d_stdout, d_stderr = gpg_run.communicate(util.to_bytes(buf)) except OSError as e: log.error("gnupg run failed, does gpg binary exist? : %s" % e) raise rx = re.compile("^gpg: (Good signature from| aka) .*<([^>]+)>") emails = [] - for l in d_stderr.decode().split('\n'): + for l in util.to_str(d_stderr).split('\n'): m = rx.match(l) if m: emails.append(m.group(2)) @@ -85,12 +81,12 @@ def sign(buf): # TODO: check for gpg return code! gpg_run = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, close_fds=True) try: - d_stdout, d_stderr = gpg_run.communicate(buf.decode().encode('utf-8')) + d_stdout, d_stderr = gpg_run.communicate(util.to_bytes(buf)) except OSError as e: log.error("gnupg signing failed, does gpg binary exist? : %s" % e) raise if len(d_stderr): - log.error("gpg: %s" % d_stderr.decode()) + log.error("gpg: %s" % util.to_str(d_stderr)) return d_stdout