summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Alejandro <ivanalejandro0@gmail.com>2013-11-11 16:24:28 -0300
committerIvan Alejandro <ivanalejandro0@gmail.com>2013-11-11 16:34:18 -0300
commit0f10209dafb330320df387e66a1cc9083a9ae755 (patch)
tree32e363c40f22f1c0a20bc31caf003430ed7bbfdc
parent9dfd2d68dbe02b222e4bb63f05c3d12d735154e4 (diff)
Use 'utf-8' as default/fallback encoding.
- Also reorder stdlib imports alphabetically :)
-rw-r--r--keymanager/changes/bug-4427_default-encoding-to-utf82
-rw-r--r--keymanager/src/leap/keymanager/openpgp.py8
2 files changed, 9 insertions, 1 deletions
diff --git a/keymanager/changes/bug-4427_default-encoding-to-utf8 b/keymanager/changes/bug-4427_default-encoding-to-utf8
new file mode 100644
index 0000000..3f7d671
--- /dev/null
+++ b/keymanager/changes/bug-4427_default-encoding-to-utf8
@@ -0,0 +1,2 @@
+ o Default encoding to 'utf-8' in case of system encodings not set. Closes
+ #4427.
diff --git a/keymanager/src/leap/keymanager/openpgp.py b/keymanager/src/leap/keymanager/openpgp.py
index a4dc1b8..1670e1c 100644
--- a/keymanager/src/leap/keymanager/openpgp.py
+++ b/keymanager/src/leap/keymanager/openpgp.py
@@ -21,12 +21,14 @@ Infrastructure for using OpenPGP keys in Key Manager.
"""
+import locale
import logging
import os
import re
import shutil
+import sys
import tempfile
-import locale
+
from contextlib import closing
from gnupg import GPG
@@ -516,6 +518,10 @@ class OpenPGPScheme(EncryptionScheme):
# https://github.com/isislovecruft/python-gnupg/\
# blob/master/gnupg/_meta.py#L121
encoding = locale.getpreferredencoding()
+ if encoding is None:
+ encoding = sys.stdin.encoding
+ if encoding is None:
+ encoding = 'utf-8'
return result.data.decode(encoding, 'replace')
def is_encrypted(self, data):