Browse Source

Don't fail on non-utf-8 chars

master
nemunaire 5 years ago
parent
commit
626353a02d
  1. 8
      archive.py
  2. 2
      envelope.py
  3. 2
      gpg_status_parser.py
  4. 4
      signature.py

8
archive.py

@ -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:

2
envelope.py

@ -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

2
gpg_status_parser.py

@ -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 []

4
signature.py

@ -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'))

Loading…
Cancel
Save