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

Commit8d65870

Browse files
author
Gauvain Pocentek
committed
add a json() method to GitlabObject's
1 parent1625e55 commit8d65870

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
@@ -16,6 +16,7 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818

19+
importjson
1920
importrequests
2021

2122
__title__='python-gitlab'
@@ -26,6 +27,14 @@
2627
__copyright__='Copyright 2013 Gauvain Pocentek'
2728

2829

30+
classjsonEncoder(json.JSONEncoder):
31+
defdefault(self,obj):
32+
ifisinstance(obj,GitlabObject):
33+
returnobj.__dict__
34+
elifisinstance(obj,Gitlab):
35+
return {'url':obj._url}
36+
returnjson.JSONEncoder.default(self,obj)
37+
2938
classGitlabConnectionError(Exception):
3039
pass
3140

@@ -421,6 +430,9 @@ def __init__(self, gl, data=None, **kwargs):
421430
def__str__(self):
422431
return'%s => %s'% (type(self),str(self.__dict__))
423432

433+
defjson(self):
434+
returnjson.dumps(self.__dict__,cls=jsonEncoder)
435+
424436

425437
classUser(GitlabObject):
426438
_url='/users'

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp