view MoinMoin/support/ @ 35:f0af060fb82b

making people choose the right approach to page_front_page imported from: moin--main--1.5--patch-36
author Thomas Waldmann <>
date Sun, 25 Sep 2005 14:45:38 +0000
parents 77665d8e2254
children c1c0d7f6f2b4
line wrap: on
line source
# taken from Amos' XML-RPC HowTo:

import string, xmlrpclib, httplib
from base64 import encodestring

class BasicAuthTransport(xmlrpclib.Transport):
    def __init__(self, username=None, password=None):

    def request(self, host, handler, request_body, **kw):
        # issue XML-RPC request
        h = httplib.HTTP(host)
        h.putrequest("POST", handler)

        # required by HTTP/1.1
        h.putheader("Host", host)

        # required by XML-RPC
        h.putheader("User-Agent", self.user_agent)
        h.putheader("Content-Type", "text/xml")
        h.putheader("Content-Length", str(len(request_body)))
        #h.putheader("Connection", "close") # TW XXX just trying if that cures twisted ...

        # basic auth
        if self.username is not None and self.password is not None:
            authhdr = "Basic %s" % string.replace(
                    encodestring("%s:%s" % (self.username, self.password)),
                    "\012", "")
            h.putheader("Authorization", authhdr)

        if request_body:

        errcode, errmsg, headers = h.getreply()

        if errcode != 200:
            raise xmlrpclib.ProtocolError(
                host + handler,
                errcode, errmsg,

        return self.parse_response(h.getfile())