File contents
from Shared.UoB.xmlrpclibBasicAuth import Server
import xmlrpclib, base64, exceptions
zlave_url = 'http://your.zope.server/path/to/folder/containing/external/methods'
class xmlrpc_error(exceptions.Exception):
def __init__(self, args=None):
self.args = args
def word2html(self, url, worddoc, id,):
#Stop the passed in url value from being used - temporary measure
url = zlave_url
#Connect to the server/url
s = Server(url, 'user', 'pass')
#Put returned values into suitable variables
html, images = s.word2html(base64.encodestring(worddoc), str(self.REQUEST.AUTHENTICATED_USER))
#Check to see if an error was returned in place of what you really wanted
if html == 'Error':
"""
If there are any, error details from the zlave server are returned
as the second value, in this case, 'images'
"""
raise xmlrpc_error, images
else:
#If no error, keep going
#Remember that the html was base64 encoded
html = base64.decodestring(html)
for each in images.keys():
images[each] = base64.decodestring(images[each])
return html, images
def word_doc(self, url):
#Stop the passed in url value from being used - temporary measure
url = zlave_url
s = Server(url, 'user', 'pass')
word_doc = base64.decodestring(s.html2word(base64.encodestring(self.index_html())))
self.REQUEST.RESPONSE.setHeader('content-type', 'application/msword')
self.REQUEST.RESPONSE.setHeader('content-length', len(word_doc))
self.REQUEST.RESPONSE.setHeader('content-disposition', 'attachment;filename='+self.id+'.doc')
return word_doc
def ppt2html(self, url, pptdoc, id):
#Stop the passed in url value from being used - temporary measure
url = zlave_url
s = Server(url, 'user', 'pass')
images = s.ppt2html(base64.encodestring(pptdoc), str(self.REQUEST.AUTHENTICATED_USER))
if images.has_key('null'):
raise xmlrpc_error, 'No Slides returned!'
elif images.has_key('Error'):
raise xmlrpc_error, images['Error']
else:
for key in images.keys():
images[key] = base64.decodestring(images[key])
return images
def xl2html(self, url, xldoc, id,):
#Stop the passed in url value from being used - temporary measure
url = zlave_url
#Connect to the server/url
s = Server(url, 'user', 'pass')
#Put returned values into suitable variables
html, images = s.xl2html(base64.encodestring(xldoc), str(self.REQUEST.AUTHENTICATED_USER))
#Check to see if an error was returned in place of what you really wanted
if html == 'Error':
"""
If there are any, error details from the zlave server are returned
as the second value, in this case, 'images'
"""
raise xmlrpc_error, images
else:
#If no error, keep going
#Remember that the html was base64 encoded
html = base64.decodestring(html)
for each in images.keys():
images[each] = base64.decodestring(images[each])
return html, images