From f3ba366a69c53910747dcc412fb693d0287bb5cb Mon Sep 17 00:00:00 2001 From: Ken Dreyer Date: Tue, 17 Apr 2018 02:52:35 -0600 Subject: [PATCH] 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 --- jenkins/__init__.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/jenkins/__init__.py b/jenkins/__init__.py index baa209a..4da66c1 100755 --- a/jenkins/__init__.py +++ b/jenkins/__init__.py @@ -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