""" The XMLRPC client """ import string, xmlrpclib, httplib from base64 import encodestring class BasicAuthTransport(xmlrpclib.Transport): """ taken from http://www.zope.org/Members/Amos/XML-RPC """ def __init__(self, username=None, password=None, verbose=0): self.username=username self.password=password self.verbose=verbose def request(self, host, handler, request_body, verbose=0): h = httplib.HTTP(host) h.putrequest("POST", handler) h.putheader("Host", host) h.putheader("User-Agent", self.user_agent) h.putheader("Content-Type", "text/xml") h.putheader("Content-Length", str(len(request_body))) # basic auth if self.username is not None and self.password is not None: h.putheader("AUTHORIZATION", "Basic %s" % string.replace( encodestring("%s:%s" % (self.username, self.password)), "\012", "")) h.endheaders() if request_body: h.send(request_body) errcode, errmsg, headers = h.getreply() if errcode != 200: raise xmlrpclib.ProtocolError( host + handler, errcode, errmsg, headers ) return self.parse_response(h.getfile()) if __name__=='__main__': d=xmlrpclib.Server('http://pynchon.runyaga.com:8080/', BasicAuthTransport('runyaga','%&#password($@') ) from StringIO import StringIO str_obj = None try: f = open('c:\\tmp\\dreamweaver.exe', 'rb') str_obj = encodestring( f.read() ) f.close() del f #in my example the 'putFileOnfilesystem' External Method was in the root of the ZODB #if yours in a a folder called test you would call d.test.putFileOnFilesytem(... d.putFileOnFilesystem('dreamweaver.exe', str_obj) finally: del str_obj del d """ on the server create a file in $ZOPE/Extensions called xmlrpc.py """ from base64 import decodestring from StringIO import StringIO def put_fileOnFilesystem(file_id, file_obj): """ puts the file on the file system """ file = StringIO() data = decodestring(file_obj) fd = open('/tmp/'+file_id, 'wb') file.write(data) file.seek(0) fd.write( file.read() ) fd.close() del file del data """ in the ZODB create a External Method: """ ID = putFileOnFilesystem module = xmlrpc (name of the $ZOPE/Extnesions file w/o the .py) function = put_fileOnFilesystem