Skip to content

Commit 34d6952

Browse files
author
Gauvain Pocentek
committed
Support namespace/name for project id
Closes #28
1 parent d38f219 commit 34d6952

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

gitlab.py

+24-8
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,12 @@ def list(self, obj_class, **kwargs):
187187
raise GitlabListError('Missing attribute(s): %s' %
188188
", ".join(missing))
189189

190-
url = obj_class._url % kwargs
190+
args = _sanitize_dict(kwargs)
191+
url = obj_class._url % args
191192
url = '%s%s' % (self._url, url)
192-
if kwargs:
193+
if args:
193194
url += "?%s" % ("&".join(
194-
["%s=%s" % (k, v) for k, v in kwargs.items()]))
195+
["%s=%s" % (k, v) for k, v in args.items()]))
195196

196197
try:
197198
r = requests.get(url, headers=self.headers, verify=self.ssl_verify)
@@ -225,7 +226,7 @@ def get(self, obj_class, id=None, **kwargs):
225226
raise GitlabListError('Missing attribute(s): %s' %
226227
", ".join(missing))
227228

228-
url = obj_class._url % kwargs
229+
url = obj_class._url % _sanitize_dict(kwargs)
229230
if id is not None:
230231
url = '%s%s/%s' % (self._url, url, str(id))
231232
else:
@@ -247,8 +248,9 @@ def get(self, obj_class, id=None, **kwargs):
247248
raise GitlabGetError('%d: %s' % (r.status_code, r.text))
248249

249250
def delete(self, obj):
250-
url = obj._url % obj.__dict__
251-
url = '%s%s/%s' % (self._url, url, str(obj.id))
251+
args = _sanitize_dict(obj.__dict__)
252+
url = obj._url % args
253+
url = '%s%s/%s' % (self._url, url, args['id'])
252254

253255
try:
254256
r = requests.delete(url,
@@ -275,7 +277,8 @@ def create(self, obj):
275277
raise GitlabCreateError('Missing attribute(s): %s' %
276278
", ".join(missing))
277279

278-
url = obj._url % obj.__dict__
280+
args = _sanitize_dict(obj.__dict__)
281+
url = obj._url % args
279282
url = '%s%s' % (self._url, url)
280283

281284
try:
@@ -294,7 +297,8 @@ def create(self, obj):
294297
raise GitlabCreateError('%d: %s' % (r.status_code, r.text))
295298

296299
def update(self, obj):
297-
url = obj._url % obj.__dict__
300+
args = _sanitize_dict(obj.__dict__)
301+
url = obj._url % args
298302
url = '%s%s/%s' % (self._url, url, str(obj.id))
299303

300304
# build a dict of data that can really be sent to server
@@ -446,9 +450,21 @@ def Team(self, id=None, **kwargs):
446450
"""
447451
return self._getListOrObject(Team, id, **kwargs)
448452

453+
449454
def _get_display_encoding():
450455
return sys.stdout.encoding or sys.getdefaultencoding()
451456

457+
458+
def _sanitize(value):
459+
if type(value) in (str, unicode):
460+
return value.replace('/', '%2F')
461+
return value
462+
463+
464+
def _sanitize_dict(src):
465+
return {k:_sanitize(v) for k, v in src.items()}
466+
467+
452468
class GitlabObject(object):
453469
_url = None
454470
_returnClass = None

0 commit comments

Comments
 (0)