@@ -384,12 +384,6 @@ def update(self, obj):
384
384
else :
385
385
raise GitlabUpdateError ('%d: %s' % (r .status_code , r .text ))
386
386
387
- def _getListOrObject (self , cls , id , ** kwargs ):
388
- if id is None :
389
- return cls .list (self , ** kwargs )
390
- else :
391
- return cls (self , id , ** kwargs )
392
-
393
387
def Hook (self , id = None , ** kwargs ):
394
388
"""Creates/tests/lists system hook(s) known by the GitLab server.
395
389
@@ -401,7 +395,7 @@ def Hook(self, id=None, **kwargs):
401
395
object is NOT saved on the server. Use the save() method on the object
402
396
to write it on the server.
403
397
"""
404
- return self ._getListOrObject (Hook , id , ** kwargs )
398
+ return Hook ._getListOrObject (self , id , ** kwargs )
405
399
406
400
def Project (self , id = None , ** kwargs ):
407
401
"""Creates/gets/lists project(s) known by the GitLab server.
@@ -415,14 +409,14 @@ def Project(self, id=None, **kwargs):
415
409
object is NOT saved on the server. Use the save() method on the object
416
410
to write it on the server.
417
411
"""
418
- return self ._getListOrObject (Project , id , ** kwargs )
412
+ return Project ._getListOrObject (self , id , ** kwargs )
419
413
420
414
def UserProject (self , id = None , ** kwargs ):
421
415
"""Creates a project for a user.
422
416
423
417
id must be a dict.
424
418
"""
425
- return self ._getListOrObject (UserProject , id , ** kwargs )
419
+ return UserProject ._getListOrObject (self , id , ** kwargs )
426
420
427
421
def _list_projects (self , url , ** kwargs ):
428
422
r = self .rawGet (url , ** kwargs )
@@ -472,15 +466,15 @@ def Group(self, id=None, **kwargs):
472
466
object is NOT saved on the server. Use the save() method on the object
473
467
to write it on the server.
474
468
"""
475
- return self ._getListOrObject (Group , id , ** kwargs )
469
+ return Group ._getListOrObject (self , id , ** kwargs )
476
470
477
471
def Issue (self , id = None , ** kwargs ):
478
472
"""Lists issues(s) known by the GitLab server.
479
473
480
474
Does not support creation or getting a single issue unlike other
481
475
methods in this class yet.
482
476
"""
483
- return self ._getListOrObject (Issue , id , ** kwargs )
477
+ return Issue ._getListOrObject (self , id , ** kwargs )
484
478
485
479
def User (self , id = None , ** kwargs ):
486
480
"""Creates/gets/lists users(s) known by the GitLab server.
@@ -494,7 +488,7 @@ def User(self, id=None, **kwargs):
494
488
object is NOT saved on the server. Use the save() method on the object
495
489
to write it on the server.
496
490
"""
497
- return self ._getListOrObject (User , id , ** kwargs )
491
+ return User ._getListOrObject (self , id , ** kwargs )
498
492
499
493
def Team (self , id = None , ** kwargs ):
500
494
"""Creates/gets/lists team(s) known by the GitLab server.
@@ -508,7 +502,7 @@ def Team(self, id=None, **kwargs):
508
502
object is NOT saved on the server. Use the save() method on the object
509
503
to write it on the server.
510
504
"""
511
- return self ._getListOrObject (Team , id , ** kwargs )
505
+ return Team ._getListOrObject (self , id , ** kwargs )
512
506
513
507
514
508
def _get_display_encoding ():
@@ -555,23 +549,24 @@ def list(cls, gl, **kwargs):
555
549
556
550
return gl .list (cls , ** kwargs )
557
551
558
- def _getListOrObject (self , cls , id , ** kwargs ):
552
+ @classmethod
553
+ def _getListOrObject (cls , gl , id , ** kwargs ):
559
554
if id is None and cls .getListWhenNoId :
560
555
if not cls .canList :
561
556
raise GitlabListError
562
- return cls .list (self . gitlab , ** kwargs )
557
+ return cls .list (gl , ** kwargs )
563
558
elif id is None and not cls .getListWhenNoId :
564
559
if not cls .canGet :
565
560
raise GitlabGetError
566
- return cls (self . gitlab , id , ** kwargs )
561
+ return cls (gl , id , ** kwargs )
567
562
elif isinstance (id , dict ):
568
563
if not cls .canCreate :
569
564
raise GitlabCreateError
570
- return cls (self . gitlab , id , ** kwargs )
565
+ return cls (gl , id , ** kwargs )
571
566
else :
572
567
if not cls .canGet :
573
568
raise GitlabGetError
574
- return cls (self . gitlab , id , ** kwargs )
569
+ return cls (gl , id , ** kwargs )
575
570
576
571
def _getObject (self , k , v ):
577
572
if self ._constructorTypes and k in self ._constructorTypes :
@@ -721,9 +716,9 @@ class User(GitlabObject):
721
716
722
717
723
718
def Key (self , id = None , ** kwargs ):
724
- return self ._getListOrObject (UserKey , id ,
725
- user_id = self .id ,
726
- ** kwargs )
719
+ return UserKey ._getListOrObject (self . gitlab , id ,
720
+ user_id = self .id ,
721
+ ** kwargs )
727
722
728
723
729
724
class CurrentUserKey (GitlabObject ):
@@ -742,7 +737,7 @@ class CurrentUser(GitlabObject):
742
737
shortPrintAttr = 'username'
743
738
744
739
def Key (self , id = None , ** kwargs ):
745
- return self ._getListOrObject (CurrentUserKey , id , ** kwargs )
740
+ return CurrentUserKey ._getListOrObject (self . gitlab , id , ** kwargs )
746
741
747
742
class GroupMember (GitlabObject ):
748
743
_url = '/groups/%(group_id)s/members'
@@ -767,9 +762,9 @@ class Group(GitlabObject):
767
762
OWNER_ACCESS = 50
768
763
769
764
def Member (self , id = None , ** kwargs ):
770
- return self ._getListOrObject (GroupMember , id ,
771
- group_id = self .id ,
772
- ** kwargs )
765
+ return GroupMember ._getListOrObject (self . gitlab , id ,
766
+ group_id = self .id ,
767
+ ** kwargs )
773
768
774
769
def transfer_project (self , id ):
775
770
url = '/groups/%d/projects/%d' % (self .id , id )
@@ -900,10 +895,10 @@ class ProjectIssue(GitlabObject):
900
895
shortPrintAttr = 'title'
901
896
902
897
def Note (self , id = None , ** kwargs ):
903
- return self ._getListOrObject (ProjectIssueNote , id ,
904
- project_id = self .project_id ,
905
- issue_id = self .id ,
906
- ** kwargs )
898
+ return ProjectIssueNote ._getListOrObject (self . gitlab , id ,
899
+ project_id = self .project_id ,
900
+ issue_id = self .id ,
901
+ ** kwargs )
907
902
908
903
909
904
class ProjectMember (GitlabObject ):
@@ -952,10 +947,9 @@ class ProjectMergeRequest(GitlabObject):
952
947
optionalCreateAttrs = ['assignee_id' ]
953
948
954
949
def Note (self , id = None , ** kwargs ):
955
- return self ._getListOrObject (ProjectMergeRequestNote , id ,
956
- project_id = self .project_id ,
957
- merge_request_id = self .id ,
958
- ** kwargs )
950
+ return ProjectMergeRequestNote ._getListOrObject (
951
+ self .gitlab , id , project_id = self .project_id ,
952
+ merge_request_id = self .id , ** kwargs )
959
953
960
954
961
955
class ProjectMilestone (GitlabObject ):
@@ -1018,10 +1012,10 @@ def Content(self):
1018
1012
raise GitlabGetError
1019
1013
1020
1014
def Note (self , id = None , ** kwargs ):
1021
- return self ._getListOrObject (ProjectSnippetNote , id ,
1022
- project_id = self .project_id ,
1023
- snippet_id = self .id ,
1024
- ** kwargs )
1015
+ return ProjectSnippetNote ._getListOrObject (self . gitlab , id ,
1016
+ project_id = self .project_id ,
1017
+ snippet_id = self .id ,
1018
+ ** kwargs )
1025
1019
1026
1020
1027
1021
class UserProject (GitlabObject ):
@@ -1052,74 +1046,74 @@ class Project(GitlabObject):
1052
1046
shortPrintAttr = 'path'
1053
1047
1054
1048
def Branch (self , id = None , ** kwargs ):
1055
- return self ._getListOrObject (ProjectBranch , id ,
1056
- project_id = self .id ,
1057
- ** kwargs )
1049
+ return ProjectBranch ._getListOrObject (self . gitlab , id ,
1050
+ project_id = self .id ,
1051
+ ** kwargs )
1058
1052
1059
1053
def Commit (self , id = None , ** kwargs ):
1060
- return self ._getListOrObject (ProjectCommit , id ,
1061
- project_id = self .id ,
1062
- ** kwargs )
1054
+ return ProjectCommit ._getListOrObject (self . gitlab , id ,
1055
+ project_id = self .id ,
1056
+ ** kwargs )
1063
1057
1064
1058
def Event (self , id = None , ** kwargs ):
1065
- return self ._getListOrObject (ProjectEvent , id ,
1066
- project_id = self .id ,
1067
- ** kwargs )
1059
+ return ProjectEvent ._getListOrObject (self . gitlab , id ,
1060
+ project_id = self .id ,
1061
+ ** kwargs )
1068
1062
1069
1063
def Hook (self , id = None , ** kwargs ):
1070
- return self ._getListOrObject (ProjectHook , id ,
1071
- project_id = self .id ,
1072
- ** kwargs )
1064
+ return ProjectHook ._getListOrObject (self . gitlab , id ,
1065
+ project_id = self .id ,
1066
+ ** kwargs )
1073
1067
1074
1068
def Key (self , id = None , ** kwargs ):
1075
- return self ._getListOrObject (ProjectKey , id ,
1076
- project_id = self .id ,
1077
- ** kwargs )
1069
+ return ProjectKey ._getListOrObject (self . gitlab , id ,
1070
+ project_id = self .id ,
1071
+ ** kwargs )
1078
1072
1079
1073
def Issue (self , id = None , ** kwargs ):
1080
- return self ._getListOrObject (ProjectIssue , id ,
1081
- project_id = self .id ,
1082
- ** kwargs )
1074
+ return ProjectIssue ._getListOrObject (self . gitlab , id ,
1075
+ project_id = self .id ,
1076
+ ** kwargs )
1083
1077
1084
1078
def Member (self , id = None , ** kwargs ):
1085
- return self ._getListOrObject (ProjectMember , id ,
1086
- project_id = self .id ,
1087
- ** kwargs )
1079
+ return ProjectMember ._getListOrObject (self . gitlab , id ,
1080
+ project_id = self .id ,
1081
+ ** kwargs )
1088
1082
1089
1083
def MergeRequest (self , id = None , ** kwargs ):
1090
- return self ._getListOrObject (ProjectMergeRequest , id ,
1091
- project_id = self .id ,
1092
- ** kwargs )
1084
+ return ProjectMergeRequest ._getListOrObject (self . gitlab , id ,
1085
+ project_id = self .id ,
1086
+ ** kwargs )
1093
1087
1094
1088
def Milestone (self , id = None , ** kwargs ):
1095
- return self ._getListOrObject (ProjectMilestone , id ,
1096
- project_id = self .id ,
1097
- ** kwargs )
1089
+ return ProjectMilestone ._getListOrObject (self . gitlab , id ,
1090
+ project_id = self .id ,
1091
+ ** kwargs )
1098
1092
1099
1093
def Note (self , id = None , ** kwargs ):
1100
- return self ._getListOrObject (ProjectNote , id ,
1101
- project_id = self .id ,
1102
- ** kwargs )
1094
+ return ProjectNote ._getListOrObject (self . gitlab , id ,
1095
+ project_id = self .id ,
1096
+ ** kwargs )
1103
1097
1104
1098
def Snippet (self , id = None , ** kwargs ):
1105
- return self ._getListOrObject (ProjectSnippet , id ,
1106
- project_id = self .id ,
1107
- ** kwargs )
1099
+ return ProjectSnippet ._getListOrObject (self . gitlab , id ,
1100
+ project_id = self .id ,
1101
+ ** kwargs )
1108
1102
1109
1103
def Label (self , id = None , ** kwargs ):
1110
- return self ._getListOrObject (ProjectLabel , id ,
1111
- project_id = self .id ,
1112
- ** kwargs )
1104
+ return ProjectLabel ._getListOrObject (self . gitlab , id ,
1105
+ project_id = self .id ,
1106
+ ** kwargs )
1113
1107
1114
1108
def File (self , id = None , ** kwargs ):
1115
- return self ._getListOrObject (ProjectFile , id ,
1116
- project_id = self .id ,
1117
- ** kwargs )
1109
+ return ProjectFile ._getListOrObject (self . gitlab , id ,
1110
+ project_id = self .id ,
1111
+ ** kwargs )
1118
1112
1119
1113
def Tag (self , id = None , ** kwargs ):
1120
- return self ._getListOrObject (ProjectTag , id ,
1121
- project_id = self .id ,
1122
- ** kwargs )
1114
+ return ProjectTag ._getListOrObject (self . gitlab , id ,
1115
+ project_id = self .id ,
1116
+ ** kwargs )
1123
1117
1124
1118
def tree (self , path = '' , ref_name = '' ):
1125
1119
url = "%s/%s/repository/tree" % (self ._url , self .id )
@@ -1198,11 +1192,11 @@ class Team(GitlabObject):
1198
1192
canUpdate = False
1199
1193
1200
1194
def Member (self , id = None , ** kwargs ):
1201
- return self ._getListOrObject (TeamMember , id ,
1202
- team_id = self .id ,
1203
- ** kwargs )
1195
+ return TeamMember ._getListOrObject (self . gitlab , id ,
1196
+ team_id = self .id ,
1197
+ ** kwargs )
1204
1198
1205
1199
def Project (self , id = None , ** kwargs ):
1206
- return self ._getListOrObject (TeamProject , id ,
1207
- team_id = self .id ,
1208
- ** kwargs )
1200
+ return TeamProject ._getListOrObject (self . gitlab , id ,
1201
+ team_id = self .id ,
1202
+ ** kwargs )
0 commit comments