Skip to content

Commit 64cead6

Browse files
author
Gauvain Pocentek
committed
Fix strings encoding (Closes #6)
1 parent ceda87a commit 64cead6

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
Version 0.4
2+
3+
* Fix strings encoding (Closes #6)
4+
15
Version 0.3
26

37
* Use PRIVATE-TOKEN header for passing the auth token

gitlab.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import json
2020
import requests
21+
import sys
2122

2223
__title__ = 'python-gitlab'
2324
__version__ = '0.3'
@@ -298,8 +299,10 @@ def update(self, obj):
298299
# build a dict of data that can really be sent to server
299300
d = {}
300301
for k, v in obj.__dict__.items():
301-
if type(v) in (int, str, unicode, bool):
302+
if type(v) in (int, str, bool):
302303
d[k] = str(v)
304+
elif type(v) == unicode:
305+
d[k] = str(v.encode(sys.stdout.encoding, "replace"))
303306

304307
try:
305308
r = requests.put(url, d, headers=self.headers, verify=self.ssl_verify)
@@ -520,6 +523,8 @@ def _obj_to_str(obj):
520523
elif isinstance(obj, list):
521524
s = ", ".join([GitlabObject._obj_to_str(x) for x in obj])
522525
return "[ %s ]" %s
526+
elif isinstance(obj, unicode):
527+
return obj.encode(sys.stdout.encoding, "replace")
523528
else:
524529
return str(obj)
525530

@@ -530,7 +535,7 @@ def pretty_print(self, depth=0):
530535
if k == self.idAttr:
531536
continue
532537
v = self.__dict__[k]
533-
pretty_k = k.replace('_', '-')
538+
pretty_k = k.replace('_', '-').encode(sys.stdout.encoding, "replace")
534539
if isinstance(v, GitlabObject):
535540
if depth == 0:
536541
print("%s:" % pretty_k)

0 commit comments

Comments
 (0)