Skip to content

Commit

Permalink
Fix global unicode/codecs monkey-patch
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
jannschu committed Oct 7, 2018
1 parent 7845714 commit a179dfa
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions pretty_bad_protocol/_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,6 @@ def __init__(self, binary=None, home=None, keyring=None, secring=None,
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')

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

0 comments on commit a179dfa

Please sign in to comment.