summaryrefslogtreecommitdiff
path: root/gitlab/__init__.py
diff options
context:
space:
mode:
authorJames Johnson <d0c.s4vage@gmail.com>2017-09-11 23:20:08 -0500
committerGauvain Pocentek <gauvain@pocentek.net>2017-09-12 06:20:08 +0200
commit29879d61d117ff7909302ed845a6a1eb13814365 (patch)
treefafcb7f7003cc4b5a4146ea6090a76d9bf82082e /gitlab/__init__.py
parentfd40fce913fbb3cd0e3aa2fd042e20bf1d51e9d6 (diff)
downloadgitlab-29879d61d117ff7909302ed845a6a1eb13814365.tar.gz
adds project upload feature (#239)
Diffstat (limited to 'gitlab/__init__.py')
-rw-r--r--gitlab/__init__.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/gitlab/__init__.py b/gitlab/__init__.py
index 0768abb..4a56175 100644
--- a/gitlab/__init__.py
+++ b/gitlab/__init__.py
@@ -396,11 +396,13 @@ class Gitlab(object):
return results
- def _raw_post(self, path_, data=None, content_type=None, **kwargs):
+ def _raw_post(self, path_, data=None, content_type=None,
+ files=None, **kwargs):
url = '%s%s' % (self._url, path_)
opts = self._get_session_opts(content_type)
try:
- return self.session.post(url, params=kwargs, data=data, **opts)
+ return self.session.post(url, params=kwargs, data=data,
+ files=files, **opts)
except Exception as e:
raise GitlabConnectionError(
"Can't connect to GitLab server (%s)" % e)
@@ -628,7 +630,7 @@ class Gitlab(object):
return '%s%s' % (self._url, path)
def http_request(self, verb, path, query_data={}, post_data={},
- streamed=False, **kwargs):
+ streamed=False, files=None, **kwargs):
"""Make an HTTP request to the Gitlab server.
Args:
@@ -658,6 +660,11 @@ class Gitlab(object):
params = query_data.copy()
params.update(kwargs)
opts = self._get_session_opts(content_type='application/json')
+
+ # don't set the content-type header when uploading files
+ if files is not None:
+ del opts["headers"]["Content-type"]
+
verify = opts.pop('verify')
timeout = opts.pop('timeout')
@@ -668,7 +675,7 @@ class Gitlab(object):
# always agree with this decision (this is the case with a default
# gitlab installation)
req = requests.Request(verb, url, json=post_data, params=params,
- **opts)
+ files=files, **opts)
prepped = self.session.prepare_request(req)
prepped.url = sanitized_url(prepped.url)
result = self.session.send(prepped, stream=streamed, verify=verify,
@@ -756,7 +763,8 @@ class Gitlab(object):
# No pagination, generator requested
return GitlabList(self, url, query_data, **kwargs)
- def http_post(self, path, query_data={}, post_data={}, **kwargs):
+ def http_post(self, path, query_data={}, post_data={}, files=None,
+ **kwargs):
"""Make a POST request to the Gitlab server.
Args:
@@ -776,7 +784,7 @@ class Gitlab(object):
GitlabParsingError: If the json data could not be parsed
"""
result = self.http_request('post', path, query_data=query_data,
- post_data=post_data, **kwargs)
+ post_data=post_data, files=files, **kwargs)
try:
if result.headers.get('Content-Type', None) == 'application/json':
return result.json()