[Zope-dev] external method problems (ARGH!)

auto44082@hushmail.com auto44082@hushmail.com
Wed, 1 Mar 2000 08:07:23 -0800 (PST)


Hello,

I tried posting this to the zope list, but then thought it might be more 
appropriat here.
I'm getting grief from an external python, method and I'm hoping that someone 
has some ideas that might help. Here's what I'm doing.

I have a Zope product (SmartDTML) consisting of a Zclass which inherrits 
a DTML Document. I've heavily modified the constructor DTML Method, and 
among other things it calls some external python code which takes an uploaded 
file, converts it, and then preloads it into the DTML document via the munge() 
method. (I've included the code below)

The external python code can be run from two places. 1. it runs automatically 
when you add a new instance of SmartDTML. and 2. from the Upload tab of 
the newly created SmartDTML instance . Well when called from the object's 
constructor, my external code runs and works just fine. But when called 
from the Upload tab, I keep getting "read-only character buffer, instance" 
errors out of zope. I have an indistinct feeling that it might have something 
to do with permissions but I don't know enough about Zope yet to know whether 
or not that is a valid hunch.

Incidentally, this product I'm working on is a supposed to be a modified 
DTML Document which knows how to convert MSWord documents to HTML automatically.

Here's the offending python code:
#upload_file is an object property containing the uploaded file if available,
#convert is a text field indicating whether or not DOC->HTML conversion 
should be done or not
def convertFile(self):
        import os
        """Converts MSWord Documents to HTML"""
        if self.convert == 'YES' and self.upload_file != '':
                #convert upload_file to HTML
                f=open('./Extensions/tempfile.doc', 'w') #creat a temp file
                testvar = self.upload_file
                f.write(testvar)
                f.close() #convert it
                os.system('wvHtml ./Extensions/tempfile.doc > ./Extensions/tempfile.html')
                f=open('./Extensions/tempfile.html', 'r')
                testvar = f.read()
                self.munge(testvar)
                f.close()
                os.remove('./Extensions/tempfile.doc') #clean up after ourselves
                os.remove('./Extensions/tempfile.html')
        else:
                #no conversion
                if self.upload_file == '':
                #no upload_file so give it a standard header & footer
                        testvar = "<dtml-var standard_html_header>\n\
<h2><dtml-var title_or_id></h2>\n<p>\nThis is the <dtml-var id> Document.\n\
</p>\n<dtml-var standard_dtml_footer>"

                else:
            #already html, no conversion needed
                        testvar = self.upload_file

                self.munge(testvar)




IMPORTANT NOTICE:  If you are not using HushMail, this message could have been read easily by the many people who have access to your open personal email messages.
Get your FREE, totally secure email address at http://www.hushmail.com.