From 859f5658745b74e0e39a491ae0281adda023471c Mon Sep 17 00:00:00 2001 From: Ben Hearsum Date: Tue, 30 Jul 2013 14:00:13 -0400 Subject: [PATCH] Add support for Python 2.7, which has a vastly different xmlrpclib. --- pyzilla.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pyzilla.py b/pyzilla.py index 9d4e240..16be494 100644 --- a/pyzilla.py +++ b/pyzilla.py @@ -76,7 +76,17 @@ def info(self): # creating a cookie jar for my cookies cj = cookielib.LWPCookieJar() self.send_content(h, request_body) - errcode, errmsg, headers = h.getreply() + try: + # In Python <= 2.6, h is an HTTP object, which has a nice + # "getreply" method. + errcode, errmsg, headers = h.getreply() + except AttributeError: + # In other reasons we have an HTTPConnection, which has a + # different interface + resp = h.getresponse() + errcode = resp.status + errmsg = resp.reason + headers = resp.msg cresponse = CookieResponse(headers) cj.extract_cookies(cresponse, crequest) if len(cj) >0 and not os.path.exists(self.cookiefile): @@ -88,9 +98,10 @@ def info(self): self.verbose = verbose try: sock = h._conn.sock + return self._parse_response(h.getfile(), sock) except AttributeError: sock = None - return self._parse_response(h.getfile(), sock) + return self.parse_response(resp) class BugZilla(xmlrpclib.Server): def __init__(self, url, verbose = False, cookiefile = None,