18
18
from __future__ import print_function
19
19
from __future__ import division
20
20
from __future__ import absolute_import
21
- from itertools import chain
21
+ import itertools
22
22
import json
23
23
import sys
24
24
import warnings
@@ -179,13 +179,13 @@ def credentials_auth(self):
179
179
else :
180
180
_raiseErrorFromResponse (r , GitlabAuthenticationError )
181
181
182
- self .setToken (self .user .private_token )
182
+ self .set_token (self .user .private_token )
183
183
184
184
def token_auth (self ):
185
185
self .user = CurrentUser (self )
186
186
187
187
def setUrl (self , url ):
188
- """Updates the gitlab URL"""
188
+ """Updates the gitlab URL. """
189
189
self ._url = '%s/api/v3' % url
190
190
191
191
def constructUrl (self , id_ , obj , parameters ):
@@ -205,27 +205,28 @@ def _createHeaders(self, content_type=None, headers={}):
205
205
return request_headers
206
206
207
207
def setToken (self , token ):
208
- """(DEPRECATED) Sets the private token for authentication"""
208
+ """(DEPRECATED) Sets the private token for authentication. """
209
209
warnings .warn ("setToken is deprecated, use set_token instead" ,
210
210
DeprecationWarning )
211
211
self .set_token (token )
212
212
213
213
def set_token (self , token ):
214
- """Sets the private token for authentication"""
214
+ """Sets the private token for authentication. """
215
215
self .private_token = token if token else None
216
216
if token :
217
217
self .headers ["PRIVATE-TOKEN" ] = token
218
218
elif "PRIVATE-TOKEN" in self .headers :
219
219
del self .headers ["PRIVATE-TOKEN" ]
220
220
221
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" ,
222
+ """(DEPRECATED) Sets the login and password for authentication."""
223
+ warnings .warn ("setCredential is deprecated, use set_credentials "
224
+ "instead" ,
224
225
DeprecationWarning )
225
226
self .set_credentials (email , password )
226
227
227
228
def set_credentials (self , email , password ):
228
- """Sets the email/login and password for authentication"""
229
+ """Sets the email/login and password for authentication. """
229
230
self .email = email
230
231
self .password = password
231
232
@@ -300,8 +301,8 @@ def _raw_delete(self, path, content_type=None, **kwargs):
300
301
301
302
def list (self , obj_class , ** kwargs ):
302
303
missing = []
303
- for k in chain (obj_class .requiredUrlAttrs ,
304
- obj_class .requiredListAttrs ):
304
+ for k in itertools . chain (obj_class .requiredUrlAttrs ,
305
+ obj_class .requiredListAttrs ):
305
306
if k not in kwargs :
306
307
missing .append (k )
307
308
if missing :
@@ -348,8 +349,8 @@ def list(self, obj_class, **kwargs):
348
349
349
350
def get (self , obj_class , id = None , ** kwargs ):
350
351
missing = []
351
- for k in chain (obj_class .requiredUrlAttrs ,
352
- obj_class .requiredGetAttrs ):
352
+ for k in itertools . chain (obj_class .requiredUrlAttrs ,
353
+ obj_class .requiredGetAttrs ):
353
354
if k not in kwargs :
354
355
missing .append (k )
355
356
if missing :
@@ -381,7 +382,8 @@ def delete(self, obj, **kwargs):
381
382
params = obj .__dict__ .copy ()
382
383
params .update (kwargs )
383
384
missing = []
384
- for k in chain (obj .requiredUrlAttrs , obj .requiredDeleteAttrs ):
385
+ for k in itertools .chain (obj .requiredUrlAttrs ,
386
+ obj .requiredDeleteAttrs ):
385
387
if k not in params :
386
388
missing .append (k )
387
389
if missing :
@@ -415,7 +417,8 @@ def create(self, obj, **kwargs):
415
417
params = obj .__dict__ .copy ()
416
418
params .update (kwargs )
417
419
missing = []
418
- for k in chain (obj .requiredUrlAttrs , obj .requiredCreateAttrs ):
420
+ for k in itertools .chain (obj .requiredUrlAttrs ,
421
+ obj .requiredCreateAttrs ):
419
422
if k not in params :
420
423
missing .append (k )
421
424
if missing :
@@ -446,7 +449,8 @@ def update(self, obj, **kwargs):
446
449
params = obj .__dict__ .copy ()
447
450
params .update (kwargs )
448
451
missing = []
449
- for k in chain (obj .requiredUrlAttrs , obj .requiredCreateAttrs ):
452
+ for k in itertools .chain (obj .requiredUrlAttrs ,
453
+ obj .requiredCreateAttrs ):
450
454
if k not in params :
451
455
missing .append (k )
452
456
if missing :
@@ -642,8 +646,8 @@ class GitlabObject(object):
642
646
643
647
def _dataForGitlab (self , extra_parameters = {}):
644
648
data = {}
645
- for attribute in chain (self .requiredCreateAttrs ,
646
- self .optionalCreateAttrs ):
649
+ for attribute in itertools . chain (self .requiredCreateAttrs ,
650
+ self .optionalCreateAttrs ):
647
651
if hasattr (self , attribute ):
648
652
data [attribute ] = getattr (self , attribute )
649
653
@@ -719,8 +723,8 @@ def __init__(self, gl, data=None, **kwargs):
719
723
self ._created = False
720
724
self .gitlab = gl
721
725
722
- if data is None or isinstance (data , six .integer_types ) or \
723
- isinstance (data , six .string_types ):
726
+ if ( data is None or isinstance (data , six .integer_types ) or
727
+ isinstance (data , six .string_types ) ):
724
728
if not self .canGet :
725
729
raise NotImplementedError
726
730
data = self .gitlab .get (self .__class__ , data , ** kwargs )
@@ -938,8 +942,8 @@ def diff(self, **kwargs):
938
942
_raiseErrorFromResponse (r , GitlabGetError )
939
943
940
944
def blob (self , filepath , ** kwargs ):
941
- url = '/projects/%(project_id)s/repository/blobs/%(commit_id)s' % \
942
- {'project_id' : self .project_id , 'commit_id' : self .id }
945
+ url = ( '/projects/%(project_id)s/repository/blobs/%(commit_id)s' %
946
+ {'project_id' : self .project_id , 'commit_id' : self .id })
943
947
url += '?filepath=%s' % filepath
944
948
r = self .gitlab ._raw_get (url , ** kwargs )
945
949
if r .status_code == 200 :
@@ -1115,8 +1119,8 @@ class ProjectSnippet(GitlabObject):
1115
1119
shortPrintAttr = 'title'
1116
1120
1117
1121
def Content (self , ** kwargs ):
1118
- url = "/projects/%(project_id)s/snippets/%(snippet_id)s/raw" % \
1119
- {'project_id' : self .project_id , 'snippet_id' : self .id }
1122
+ url = ( "/projects/%(project_id)s/snippets/%(snippet_id)s/raw" %
1123
+ {'project_id' : self .project_id , 'snippet_id' : self .id })
1120
1124
r = self .gitlab ._raw_get (url , ** kwargs )
1121
1125
1122
1126
if r .status_code == 200 :
@@ -1271,24 +1275,24 @@ def create_file(self, path, branch, content, message, **kwargs):
1271
1275
GitlabConnectionError: Connection to GitLab-server failed
1272
1276
"""
1273
1277
url = "/projects/%s/repository/files" % self .id
1274
- url += "?file_path=%s&branch_name=%s&content=%s&commit_message=%s" % \
1275
- (path , branch , content , message )
1278
+ url += ( "?file_path=%s&branch_name=%s&content=%s&commit_message=%s" %
1279
+ (path , branch , content , message ) )
1276
1280
r = self .gitlab ._raw_post (url , data = None , content_type = None , ** kwargs )
1277
1281
if r .status_code != 201 :
1278
1282
_raiseErrorFromResponse (r , GitlabCreateError )
1279
1283
1280
1284
def update_file (self , path , branch , content , message , ** kwargs ):
1281
1285
url = "/projects/%s/repository/files" % self .id
1282
- url += "?file_path=%s&branch_name=%s&content=%s&commit_message=%s" % \
1283
- (path , branch , content , message )
1286
+ url += ( "?file_path=%s&branch_name=%s&content=%s&commit_message=%s" %
1287
+ (path , branch , content , message ) )
1284
1288
r = self .gitlab ._raw_put (url , data = None , content_type = None , ** kwargs )
1285
1289
if r .status_code != 200 :
1286
1290
_raiseErrorFromResponse (r , GitlabUpdateError )
1287
1291
1288
1292
def delete_file (self , path , branch , message , ** kwargs ):
1289
1293
url = "/projects/%s/repository/files" % self .id
1290
- url += "?file_path=%s&branch_name=%s&commit_message=%s" % \
1291
- (path , branch , message )
1294
+ url += ( "?file_path=%s&branch_name=%s&commit_message=%s" %
1295
+ (path , branch , message ) )
1292
1296
r = self .gitlab ._raw_delete (url , ** kwargs )
1293
1297
if r .status_code != 200 :
1294
1298
_raiseErrorFromResponse (r , GitlabDeleteError )
0 commit comments