Skip to content

Commit

Permalink
bugzilla: import module names instead of individual function names
Browse files Browse the repository at this point in the history
  • Loading branch information
williamh committed Aug 4, 2012
1 parent 3721173 commit 69cd71a
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions bugz/bugzilla.py
Expand Up @@ -4,38 +4,37 @@
# following URL: # following URL:
# http://www.bugzilla.org/docs/4.2/en/html/api/Bugzilla/WebService.html # http://www.bugzilla.org/docs/4.2/en/html/api/Bugzilla/WebService.html


from cookielib import CookieJar import cookielib
from urllib import splittype, splithost, splituser, splitpasswd import urllib
from urllib2 import build_opener, HTTPBasicAuthHandler, HTTPCookieProcessor import urllib2
from urllib2 import HTTPPasswordMgrWithDefaultRealm, Request import xmlrpclib
from xmlrpclib import ProtocolError, ServerProxy, Transport


class RequestTransport(Transport): class RequestTransport(xmlrpclib.Transport):
def __init__(self, uri, cookiejar=None, use_datetime=0): def __init__(self, uri, cookiejar=None, use_datetime=0):
Transport.__init__(self, use_datetime=use_datetime) xmlrpclib.Transport.__init__(self, use_datetime=use_datetime)


self.opener = build_opener() self.opener = urllib2.build_opener()


# Parse auth (user:passwd) from the uri # Parse auth (user:passwd) from the uri
urltype, rest = splittype(uri) urltype, rest = urllib.splittype(uri)
host, rest = splithost(rest) host, rest = urllib.splithost(rest)
auth, host = splituser(host) auth, host = urllib.splituser(host)
self.uri = urltype + '://' + host + rest self.uri = urltype + '://' + host + rest


# Handle HTTP Basic authentication # Handle HTTP Basic authentication
if auth is not None: if auth is not None:
user, passwd = splitpasswd(auth) user, passwd = urllib.splitpasswd(auth)
passwdmgr = HTTPPasswordMgrWithDefaultRealm() passwdmgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
passwdmgr.add_password(realm=None, uri=self.uri, user=user, passwd=passwd) passwdmgr.add_password(realm=None, uri=self.uri, user=user, passwd=passwd)
authhandler = HTTPBasicAuthHandler(passwdmgr) authhandler = urllib2.HTTPBasicAuthHandler(passwdmgr)
self.opener.add_handler(authhandler) self.opener.add_handler(authhandler)


# Handle HTTP Cookies # Handle HTTP Cookies
if cookiejar is not None: if cookiejar is not None:
self.opener.add_handler(HTTPCookieProcessor(cookiejar)) self.opener.add_handler(urllib2.HTTPCookieProcessor(cookiejar))


def request(self, host, handler, request_body, verbose=0): def request(self, host, handler, request_body, verbose=0):
req = Request(self.uri) req = urllib2.Request(self.uri)
req.add_header('User-Agent', self.user_agent) req.add_header('User-Agent', self.user_agent)
req.add_header('Content-Type', 'text/xml') req.add_header('Content-Type', 'text/xml')


Expand All @@ -56,17 +55,17 @@ def request(self, host, handler, request_body, verbose=0):
return self.parse_response(resp) return self.parse_response(resp)


resp.close() resp.close()
raise ProtocolError(self.uri, resp.status, resp.reason, resp.msg) raise xmlrpclib.ProtocolError(self.uri, resp.status, resp.reason, resp.msg)


class BugzillaProxy(ServerProxy): class BugzillaProxy(xmlrpclib.ServerProxy):
def __init__(self, uri, encoding=None, verbose=0, allow_none=0, def __init__(self, uri, encoding=None, verbose=0, allow_none=0,
use_datetime=0, cookiejar=None): use_datetime=0, cookiejar=None):


if cookiejar is None: if cookiejar is None:
cookiejar = CookieJar() cookiejar = cookielib.CookieJar()


transport = RequestTransport(use_datetime=use_datetime, uri=uri, transport = RequestTransport(use_datetime=use_datetime, uri=uri,
cookiejar=cookiejar) cookiejar=cookiejar)
ServerProxy.__init__(self, uri=uri, transport=transport, xmlrpclib.ServerProxy.__init__(self, uri=uri, transport=transport,
encoding=encoding, verbose=verbose, allow_none=allow_none, encoding=encoding, verbose=verbose, allow_none=allow_none,
use_datetime=use_datetime) use_datetime=use_datetime)

0 comments on commit 69cd71a

Please sign in to comment.