Don't fail on non-utf-8 chars

This commit is contained in:
nemunaire 2017-10-26 00:22:50 +02:00
parent 4d9ac08a89
commit 626353a02d
4 changed files with 9 additions and 7 deletions

View File

@ -66,7 +66,7 @@ def _guess_mime(data):
p.stdin.close() p.stdin.close()
p.wait() p.wait()
if p.returncode == 0: if p.returncode == 0:
return p.stdout.read().decode().strip() return p.stdout.read().decode('utf-8', 'replace').strip()
def guess_mime(cnt): def guess_mime(cnt):
@ -107,8 +107,8 @@ def extract(cnt, dest=None):
p.stdin.write(data.encode() if isinstance(data, str) else data) p.stdin.write(data.encode() if isinstance(data, str) else data)
p.stdin.close() p.stdin.close()
p.wait() p.wait()
err = p.stdout.read().decode() err = p.stdout.read().decode('utf-8', 'replace')
err += p.stderr.read().decode() err += p.stderr.read().decode('utf-8', 'replace')
if p.returncode == 0: if p.returncode == 0:
if dest is not None: if dest is not None:
nsub = len([x for x in os.listdir(odest) if x.find(os.path.basename(ldest) + ".") == 0]) + 1 nsub = len([x for x in os.listdir(odest) if x.find(os.path.basename(ldest) + ".") == 0]) + 1
@ -124,6 +124,8 @@ def extract(cnt, dest=None):
shutil.move(os.path.join(temp, os.listdir(temp)[0]), dest) shutil.move(os.path.join(temp, os.listdir(temp)[0]), dest)
else: else:
shutil.move(temp, dest) shutil.move(temp, dest)
# Update modification time to reflect submission timestamp
os.utime(dest)
yield MailTest("Archive successfully extracted.", details=err) yield MailTest("Archive successfully extracted.", details=err)
yield dest yield dest
else: else:

View File

@ -13,7 +13,7 @@ def import_pubkey(key, GNUPG_DIRECTORY):
p.stdin.write(key) p.stdin.write(key)
p.stdin.close() p.stdin.close()
p.wait() p.wait()
gpg_output = p.stderr.read().decode() gpg_output = p.stderr.read().decode("utf-8", "replace")
if p.returncode == 0: if p.returncode == 0:
yield MailTest("New PGP key successfully imported:", details=gpg_output) yield MailTest("New PGP key successfully imported:", details=gpg_output)
yield False yield False

View File

@ -138,7 +138,7 @@ def parse(fd):
line = fd.readline() line = fd.readline()
context = {} context = {}
while line: while line:
res = re.match(r"^\[GNUPG:\] (?P<keyword>\S+)(?: (?P<args>.*))?$", line.decode()) res = re.match(r"^\[GNUPG:\] (?P<keyword>\S+)(?: (?P<args>.*))?$", line.decode('utf-8', 'replace'))
if res is not None: if res is not None:
keyword = res.group("keyword") keyword = res.group("keyword")
args = res.group("args").split(" ") if res.group("args") is not None else [] args = res.group("args").split(" ") if res.group("args") is not None else []

View File

@ -85,7 +85,7 @@ def check_sep(data, sign, GNUPG_DIRECTORY):
finally: finally:
os.unlink(f.name) os.unlink(f.name)
yield from verify_sign(data, gpg_rcode, gpg_status, gpg_output.decode('utf-8')) yield from verify_sign(data, gpg_rcode, gpg_status, gpg_output.decode('utf-8', 'replace'))
def check_merged(bdata, GNUPG_DIRECTORY): def check_merged(bdata, GNUPG_DIRECTORY):
@ -128,4 +128,4 @@ def check_merged(bdata, GNUPG_DIRECTORY):
else: else:
bdata = None bdata = None
yield from verify_sign(bdata, gpg_rcode, gpg_status, gpg_output.decode('utf-8')) yield from verify_sign(bdata, gpg_rcode, gpg_status, gpg_output.decode('utf-8', 'replace'))