Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite236fd9

Browse files
committed
Fix encoding error when printing to redirected output
When redirecting output to a file sys.stdout.encoding is None, so usesys.getdefaultencoding() instead.
1 parent8ce3e30 commite236fd9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

‎gitlab.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,8 @@ def Team(self, id=None, **kwargs):
445445
"""
446446
returnself._getListOrObject(Team,id,**kwargs)
447447

448+
def_get_display_encoding():
449+
returnsys.stdout.encodingorsys.getdefaultencoding()
448450

449451
classGitlabObject(object):
450452
_url=None
@@ -574,7 +576,7 @@ def _obj_to_str(obj):
574576
s=", ".join([GitlabObject._obj_to_str(x)forxinobj])
575577
return"[ %s ]"%s
576578
elifisinstance(obj,unicode):
577-
returnobj.encode(sys.stdout.encoding,"replace")
579+
returnobj.encode(_get_display_encoding(),"replace")
578580
else:
579581
returnstr(obj)
580582

@@ -585,8 +587,8 @@ def pretty_print(self, depth=0):
585587
ifk==self.idAttr:
586588
continue
587589
v=self.__dict__[k]
588-
pretty_k=k.replace('_','-').encode(sys.stdout.encoding,
589-
"replace")
590+
pretty_k=k.replace('_','-')
591+
pretty_k=pretty_k.encode(_get_display_encoding(),"replace")
590592
ifisinstance(v,GitlabObject):
591593
ifdepth==0:
592594
print("%s:"%pretty_k)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp