##// 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 255 from mercurial.i18n import _
256 256 from mercurial.node import short
257 257 from mercurial import cmdutil, mail, templater, util
258 import re, time, xmlrpclib
258 import re, time, urlparse, xmlrpclib
259 259
260 260 class bzaccess(object):
261 261 '''Base class for access to Bugzilla.'''
@@ -473,17 +473,16 class bzmysql_3_0(bzmysql_2_18):
473 473
474 474 # Buzgilla via XMLRPC interface.
475 475
476 class CookieSafeTransport(xmlrpclib.SafeTransport):
477 """A SafeTransport that retains cookies over its lifetime.
476 class cookietransportrequest(object):
477 """A Transport request method that retains cookies over its lifetime.
478 478
479 479 The regular xmlrpclib transports ignore cookies. Which causes
480 480 a bit of a problem when you need a cookie-based login, as with
481 481 the Bugzilla XMLRPC interface.
482 482
483 So this is a SafeTransport which looks for cookies being set
484 in responses and saves them to add to all future requests.
485 It appears a SafeTransport can do both HTTP and HTTPS sessions,
486 which saves us having to do a CookieTransport too.
483 So this is a helper for defining a Transport which looks for
484 cookies being set in responses and saves them to add to all future
485 requests.
487 486 """
488 487
489 488 # Inspiration drawn from
@@ -537,6 +536,18 class CookieSafeTransport(xmlrpclib.Safe
537 536
538 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 551 class bzxmlrpc(bzaccess):
541 552 """Support for access to Bugzilla via the Bugzilla XMLRPC API.
542 553
@@ -553,9 +564,15 class bzxmlrpc(bzaccess):
553 564 user = self.ui.config('bugzilla', 'user', 'bugs')
554 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 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 576 def get_bug_comments(self, id):
560 577 """Return a string with all comment text for a bug."""
561 578 c = self.bzproxy.Bug.comments(dict(ids=[id]))
General Comments 0
You need to be logged in to leave comments. Login now