[Zope] XML-RPC from Python

Andy McKay andym@ActiveState.com
Fri, 20 Jul 2001 15:18:00 -0700


This is a multi-part message in MIME format.

------=_NextPart_000_0023_01C1112F.2992DBB0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: 7bit

To add SOAP support go here: http://www.ppetru.net/software/index.html

soaplibBasicAuth.py is attached, it requires soaplib.

Cheers.
--
  Andy McKay.


----- Original Message -----
From: "Brad Clements" <bkc@murkworks.com>
To: "Andy McKay" <andym@ActiveState.com>; <zope@zope.org>
Sent: Friday, July 20, 2001 2:08 PM
Subject: Re: [Zope] XML-RPC from Python


> On 20 Jul 2001, at 12:15, Andy McKay wrote:
>
> > Absolutely. It would be easier though just to include the relevant
xml-rpc
> > basic auth module with Zope. While we are at I wrote a similar one for
SOAP
> > (after patching Zope to actually work with SOAP).
> >
> > Cheers.
> > --
> >   Andy McKay.
>
>
> Whatsit!? You got Zope to handle Soap requests?
>
> That I need!
>

------=_NextPart_000_0023_01C1112F.2992DBB0
Content-Type: application/octet-stream;
	name="soaplibBasicAuth.py"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="soaplibBasicAuth.py"

import string, soaplib, httplib=0D
from base64 import encodestring=0D
=0D
def ServerProxy(url, username, password):=0D
    t =3D BasicAuthTransport(username, password)=0D
    return soaplib.ServerProxy(url, t)=0D
=0D
class BasicAuthTransport(soaplib.Transport):=0D
    def __init__(self, username=3DNone, password=3DNone):=0D
        self.username =3D username=0D
        self.password =3D password=0D
=0D
    def request(self, host, handler, request_body):=0D
        h =3D httplib.HTTP(host)=0D
        h.debuglevel =3D 0=0D
        h.putrequest("POST", handler)=0D
=0D
        # required by HTTP/1.1=0D
        h.putheader("Host", host)=0D
=0D
        if h.debuglevel > 0:=0D
            print "-- REQUEST --"=0D
            print request_body=0D
=0D
        # required by SOAP=0D
        h.putheader("User-Agent", self.user_agent)=0D
        h.putheader("Content-Type", "text/xml")=0D
        h.putheader("Content-Length", str(len(request_body)))=0D
        h.putheader("Authorization", "Basic %s" % string.replace(encodestri=
ng("%s:%s" % (self.username, self.password)), "\012", ""))=0D
        h.putheader("SOAPAction", '""')=0D
=0D
        h.endheaders()=0D
=0D
        if request_body:=0D
            h.send(request_body)=0D
=0D
        errcode, errmsg, headers =3D h.getreply()=0D
=0D
        if h.debuglevel > 0:=0D
            print "-- RESPONSE --"=0D
            print errcode, errmsg, headers=0D
=0D
        if errcode not in (200, 500):=0D
            raise ProtocolError(=0D
                host + handler,=0D
                errcode, errmsg,=0D
                headers=0D
                )=0D
=0D
        response =3D self.parse_response(h.getfile())=0D
=0D
        # should this really be done in here?=0D
        response =3D response[1]=0D
        if len(response) =3D=3D 1:=0D
            response =3D response[0]=0D
=0D
        return response
------=_NextPart_000_0023_01C1112F.2992DBB0--