[python-bugzilla] [PATCH] Fix bugzilla detection behind proxy
Cole Robinson
crobinso at redhat.com
Thu Mar 20 17:09:17 UTC 2014
On 03/14/2014 05:58 AM, Jani Nikula wrote:
> Python requests handles proxying, use it also during bugzilla detection
> phase. Don't bother with cookies at this point.
> ---
> bugzilla/__init__.py | 3 ++-
> bugzilla/base.py | 15 ++++++++-------
> 2 files changed, 10 insertions(+), 8 deletions(-)
>
> diff --git a/bugzilla/__init__.py b/bugzilla/__init__.py
> index e6fdeef03566..95bf53875c1e 100644
> --- a/bugzilla/__init__.py
> +++ b/bugzilla/__init__.py
> @@ -26,6 +26,7 @@ log = getLogger("bugzilla")
>
> from bugzilla.base import BugzillaBase as _BugzillaBase
> from bugzilla.base import BugzillaError
> +from bugzilla.base import RequestsTransport
> from bugzilla.bugzilla3 import Bugzilla3, Bugzilla32, Bugzilla34, Bugzilla36
> from bugzilla.bugzilla4 import Bugzilla4, Bugzilla42, Bugzilla44
> from bugzilla.rhbugzilla import RHBugzilla, RHBugzilla3, RHBugzilla4
> @@ -39,7 +40,7 @@ class NovellBugzilla(Bugzilla34):
> def getBugzillaClassForURL(url):
> url = Bugzilla3.fix_url(url)
> log.debug("Detecting subclass for %s", url)
> - s = ServerProxy(url)
> + s = ServerProxy(url, RequestsTransport(url))
> rhbz = False
> bzversion = ''
> c = None
> diff --git a/bugzilla/base.py b/bugzilla/base.py
> index bb7b9405bf1c..4553e1c3cdc7 100644
> --- a/bugzilla/base.py
> +++ b/bugzilla/base.py
> @@ -108,7 +108,7 @@ def _build_cookiejar(cookiefile):
> class RequestsTransport(Transport):
> user_agent = 'Python/Bugzilla'
>
> - def __init__(self, url, cookiejar,
> + def __init__(self, url, cookiejar=None,
> sslverify=True, sslcafile=None, debug=0):
> # pylint: disable=W0231
> # pylint does not handle multiple import of Transport well
> @@ -128,7 +128,7 @@ class RequestsTransport(Transport):
>
> self.request_defaults = {
> 'cert': sslcafile if self.use_https else None,
> - 'cookies': cookiejar,
> + 'cookies': cookiejar if cookiejar else None,
> 'verify': sslverify,
> 'headers': {
> 'Content-Type': 'text/xml',
> @@ -157,12 +157,13 @@ class RequestsTransport(Transport):
> response.encoding = 'UTF-8'
>
> # update/set any cookies
> - for cookie in response.cookies:
> - self._cookiejar.set_cookie(cookie)
> + if self._cookiejar is not None:
> + for cookie in response.cookies:
> + self._cookiejar.set_cookie(cookie)
>
> - if self._cookiejar.filename is not None:
> - # Save is required only if we have a filename
> - self._cookiejar.save()
> + if self._cookiejar.filename is not None:
> + # Save is required only if we have a filename
> + self._cookiejar.save()
>
> response.raise_for_status()
> return self.parse_response(response)
>
Thanks for the patch. ACK, and pushed now.
- Cole
More information about the python-bugzilla
mailing list