##// END OF EJS Templates
bugzilla: make XMLRPC interface support http and https access...
Jim Hague -
r15870:f4c85929 stable
parent child Browse files
Show More
@@ -255,7 +255,7 All the above add a comment to the Bugzi
255 from mercurial.i18n import _
255 from mercurial.i18n import _
256 from mercurial.node import short
256 from mercurial.node import short
257 from mercurial import cmdutil, mail, templater, util
257 from mercurial import cmdutil, mail, templater, util
258 import re, time, xmlrpclib
258 import re, time, urlparse, xmlrpclib
259
259
260 class bzaccess(object):
260 class bzaccess(object):
261 '''Base class for access to Bugzilla.'''
261 '''Base class for access to Bugzilla.'''
@@ -473,17 +473,16 class bzmysql_3_0(bzmysql_2_18):
473
473
474 # Buzgilla via XMLRPC interface.
474 # Buzgilla via XMLRPC interface.
475
475
476 class CookieSafeTransport(xmlrpclib.SafeTransport):
476 class cookietransportrequest(object):
477 """A SafeTransport that retains cookies over its lifetime.
477 """A Transport request method that retains cookies over its lifetime.
478
478
479 The regular xmlrpclib transports ignore cookies. Which causes
479 The regular xmlrpclib transports ignore cookies. Which causes
480 a bit of a problem when you need a cookie-based login, as with
480 a bit of a problem when you need a cookie-based login, as with
481 the Bugzilla XMLRPC interface.
481 the Bugzilla XMLRPC interface.
482
482
483 So this is a SafeTransport which looks for cookies being set
483 So this is a helper for defining a Transport which looks for
484 in responses and saves them to add to all future requests.
484 cookies being set in responses and saves them to add to all future
485 It appears a SafeTransport can do both HTTP and HTTPS sessions,
485 requests.
486 which saves us having to do a CookieTransport too.
487 """
486 """
488
487
489 # Inspiration drawn from
488 # Inspiration drawn from
@@ -537,6 +536,18 class CookieSafeTransport(xmlrpclib.Safe
537
536
538 return unmarshaller.close()
537 return unmarshaller.close()
539
538
539 # The explicit calls to the underlying xmlrpclib __init__() methods are
540 # necessary. The xmlrpclib.Transport classes are old-style classes, and
541 # it turns out their __init__() doesn't get called when doing multiple
542 # inheritance with a new-style class.
543 class cookietransport(cookietransportrequest, xmlrpclib.Transport):
544 def __init__(self, use_datetime=0):
545 xmlrpclib.Transport.__init__(self, use_datetime)
546
547 class cookiesafetransport(cookietransportrequest, xmlrpclib.SafeTransport):
548 def __init__(self, use_datetime=0):
549 xmlrpclib.SafeTransport.__init__(self, use_datetime)
550
540 class bzxmlrpc(bzaccess):
551 class bzxmlrpc(bzaccess):
541 """Support for access to Bugzilla via the Bugzilla XMLRPC API.
552 """Support for access to Bugzilla via the Bugzilla XMLRPC API.
542
553
@@ -553,9 +564,15 class bzxmlrpc(bzaccess):
553 user = self.ui.config('bugzilla', 'user', 'bugs')
564 user = self.ui.config('bugzilla', 'user', 'bugs')
554 passwd = self.ui.config('bugzilla', 'password')
565 passwd = self.ui.config('bugzilla', 'password')
555
566
556 self.bzproxy = xmlrpclib.ServerProxy(bzweb, CookieSafeTransport())
567 self.bzproxy = xmlrpclib.ServerProxy(bzweb, self.transport(bzweb))
557 self.bzproxy.User.login(dict(login=user, password=passwd))
568 self.bzproxy.User.login(dict(login=user, password=passwd))
558
569
570 def transport(self, uri):
571 if urlparse.urlparse(uri, "http")[0] == "https":
572 return cookiesafetransport()
573 else:
574 return cookietransport()
575
559 def get_bug_comments(self, id):
576 def get_bug_comments(self, id):
560 """Return a string with all comment text for a bug."""
577 """Return a string with all comment text for a bug."""
561 c = self.bzproxy.Bug.comments(dict(ids=[id]))
578 c = self.bzproxy.Bug.comments(dict(ids=[id]))
General Comments 0
You need to be logged in to leave comments. Login now