| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -75,15 +75,19 @@ class GitlabAuthenticationError(Exception): | |||
| 75 | 75 | class Gitlab(object): | |
| 76 | 76 | """Represents a GitLab server connection""" | |
| 77 | 77 | def __init__(self, url, private_token=None, | |
| 78 | - email=None, password=None, ssl_verify=True): | ||
| 78 | + email=None, password=None, ssl_verify=True, timeout=None): | ||
| 79 | 79 | """Stores informations about the server | |
| 80 | 80 | ||
| 81 | 81 | url: the URL of the Gitlab server | |
| 82 | 82 | private_token: the user private token | |
| 83 | 83 | email: the user email/login | |
| 84 | 84 | password: the user password (associated with email) | |
| 85 | + ssl_verify: (Passed to requests-library) | ||
| 86 | + timeout: (Passed to requests-library). Timeout to use for requests to | ||
| 87 | + gitlab server. Float or tuple(Float,Float). | ||
| 85 | 88 | """ | |
| 86 | 89 | self._url = '%s/api/v3' % url | |
| 90 | + self.timeout = timeout | ||
| 87 | 91 | self.setToken(private_token) | |
| 88 | 92 | self.email = email | |
| 89 | 93 | self.password = password | |
@@ -141,7 +145,8 @@ def rawGet(self, path, **kwargs): | |||
| 141 | 145 | try: | |
| 142 | 146 | return requests.get(url, | |
| 143 | 147 | headers=self.headers, | |
| 144 | - verify=self.ssl_verify) | ||
| 148 | + verify=self.ssl_verify, | ||
| 149 | + timeout=self.timeout) | ||
| 145 | 150 | except: | |
| 146 | 151 | raise GitlabConnectionError( | |
| 147 | 152 | "Can't connect to GitLab server (%s)" % self._url) | |
@@ -151,7 +156,8 @@ def rawPost(self, path, data=None): | |||
| 151 | 156 | try: | |
| 152 | 157 | return requests.post(url, data, | |
| 153 | 158 | headers=self.headers, | |
| 154 | - verify=self.ssl_verify) | ||
| 159 | + verify=self.ssl_verify, | ||
| 160 | + timeout=self.timeout) | ||
| 155 | 161 | except: | |
| 156 | 162 | raise GitlabConnectionError( | |
| 157 | 163 | "Can't connect to GitLab server (%s)" % self._url) | |
@@ -162,7 +168,8 @@ def rawPut(self, path): | |||
| 162 | 168 | try: | |
| 163 | 169 | return requests.put(url, | |
| 164 | 170 | headers=self.headers, | |
| 165 | - verify=self.ssl_verify) | ||
| 171 | + verify=self.ssl_verify, | ||
| 172 | + timeout=self.timeout) | ||
| 166 | 173 | except: | |
| 167 | 174 | raise GitlabConnectionError( | |
| 168 | 175 | "Can't connect to GitLab server (%s)" % self._url) | |
@@ -173,7 +180,8 @@ def rawDelete(self, path): | |||
| 173 | 180 | try: | |
| 174 | 181 | return requests.delete(url, | |
| 175 | 182 | headers=self.headers, | |
| 176 | - verify=self.ssl_verify) | ||
| 183 | + verify=self.ssl_verify, | ||
| 184 | + timeout=self.timeout) | ||
| 177 | 185 | except: | |
| 178 | 186 | raise GitlabConnectionError( | |
| 179 | 187 | "Can't connect to GitLab server (%s)" % self._url) | |
@@ -195,7 +203,8 @@ def list(self, obj_class, **kwargs): | |||
| 195 | 203 | ["%s=%s" % (k, v) for k, v in args.items()])) | |
| 196 | 204 | ||
| 197 | 205 | try: | |
| 198 | - r = requests.get(url, headers=self.headers, verify=self.ssl_verify) | ||
| 206 | + r = requests.get(url, headers=self.headers, verify=self.ssl_verify, | ||
| 207 | + timeout=self.timeout) | ||
| 199 | 208 | except: | |
| 200 | 209 | raise GitlabConnectionError( | |
| 201 | 210 | "Can't connect to GitLab server (%s)" % self._url) | |
@@ -233,7 +242,8 @@ def get(self, obj_class, id=None, **kwargs): | |||
| 233 | 242 | url = '%s%s' % (self._url, url) | |
| 234 | 243 | ||
| 235 | 244 | try: | |
| 236 | - r = requests.get(url, headers=self.headers, verify=self.ssl_verify) | ||
| 245 | + r = requests.get(url, headers=self.headers, verify=self.ssl_verify, | ||
| 246 | + timeout=self.timeout) | ||
| 237 | 247 | except: | |
| 238 | 248 | raise GitlabConnectionError( | |
| 239 | 249 | "Can't connect to GitLab server (%s)" % self._url) | |
@@ -255,7 +265,8 @@ def delete(self, obj): | |||
| 255 | 265 | try: | |
| 256 | 266 | r = requests.delete(url, | |
| 257 | 267 | headers=self.headers, | |
| 258 | - verify=self.ssl_verify) | ||
| 268 | + verify=self.ssl_verify, | ||
| 269 | + timeout=self.timeout) | ||
| 259 | 270 | except: | |
| 260 | 271 | raise GitlabConnectionError( | |
| 261 | 272 | "Can't connect to GitLab server (%s)" % self._url) | |
@@ -288,7 +299,8 @@ def create(self, obj): | |||
| 288 | 299 | try: | |
| 289 | 300 | r = requests.post(url, obj.__dict__, | |
| 290 | 301 | headers=self.headers, | |
| 291 | - verify=self.ssl_verify) | ||
| 302 | + verify=self.ssl_verify, | ||
| 303 | + timeout=self.timeout) | ||
| 292 | 304 | except: | |
| 293 | 305 | raise GitlabConnectionError( | |
| 294 | 306 | "Can't connect to GitLab server (%s)" % self._url) | |
@@ -318,7 +330,8 @@ def update(self, obj): | |||
| 318 | 330 | try: | |
| 319 | 331 | r = requests.put(url, d, | |
| 320 | 332 | headers=self.headers, | |
| 321 | - verify=self.ssl_verify) | ||
| 333 | + verify=self.ssl_verify, | ||
| 334 | + timeout=self.timeout) | ||
| 322 | 335 | except: | |
| 323 | 336 | raise GitlabConnectionError( | |
| 324 | 337 | "Can't connect to GitLab server (%s)" % self._url) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments