Skip to content

Commit a179dfa

Browse files
committed
Fix global unicode/codecs monkey-patch
This removes the monkey-patch from isislovecruft/python-gnupg@d9116ba and instead uses a local modification of the StreamReader by switching from ›strict‹ error handlers (the default) to ›replace‹ error handlers. This should resolve isislovecruft#219 and isislovecruft#49, as well as email attachments.
1 parent 7845714 commit a179dfa

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

pretty_bad_protocol/_meta.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,14 +212,6 @@ def __init__(self, binary=None, home=None, keyring=None, secring=None,
212212
self._filesystemencoding = encodings.normalize_encoding(
213213
sys.getfilesystemencoding().lower())
214214

215-
# Issue #49: https://github.com/isislovecruft/python-gnupg/issues/49
216-
#
217-
# During `line = stream.readline()` in `_read_response()`, the Python
218-
# codecs module will choke on Unicode data, so we globally monkeypatch
219-
# the "strict" error handler to use the builtin `replace_errors`
220-
# handler:
221-
codecs.register_error('strict', codecs.replace_errors)
222-
223215
self._keyserver = 'hkp://wwwkeys.pgp.net'
224216
self.__generated_keys = os.path.join(self.homedir, 'generated-keys')
225217

@@ -753,7 +745,8 @@ def _collect_output(self, process, result, writer=None, stdin=None):
753745
make sure it's joined before returning. If a stdin stream is given,
754746
close it before returning.
755747
"""
756-
stderr = codecs.getreader(self._encoding)(process.stderr)
748+
# Issue #49: https://github.com/isislovecruft/python-gnupg/issues/49
749+
stderr = codecs.getreader(self._encoding)(process.stderr, 'replace')
757750
rr = threading.Thread(target=self._read_response,
758751
args=(stderr, result))
759752
rr.setDaemon(True)

0 commit comments

Comments
 (0)