Replace UnicodeDecodeErrors caused by Python2 readline() method.

* CHANGE gnupg._meta.GPGBase.__init__() to register the builtin
   `codecs.replace_errors` handler and a global codecs "strict" error
   handler.
 * FIXES Issue #49:
   https://github.com/isislovecruft/python-gnupg/issues/49
fix/49-unicode-decode-on-readline
Isis Lovecruft 2014-10-28 01:01:03 +00:00
parent 79b1cbc260
commit d9116bace6
No known key found for this signature in database
GPG Key ID: 18C16EC5F9F1D673
1 changed files with 8 additions and 0 deletions

View File

@ -159,6 +159,14 @@ class GPGBase(object):
self._filesystemencoding = encodings.normalize_encoding(
sys.getfilesystemencoding().lower())
# Issue #49: https://github.com/isislovecruft/python-gnupg/issues/49
#
# During `line = stream.readline()` in `_read_response()`, the Python
# codecs module will choke on Unicode data, so we globally monkeypatch
# the "strict" error handler to use the builtin `replace_errors`
# handler:
codecs.register_error('strict', codecs.replace_errors)
self._keyserver = 'hkp://wwwkeys.pgp.net'
self.__generated_keys = os.path.join(self.homedir, 'generated-keys')