From f4aa4bc423206cd38f6a0da41881e3fbc451ddb4 Mon Sep 17 00:00:00 2001 From: Andrew Moffat Date: Tue, 19 Feb 2013 21:41:23 -0600 Subject: [PATCH] bugfix for unicode test cases on machine with ascii locale. changed default value of _decode_errors from "strict" to "replace". closes #123 --- CHANGELOG.md | 8 +++++++- sh.py | 5 +++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 071e4578..2e4bec54 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ * Added exit_code attribute to SignalException and ErrorReturnCode exception classes. + +* Bugfix where throwing an ErrorReturnCode exception that had unicode on + a system with ascii encoding would fail a test. [#123](https://github.com/amoffat/sh/issues/123) + +* Changed default value for `_decode_errors` from "strict" to "replace". [#123](https://github.com/amoffat/sh/issues/123) + ## 1.08 - 1/29/12 @@ -13,7 +19,7 @@ * Bugfix where CommandNotFound was not being raised if Command was created by instantiation. [#113](https://github.com/amoffat/sh/issues/113) -* Bugfix for Commands that are wrapped with functools.wraps() [#121](https://github.com/amoffat/sh/issues/121] +* Bugfix for Commands that are wrapped with functools.wraps() [#121](https://github.com/amoffat/sh/issues/121) * Bugfix where input arguments were being assumed as ascii or unicode, but never as a string in a different encoding. diff --git a/sh.py b/sh.py index b3668df0..eff4f28a 100644 --- a/sh.py +++ b/sh.py @@ -118,7 +118,8 @@ def __init__(self, full_cmd, stdout, stderr): tstderr += ("... (%d more, please see e.stderr)" % err_delta).encode() msg = "\n\n RAN: %r\n\n STDOUT:\n%s\n\n STDERR:\n%s" %\ - (full_cmd, tstdout.decode(DEFAULT_ENCODING), tstderr.decode(DEFAULT_ENCODING)) + (full_cmd, tstdout.decode(DEFAULT_ENCODING, "replace"), + tstderr.decode(DEFAULT_ENCODING, "replace")) super(ErrorReturnCode, self).__init__(msg) @@ -454,7 +455,7 @@ class Command(object): "tty_out": True, "encoding": DEFAULT_ENCODING, - "decode_errors": "strict", + "decode_errors": "replace", # how long the process should run before it is auto-killed "timeout": 0,