Skip to content

Commit 05ab473

Browse files
author
Gauvain Pocentek
committed
improve pretty_print()
1 parent 53562b3 commit 05ab473

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

gitlab.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,17 @@ def short_print(self, depth=0):
504504
self.shortPrintAttr.replace('_', '-'),
505505
self.__dict__[self.shortPrintAttr]))
506506

507+
@staticmethod
508+
def _obj_to_str(obj):
509+
if isinstance(obj, dict):
510+
s = ", ".join(["%s: %s" % (x, GitlabObject._obj_to_str(y)) for (x, y) in obj.items()])
511+
return "{ %s }" % s
512+
elif isinstance(obj, list):
513+
s = ", ".join([GitlabObject._obj_to_str(x) for x in obj])
514+
return "[ %s ]" %s
515+
else:
516+
return str(obj)
517+
507518
def pretty_print(self, depth=0):
508519
id = self.__dict__[self.idAttr]
509520
print("%s%s: %s" % (" " * depth * 2, self.idAttr, id))
@@ -521,6 +532,7 @@ def pretty_print(self, depth=0):
521532
else:
522533
if isinstance(v, Gitlab):
523534
continue
535+
v = GitlabObject._obj_to_str(v)
524536
print("%s%s: %s" % (" " * depth * 2, pretty_k, v))
525537

526538
def json(self):

0 commit comments

Comments
 (0)