diff options
author | Crestez Dan Leonard <lcrestez@ixiacom.com> | 2014-07-28 20:43:34 +0300 |
---|---|---|
committer | Crestez Dan Leonard <lcrestez@ixiacom.com> | 2014-07-28 20:50:54 +0300 |
commit | e236fd94c48b949bbbc8e0dc2d55ebfaa1ef0069 (patch) | |
tree | a48c4d63c99ebc4a9a7dc315451c421103953ffe /gitlab.py | |
parent | 8ce3e30ba1fd3f9c587746dbe050a528bc6e952a (diff) | |
download | gitlab-e236fd94c48b949bbbc8e0dc2d55ebfaa1ef0069.tar.gz |
Fix encoding error when printing to redirected output
When redirecting output to a file sys.stdout.encoding is None, so use
sys.getdefaultencoding() instead.
Diffstat (limited to 'gitlab.py')
-rw-r--r-- | gitlab.py | 8 |
1 files changed, 5 insertions, 3 deletions
@@ -445,6 +445,8 @@ class Gitlab(object): """ return self._getListOrObject(Team, id, **kwargs) +def _get_display_encoding(): + return sys.stdout.encoding or sys.getdefaultencoding() class GitlabObject(object): _url = None @@ -574,7 +576,7 @@ class GitlabObject(object): s = ", ".join([GitlabObject._obj_to_str(x) for x in obj]) return "[ %s ]" % s elif isinstance(obj, unicode): - return obj.encode(sys.stdout.encoding, "replace") + return obj.encode(_get_display_encoding(), "replace") else: return str(obj) @@ -585,8 +587,8 @@ class GitlabObject(object): if k == self.idAttr: continue v = self.__dict__[k] - pretty_k = k.replace('_', '-').encode(sys.stdout.encoding, - "replace") + pretty_k = k.replace('_', '-') + pretty_k = pretty_k.encode(_get_display_encoding(), "replace") if isinstance(v, GitlabObject): if depth == 0: print("%s:" % pretty_k) |