adds a nicer __repr__

This commit is contained in:
Jannis Gebauer
2016-09-08 10:25:48 +02:00
parent 676f13bfa5
commit 8571d87c77
88 changed files with 322 additions and 1 deletions
+20 -1
View File
@@ -24,12 +24,15 @@
# along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
# #
# ##############################################################################
import sys
import datetime
from operator import itemgetter
import GithubException
import Consts
atLeastPython3 = sys.hexversion >= 0x03000000
class _NotSetType:
def __repr__(self):
@@ -207,6 +210,22 @@ class GithubObject(object):
'''
return self._headers.get(Consts.RES_LAST_MODIFED)
def get__repr__(self, params):
"""
Converts the object to a nicely printable string.
"""
def format_params(params):
if atLeastPython3:
items = params.items()
else:
items = list(params.items())
for k, v in sorted(items, key=itemgetter(1)):
yield '{k}="{v}"'.format(k=k, v=v) if isinstance(v, (str, unicode)) else '{k}={v}'.format(k=k, v=v)
return '{class_name}({params})'.format(
class_name=self.__class__.__name__,
params=", ".join(list(format_params(params)))
)
class NonCompletableGithubObject(GithubObject):
def _completeIfNeeded(self):