2121from itertools import chain
2222import json
2323import sys
24+ import warnings
2425
2526import requests
2627import six
3233__license__ = 'LGPL3'
3334__copyright__ = 'Copyright 2013-2014 Gauvain Pocentek'
3435
36+ warnings .simplefilter ('always' , DeprecationWarning )
37+
3538
3639class jsonEncoder (json .JSONEncoder ):
3740 def default (self , obj ):
@@ -144,7 +147,7 @@ def __init__(self, url, private_token=None,
144147 self .timeout = timeout
145148 #: Headers that will be used in request to GitLab
146149 self .headers = {}
147- self .setToken (private_token )
150+ self .set_token (private_token )
148151 #: the user email
149152 self .email = email
150153 #: the user password (associated with email)
@@ -169,7 +172,7 @@ def credentials_auth(self):
169172 raise GitlabAuthenticationError ("Missing email/password" )
170173
171174 data = json .dumps ({'email' : self .email , 'password' : self .password })
172- r = self .rawPost ('/session' , data , content_type = 'application/json' )
175+ r = self ._raw_post ('/session' , data , content_type = 'application/json' )
173176
174177 if r .status_code == 201 :
175178 self .user = CurrentUser (self , r .json ())
@@ -202,6 +205,12 @@ def _createHeaders(self, content_type=None, headers={}):
202205 return request_headers
203206
204207 def setToken (self , token ):
208+ """(DEPRECATED) Sets the private token for authentication"""
209+ warnings .warn ("setToken is deprecated, use set_token instead" ,
210+ DeprecationWarning )
211+ self .set_token (token )
212+
213+ def set_token (self , token ):
205214 """Sets the private token for authentication"""
206215 self .private_token = token if token else None
207216 if token :
@@ -210,11 +219,21 @@ def setToken(self, token):
210219 del self .headers ["PRIVATE-TOKEN" ]
211220
212221 def setCredentials (self , email , password ):
222+ """(DEPRECATED) Sets the email/login and password for authentication"""
223+ warnings .warn ("setToken is deprecated, use set_credentials instead" ,
224+ DeprecationWarning )
225+ self .set_credentials (email , password )
226+
227+ def set_credentials (self , email , password ):
213228 """Sets the email/login and password for authentication"""
214229 self .email = email
215230 self .password = password
216231
217232 def rawGet (self , path , content_type = None , ** kwargs ):
233+ warnings .warn ("rawGet is deprecated" , DeprecationWarning )
234+ return self ._raw_get (path , content_type , ** kwargs )
235+
236+ def _raw_get (self , path , content_type = None , ** kwargs ):
218237 url = '%s%s' % (self ._url , path )
219238 headers = self ._createHeaders (content_type )
220239
@@ -229,6 +248,10 @@ def rawGet(self, path, content_type=None, **kwargs):
229248 "Can't connect to GitLab server (%s)" % self ._url )
230249
231250 def rawPost (self , path , data = None , content_type = None , ** kwargs ):
251+ warnings .warn ("rawPost is deprecated" , DeprecationWarning )
252+ return self ._raw_post (path , data , content_type , ** kwargs )
253+
254+ def _raw_post (self , path , data = None , content_type = None , ** kwargs ):
232255 url = '%s%s' % (self ._url , path )
233256 headers = self ._createHeaders (content_type )
234257 try :
@@ -241,6 +264,10 @@ def rawPost(self, path, data=None, content_type=None, **kwargs):
241264 "Can't connect to GitLab server (%s)" % self ._url )
242265
243266 def rawPut (self , path , data = None , content_type = None , ** kwargs ):
267+ warnings .warn ("rawPut is deprecated" , DeprecationWarning )
268+ return self ._raw_put (path , data , content_type , ** kwargs )
269+
270+ def _raw_put (self , path , data = None , content_type = None , ** kwargs ):
244271 url = '%s%s' % (self ._url , path )
245272 headers = self ._createHeaders (content_type )
246273
@@ -254,6 +281,10 @@ def rawPut(self, path, data=None, content_type=None, **kwargs):
254281 "Can't connect to GitLab server (%s)" % self ._url )
255282
256283 def rawDelete (self , path , content_type = None , ** kwargs ):
284+ warnings .warn ("rawDelete is deprecated" , DeprecationWarning )
285+ return self ._raw_delete (path , content_type , ** kwargs )
286+
287+ def _raw_delete (self , path , content_type = None , ** kwargs ):
257288 url = '%s%s' % (self ._url , path )
258289 headers = self ._createHeaders (content_type )
259290
@@ -476,7 +507,7 @@ def UserProject(self, id=None, **kwargs):
476507 return UserProject ._getListOrObject (self , id , ** kwargs )
477508
478509 def _list_projects (self , url , ** kwargs ):
479- r = self .rawGet (url , ** kwargs )
510+ r = self ._raw_get (url , ** kwargs )
480511 if r .status_code != 200 :
481512 _raiseErrorFromResponse (r , GitlabListError )
482513
@@ -838,7 +869,7 @@ def Member(self, id=None, **kwargs):
838869
839870 def transfer_project (self , id , ** kwargs ):
840871 url = '/groups/%d/projects/%d' % (self .id , id )
841- r = self .gitlab .rawPost (url , None , ** kwargs )
872+ r = self .gitlab ._raw_post (url , None , ** kwargs )
842873 if r .status_code != 201 :
843874 _raiseErrorFromResponse (r , GitlabTransferProjectError )
844875
@@ -875,7 +906,7 @@ def protect(self, protect=True, **kwargs):
875906 url = self ._url % {'project_id' : self .project_id }
876907 action = 'protect' if protect else 'unprotect'
877908 url = "%s/%s/%s" % (url , self .name , action )
878- r = self .gitlab .rawPut (url , data = None , content_type = None , ** kwargs )
909+ r = self .gitlab ._raw_put (url , data = None , content_type = None , ** kwargs )
879910
880911 if r .status_code == 200 :
881912 if protect :
@@ -900,7 +931,7 @@ class ProjectCommit(GitlabObject):
900931 def diff (self , ** kwargs ):
901932 url = ('/projects/%(project_id)s/repository/commits/%(commit_id)s/diff'
902933 % {'project_id' : self .project_id , 'commit_id' : self .id })
903- r = self .gitlab .rawGet (url , ** kwargs )
934+ r = self .gitlab ._raw_get (url , ** kwargs )
904935 if r .status_code == 200 :
905936 return r .json ()
906937 else :
@@ -910,7 +941,7 @@ def blob(self, filepath, **kwargs):
910941 url = '/projects/%(project_id)s/repository/blobs/%(commit_id)s' % \
911942 {'project_id' : self .project_id , 'commit_id' : self .id }
912943 url += '?filepath=%s' % filepath
913- r = self .gitlab .rawGet (url , ** kwargs )
944+ r = self .gitlab ._raw_get (url , ** kwargs )
914945 if r .status_code == 200 :
915946 return r .content
916947 else :
@@ -1086,7 +1117,7 @@ class ProjectSnippet(GitlabObject):
10861117 def Content (self , ** kwargs ):
10871118 url = "/projects/%(project_id)s/snippets/%(snippet_id)s/raw" % \
10881119 {'project_id' : self .project_id , 'snippet_id' : self .id }
1089- r = self .gitlab .rawGet (url , ** kwargs )
1120+ r = self .gitlab ._raw_get (url , ** kwargs )
10901121
10911122 if r .status_code == 200 :
10921123 return r .content
@@ -1200,7 +1231,7 @@ def Tag(self, id=None, **kwargs):
12001231 def tree (self , path = '' , ref_name = '' , ** kwargs ):
12011232 url = "%s/%s/repository/tree" % (self ._url , self .id )
12021233 url += '?path=%s&ref_name=%s' % (path , ref_name )
1203- r = self .gitlab .rawGet (url , ** kwargs )
1234+ r = self .gitlab ._raw_get (url , ** kwargs )
12041235 if r .status_code == 200 :
12051236 return r .json ()
12061237 else :
@@ -1209,7 +1240,7 @@ def tree(self, path='', ref_name='', **kwargs):
12091240 def blob (self , sha , filepath , ** kwargs ):
12101241 url = "%s/%s/repository/blobs/%s" % (self ._url , self .id , sha )
12111242 url += '?filepath=%s' % (filepath )
1212- r = self .gitlab .rawGet (url , ** kwargs )
1243+ r = self .gitlab ._raw_get (url , ** kwargs )
12131244 if r .status_code == 200 :
12141245 return r .content
12151246 else :
@@ -1219,7 +1250,7 @@ def archive(self, sha=None, **kwargs):
12191250 url = '/projects/%s/repository/archive' % self .id
12201251 if sha :
12211252 url += '?sha=%s' % sha
1222- r = self .gitlab .rawGet (url , ** kwargs )
1253+ r = self .gitlab ._raw_get (url , ** kwargs )
12231254 if r .status_code == 200 :
12241255 return r .content
12251256 else :
@@ -1242,23 +1273,23 @@ def create_file(self, path, branch, content, message, **kwargs):
12421273 url = "/projects/%s/repository/files" % self .id
12431274 url += "?file_path=%s&branch_name=%s&content=%s&commit_message=%s" % \
12441275 (path , branch , content , message )
1245- r = self .gitlab .rawPost (url , data = None , content_type = None , ** kwargs )
1276+ r = self .gitlab ._raw_post (url , data = None , content_type = None , ** kwargs )
12461277 if r .status_code != 201 :
12471278 _raiseErrorFromResponse (r , GitlabCreateError )
12481279
12491280 def update_file (self , path , branch , content , message , ** kwargs ):
12501281 url = "/projects/%s/repository/files" % self .id
12511282 url += "?file_path=%s&branch_name=%s&content=%s&commit_message=%s" % \
12521283 (path , branch , content , message )
1253- r = self .gitlab .rawPut (url , data = None , content_type = None , ** kwargs )
1284+ r = self .gitlab ._raw_put (url , data = None , content_type = None , ** kwargs )
12541285 if r .status_code != 200 :
12551286 _raiseErrorFromResponse (r , GitlabUpdateError )
12561287
12571288 def delete_file (self , path , branch , message , ** kwargs ):
12581289 url = "/projects/%s/repository/files" % self .id
12591290 url += "?file_path=%s&branch_name=%s&commit_message=%s" % \
12601291 (path , branch , message )
1261- r = self .gitlab .rawDelete (url , ** kwargs )
1292+ r = self .gitlab ._raw_delete (url , ** kwargs )
12621293 if r .status_code != 200 :
12631294 _raiseErrorFromResponse (r , GitlabDeleteError )
12641295
0 commit comments