Merge remote-tracking branch 'ivan/bug/4000_support-non-ascii' into develop
authorTomás Touceda <chiiph@leap.se>
Wed, 23 Oct 2013 14:30:05 +0000 (11:30 -0300)
committerTomás Touceda <chiiph@leap.se>
Wed, 23 Oct 2013 14:30:05 +0000 (11:30 -0300)
changes/bug-4000_suport-non-ascii [new file with mode: 0644]
src/leap/keymanager/openpgp.py

diff --git a/changes/bug-4000_suport-non-ascii b/changes/bug-4000_suport-non-ascii
new file mode 100644 (file)
index 0000000..cb1b78f
--- /dev/null
@@ -0,0 +1 @@
+  o Return unicode decrypted text to avoid encoding issues. Related to #4000.
index 6412331..8ec8639 100644 (file)
@@ -26,6 +26,7 @@ import os
 import re
 import shutil
 import tempfile
+import locale
 
 from gnupg import GPG
 from gnupg.gnupg import GPGUtilities
@@ -482,7 +483,7 @@ class OpenPGPScheme(EncryptionScheme):
         :type verify: OpenPGPKey
 
         :return: The decrypted data.
-        :rtype: str
+        :rtype: unicode
 
         @raise InvalidSignature: Raised if unable to verify the signature with
             C{verify} key.
@@ -504,7 +505,12 @@ class OpenPGPScheme(EncryptionScheme):
                     raise errors.InvalidSignature(
                         'Failed to verify signature with key %s: %s' %
                         (verify.key_id, stderr))
-            return result.data
+
+            # XXX: this is the encoding used by gpg module
+            # https://github.com/isislovecruft/python-gnupg/\
+            #   blob/master/gnupg/_meta.py#L121
+            encoding = locale.getpreferredencoding()
+            return result.data.decode(encoding, 'replace')
 
     def is_encrypted(self, data):
         """