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.wait()
if p.returncode == 0:
return p.stdout.read().decode().strip()
return p.stdout.read().decode('utf-8', 'replace').strip()
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.close()
p.wait()
err = p.stdout.read().decode()
err += p.stderr.read().decode()
err = p.stdout.read().decode('utf-8', 'replace')
err += p.stderr.read().decode('utf-8', 'replace')
if p.returncode == 0:
if dest is not None:
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)
else:
shutil.move(temp, dest)
# Update modification time to reflect submission timestamp
os.utime(dest)
yield MailTest("Archive successfully extracted.", details=err)
yield dest
else:

View File

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

View File

@ -138,7 +138,7 @@ def parse(fd):
line = fd.readline()
context = {}
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:
keyword = res.group("keyword")
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:
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):
@ -128,4 +128,4 @@ def check_merged(bdata, GNUPG_DIRECTORY):
else:
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'))