21
21
from itertools import chain
22
22
import json
23
23
import sys
24
+ import warnings
24
25
25
26
import requests
26
27
import six
32
33
__license__ = 'LGPL3'
33
34
__copyright__ = 'Copyright 2013-2014 Gauvain Pocentek'
34
35
36
+ warnings .simplefilter ('always' , DeprecationWarning )
37
+
35
38
36
39
class jsonEncoder (json .JSONEncoder ):
37
40
def default (self , obj ):
@@ -144,7 +147,7 @@ def __init__(self, url, private_token=None,
144
147
self .timeout = timeout
145
148
#: Headers that will be used in request to GitLab
146
149
self .headers = {}
147
- self .setToken (private_token )
150
+ self .set_token (private_token )
148
151
#: the user email
149
152
self .email = email
150
153
#: the user password (associated with email)
@@ -169,7 +172,7 @@ def credentials_auth(self):
169
172
raise GitlabAuthenticationError ("Missing email/password" )
170
173
171
174
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' )
173
176
174
177
if r .status_code == 201 :
175
178
self .user = CurrentUser (self , r .json ())
@@ -202,6 +205,12 @@ def _createHeaders(self, content_type=None, headers={}):
202
205
return request_headers
203
206
204
207
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 ):
205
214
"""Sets the private token for authentication"""
206
215
self .private_token = token if token else None
207
216
if token :
@@ -210,11 +219,21 @@ def setToken(self, token):
210
219
del self .headers ["PRIVATE-TOKEN" ]
211
220
212
221
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 ):
213
228
"""Sets the email/login and password for authentication"""
214
229
self .email = email
215
230
self .password = password
216
231
217
232
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 ):
218
237
url = '%s%s' % (self ._url , path )
219
238
headers = self ._createHeaders (content_type )
220
239
@@ -229,6 +248,10 @@ def rawGet(self, path, content_type=None, **kwargs):
229
248
"Can't connect to GitLab server (%s)" % self ._url )
230
249
231
250
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 ):
232
255
url = '%s%s' % (self ._url , path )
233
256
headers = self ._createHeaders (content_type )
234
257
try :
@@ -241,6 +264,10 @@ def rawPost(self, path, data=None, content_type=None, **kwargs):
241
264
"Can't connect to GitLab server (%s)" % self ._url )
242
265
243
266
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 ):
244
271
url = '%s%s' % (self ._url , path )
245
272
headers = self ._createHeaders (content_type )
246
273
@@ -254,6 +281,10 @@ def rawPut(self, path, data=None, content_type=None, **kwargs):
254
281
"Can't connect to GitLab server (%s)" % self ._url )
255
282
256
283
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 ):
257
288
url = '%s%s' % (self ._url , path )
258
289
headers = self ._createHeaders (content_type )
259
290
@@ -476,7 +507,7 @@ def UserProject(self, id=None, **kwargs):
476
507
return UserProject ._getListOrObject (self , id , ** kwargs )
477
508
478
509
def _list_projects (self , url , ** kwargs ):
479
- r = self .rawGet (url , ** kwargs )
510
+ r = self ._raw_get (url , ** kwargs )
480
511
if r .status_code != 200 :
481
512
_raiseErrorFromResponse (r , GitlabListError )
482
513
@@ -838,7 +869,7 @@ def Member(self, id=None, **kwargs):
838
869
839
870
def transfer_project (self , id , ** kwargs ):
840
871
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 )
842
873
if r .status_code != 201 :
843
874
_raiseErrorFromResponse (r , GitlabTransferProjectError )
844
875
@@ -875,7 +906,7 @@ def protect(self, protect=True, **kwargs):
875
906
url = self ._url % {'project_id' : self .project_id }
876
907
action = 'protect' if protect else 'unprotect'
877
908
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 )
879
910
880
911
if r .status_code == 200 :
881
912
if protect :
@@ -900,7 +931,7 @@ class ProjectCommit(GitlabObject):
900
931
def diff (self , ** kwargs ):
901
932
url = ('/projects/%(project_id)s/repository/commits/%(commit_id)s/diff'
902
933
% {'project_id' : self .project_id , 'commit_id' : self .id })
903
- r = self .gitlab .rawGet (url , ** kwargs )
934
+ r = self .gitlab ._raw_get (url , ** kwargs )
904
935
if r .status_code == 200 :
905
936
return r .json ()
906
937
else :
@@ -910,7 +941,7 @@ def blob(self, filepath, **kwargs):
910
941
url = '/projects/%(project_id)s/repository/blobs/%(commit_id)s' % \
911
942
{'project_id' : self .project_id , 'commit_id' : self .id }
912
943
url += '?filepath=%s' % filepath
913
- r = self .gitlab .rawGet (url , ** kwargs )
944
+ r = self .gitlab ._raw_get (url , ** kwargs )
914
945
if r .status_code == 200 :
915
946
return r .content
916
947
else :
@@ -1086,7 +1117,7 @@ class ProjectSnippet(GitlabObject):
1086
1117
def Content (self , ** kwargs ):
1087
1118
url = "/projects/%(project_id)s/snippets/%(snippet_id)s/raw" % \
1088
1119
{'project_id' : self .project_id , 'snippet_id' : self .id }
1089
- r = self .gitlab .rawGet (url , ** kwargs )
1120
+ r = self .gitlab ._raw_get (url , ** kwargs )
1090
1121
1091
1122
if r .status_code == 200 :
1092
1123
return r .content
@@ -1200,7 +1231,7 @@ def Tag(self, id=None, **kwargs):
1200
1231
def tree (self , path = '' , ref_name = '' , ** kwargs ):
1201
1232
url = "%s/%s/repository/tree" % (self ._url , self .id )
1202
1233
url += '?path=%s&ref_name=%s' % (path , ref_name )
1203
- r = self .gitlab .rawGet (url , ** kwargs )
1234
+ r = self .gitlab ._raw_get (url , ** kwargs )
1204
1235
if r .status_code == 200 :
1205
1236
return r .json ()
1206
1237
else :
@@ -1209,7 +1240,7 @@ def tree(self, path='', ref_name='', **kwargs):
1209
1240
def blob (self , sha , filepath , ** kwargs ):
1210
1241
url = "%s/%s/repository/blobs/%s" % (self ._url , self .id , sha )
1211
1242
url += '?filepath=%s' % (filepath )
1212
- r = self .gitlab .rawGet (url , ** kwargs )
1243
+ r = self .gitlab ._raw_get (url , ** kwargs )
1213
1244
if r .status_code == 200 :
1214
1245
return r .content
1215
1246
else :
@@ -1219,7 +1250,7 @@ def archive(self, sha=None, **kwargs):
1219
1250
url = '/projects/%s/repository/archive' % self .id
1220
1251
if sha :
1221
1252
url += '?sha=%s' % sha
1222
- r = self .gitlab .rawGet (url , ** kwargs )
1253
+ r = self .gitlab ._raw_get (url , ** kwargs )
1223
1254
if r .status_code == 200 :
1224
1255
return r .content
1225
1256
else :
@@ -1242,23 +1273,23 @@ def create_file(self, path, branch, content, message, **kwargs):
1242
1273
url = "/projects/%s/repository/files" % self .id
1243
1274
url += "?file_path=%s&branch_name=%s&content=%s&commit_message=%s" % \
1244
1275
(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 )
1246
1277
if r .status_code != 201 :
1247
1278
_raiseErrorFromResponse (r , GitlabCreateError )
1248
1279
1249
1280
def update_file (self , path , branch , content , message , ** kwargs ):
1250
1281
url = "/projects/%s/repository/files" % self .id
1251
1282
url += "?file_path=%s&branch_name=%s&content=%s&commit_message=%s" % \
1252
1283
(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 )
1254
1285
if r .status_code != 200 :
1255
1286
_raiseErrorFromResponse (r , GitlabUpdateError )
1256
1287
1257
1288
def delete_file (self , path , branch , message , ** kwargs ):
1258
1289
url = "/projects/%s/repository/files" % self .id
1259
1290
url += "?file_path=%s&branch_name=%s&commit_message=%s" % \
1260
1291
(path , branch , message )
1261
- r = self .gitlab .rawDelete (url , ** kwargs )
1292
+ r = self .gitlab ._raw_delete (url , ** kwargs )
1262
1293
if r .status_code != 200 :
1263
1294
_raiseErrorFromResponse (r , GitlabDeleteError )
1264
1295
0 commit comments