add jenkins_request() method

Move the main pieces of the jenkins_open() method out into a new
jenkins_request() method.

This makes the raw requests.Response object available to other callers,
so they can access things that were not in the response's body string,
such as the response headers.

Change-Id: I1f4049899cf3fa25e6159c416a325419b91e322e
Closes-Bug: #1724932
This commit is contained in:
Ken Dreyer 2018-04-17 02:52:35 -06:00
parent 08f76f724d
commit f3ba366a69
1 changed files with 14 additions and 2 deletions

View File

@ -525,9 +525,21 @@ class Jenkins(object):
return self._session.send(r, **_settings)
def jenkins_open(self, req, add_crumb=True, resolve_auth=True):
'''Return the HTTP response body from a ``requests.Request``.
:returns: ``str``
'''
return self.jenkins_request(req, add_crumb, resolve_auth).text
def jenkins_request(self, req, add_crumb=True, resolve_auth=True):
'''Utility routine for opening an HTTP request to a Jenkins server.
This should only be used to extend the :class:`Jenkins` API.
:param req: A ``requests.Request`` to submit.
:param add_crumb: If True, try to add a crumb header to this ``req``
before submitting. Defaults to ``True``.
:param resolve_auth: If True, maybe add authentication. Defaults to
``True``.
:returns: A ``requests.Response`` object.
'''
try:
if resolve_auth:
@ -536,7 +548,7 @@ class Jenkins(object):
self.maybe_add_crumb(req)
return self._response_handler(
self._request(req)).text
self._request(req))
except req_exc.HTTPError as e:
# Jenkins's funky authentication means its nigh impossible to