Re: [Boa Constr] Unicode sent into ZPythonScript_edit
Status: Beta
Brought to you by:
riaan
From: Riaan B. <riaan@e.co.za> - 2006-04-12 16:18:55
|
Hi Pavel, Pavel Reznicek wrote: > Hello developers, > > I had a small problem using boa-constructor with Zope. I am a beginner > in this region but I took all my courage and submitted a bug on the Zope > development site. You can view it at this address: > http://www.zope.org/Collectors/Zope/2066 > > It happened when I was trying to save a Python script object that I had > downloaded from my Zope instance. The base was that Zope doesn't like > the Python scripts to be written in Unicode. > > Here you have the traceback that showed up to me in boa-constructor in a > message box when I was trying to save the script: > > Unexpected Zope exception: Traceback (most recent call last): File > "/usr/lib/zope/lib/python/ZPublisher/Publish.py", line 175, in > publish_module_standard response = publish(request, module_name, > after_list, debug=debug) File > "/usr/lib/zope/lib/python/ZPublisher/Publish.py", line 132, in publish > sys.exc_info()[2], File > "/usr/lib/zope/lib/python/ZPublisher/Publish.py", line 101, in publish > request, bind=1) File "/usr/lib/zope/lib/python/ZPublisher/mapply.py", > line 88, in mapply if debug is not None: return > debug(object,args,context) File > "/usr/lib/zope/lib/python/ZPublisher/Publish.py", line 39, in > call_object result=apply(object,args) # Type s to step into published > object. File > "/usr/lib/zope/lib/python/Products/PythonScripts/PythonScript.py", line > 133, in ZPythonScriptHTML_editAction self.ZPythonScript_edit(params, > body) File > "/usr/lib/zope/lib/python/Products/PythonScripts/PythonScript.py", line > 149, in ZPythonScript_edit body = body.read() AttributeError: 'unicode' > object has no attribute 'read' > > I saw the last place above in the Zope code and noticed that it counts > only with the str object type, not unicode. I tried then to modify it: > > "/usr/lib/zope/lib/python/Products/PythonScripts/PythonScript.py", line > 149, in ZPythonScript_edit: > > #################################### > if type(body) is not type(''): > #################################### > > to this code: > > #################################### > if type(body) is not type('')\ > and type(body) is not type(u''): > #################################### > > and it worked just fine, boa-constructor saved it in Zope. > > Then, as I tried to edit that script in the ZMI through the browser, > Zope was complaining about bad encoding. It was saved as unicode there > (I have the utf-8 encoding as default in my Python and boa) and Zope > expects to have iso-8859-1 as the default character set. I then changed > the default encoding in Zope and again, it solved the problem in Zope. > > As a result, I can now edit my Zope Python scripts in boa-constructor > and save them and read Unicode. > > BUT I also initiated a patch proposal to the same bug issue. Now the > developers ask if it is wise to save Python scripts in Unicode to Zope. > Maybe it's more due to my settings than your, boa-constructor's > developers' purpose but, it would be nice if the Zope community had your > opinion in this case. > > Thank you all, have nice Easter. > > Pavel Reznicek I'm not sure what the right answer is, but as the Zope developers seem uncomfortable with accepting unicode as input, I guess it should be converted to a string before being posted to Zope. I'll have a look at doing this. Cheers, Riaan. |