Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timeout support #39

Merged
merged 1 commit into from Oct 13, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 23 additions & 10 deletions gitlab.py
Expand Up @@ -75,15 +75,19 @@ class GitlabAuthenticationError(Exception):
class Gitlab(object):
"""Represents a GitLab server connection"""
def __init__(self, url, private_token=None,
email=None, password=None, ssl_verify=True):
email=None, password=None, ssl_verify=True, timeout=None):
"""Stores informations about the server

url: the URL of the Gitlab server
private_token: the user private token
email: the user email/login
password: the user password (associated with email)
ssl_verify: (Passed to requests-library)
timeout: (Passed to requests-library). Timeout to use for requests to
gitlab server. Float or tuple(Float,Float).
"""
self._url = '%s/api/v3' % url
self.timeout = timeout
self.setToken(private_token)
self.email = email
self.password = password
Expand Down Expand Up @@ -141,7 +145,8 @@ def rawGet(self, path, **kwargs):
try:
return requests.get(url,
headers=self.headers,
verify=self.ssl_verify)
verify=self.ssl_verify,
timeout=self.timeout)
except:
raise GitlabConnectionError(
"Can't connect to GitLab server (%s)" % self._url)
Expand All @@ -151,7 +156,8 @@ def rawPost(self, path, data=None):
try:
return requests.post(url, data,
headers=self.headers,
verify=self.ssl_verify)
verify=self.ssl_verify,
timeout=self.timeout)
except:
raise GitlabConnectionError(
"Can't connect to GitLab server (%s)" % self._url)
Expand All @@ -162,7 +168,8 @@ def rawPut(self, path):
try:
return requests.put(url,
headers=self.headers,
verify=self.ssl_verify)
verify=self.ssl_verify,
timeout=self.timeout)
except:
raise GitlabConnectionError(
"Can't connect to GitLab server (%s)" % self._url)
Expand All @@ -173,7 +180,8 @@ def rawDelete(self, path):
try:
return requests.delete(url,
headers=self.headers,
verify=self.ssl_verify)
verify=self.ssl_verify,
timeout=self.timeout)
except:
raise GitlabConnectionError(
"Can't connect to GitLab server (%s)" % self._url)
Expand All @@ -195,7 +203,8 @@ def list(self, obj_class, **kwargs):
["%s=%s" % (k, v) for k, v in args.items()]))

try:
r = requests.get(url, headers=self.headers, verify=self.ssl_verify)
r = requests.get(url, headers=self.headers, verify=self.ssl_verify,
timeout=self.timeout)
except:
raise GitlabConnectionError(
"Can't connect to GitLab server (%s)" % self._url)
Expand Down Expand Up @@ -233,7 +242,8 @@ def get(self, obj_class, id=None, **kwargs):
url = '%s%s' % (self._url, url)

try:
r = requests.get(url, headers=self.headers, verify=self.ssl_verify)
r = requests.get(url, headers=self.headers, verify=self.ssl_verify,
timeout=self.timeout)
except:
raise GitlabConnectionError(
"Can't connect to GitLab server (%s)" % self._url)
Expand All @@ -255,7 +265,8 @@ def delete(self, obj):
try:
r = requests.delete(url,
headers=self.headers,
verify=self.ssl_verify)
verify=self.ssl_verify,
timeout=self.timeout)
except:
raise GitlabConnectionError(
"Can't connect to GitLab server (%s)" % self._url)
Expand Down Expand Up @@ -288,7 +299,8 @@ def create(self, obj):
try:
r = requests.post(url, obj.__dict__,
headers=self.headers,
verify=self.ssl_verify)
verify=self.ssl_verify,
timeout=self.timeout)
except:
raise GitlabConnectionError(
"Can't connect to GitLab server (%s)" % self._url)
Expand Down Expand Up @@ -318,7 +330,8 @@ def update(self, obj):
try:
r = requests.put(url, d,
headers=self.headers,
verify=self.ssl_verify)
verify=self.ssl_verify,
timeout=self.timeout)
except:
raise GitlabConnectionError(
"Can't connect to GitLab server (%s)" % self._url)
Expand Down