[Zope-dev] Unicode treatment in 2.6b1 [TRACEBACK]
Andreas Kostyrka
andreas@kostyrka.priv.at
27 Sep 2002 16:42:18 +0200
Hi!
I've traced back the source of my UTF-8 + plain string problem.
My python script calls manage_changeProperties like this:
request = container.REQUEST
RESPONSE = request.RESPONSE
standorte=request['standorte'].replace(', ',',')
context.manage_changeProperties({'standorte':standorte})
return context.index_html(context,request)
Now if I comment out the manage_changeProperties, it works ok, but of
course does not change the property.
Andreas
Following are the exact tracebacks I've generated:
Am Fre, 2002-09-27 um 12.54 schrieb Andreas Kostyrka:
> Am Fre, 2002-09-27 um 11.30 schrieb Toby Dickenson:
> > On Friday 27 Sep 2002 10:16 am, Andreas Kostyrka wrote:
> >
> > > Now in some cases ZPublisher adds the UTF-8 content-type
> >
> > To a response header? I fairly sure ZPublisher never does that.
> Well, someone does. I do not :)
> >
> > Perhaps you could add some debugging hooks to RESPONSE.setHeader to see who
> > is?
> I'll look into that.
Well, I've added a traceback.print_stack like this:
Index: HTTPResponse.py
===================================================================
RCS file: /cvs-repository/Zope/lib/python/ZPublisher/HTTPResponse.py,v
retrieving revision 1.70
diff -u -u -r1.70 HTTPResponse.py
--- HTTPResponse.py 24 Sep 2002 22:13:26 -0000 1.70
+++ HTTPResponse.py 27 Sep 2002 14:37:49 -0000
@@ -17,6 +17,7 @@
import types, os, sys, re
import zlib, struct
+import traceback
from string import translate, maketrans
from types import StringType, InstanceType, LongType, UnicodeType
from BaseResponse import BaseResponse
@@ -240,6 +241,8 @@
return
name = literal and name or key
self.headers[name] = value
+ if name.upper()=="CONTENT-TYPE" and value.find("UTF")<>-1:
+ traceback.print_stack()
def addHeader(self, name, value):
'''\
It produced:
File "/home/andreas/Zope/ZServer/PubCore/ZServerPublisher.py", line
23, in __init__
response=response)
File "/home/andreas/Zope/lib/python/ZPublisher/Publish.py", line 150,
in publish_module
response = publish(request, module_name, after_list, debug=debug)
File "/home/andreas/Zope/lib/python/ZPublisher/Publish.py", line 98,
in publish
request, bind=1)
File "/home/andreas/Zope/lib/python/ZPublisher/mapply.py", line 88, in
mapply
if debug is not None: return debug(object,args,context)
File "/home/andreas/Zope/lib/python/ZPublisher/Publish.py", line 39,
in call_object
result=apply(object,args) # Type s<cr> to step into published
object.
File "/home/andreas/Zope/lib/python/Shared/DC/Scripts/Bindings.py",
line 252, in __call__
return self._bindAndExec(args, kw, None)
File "/home/andreas/Zope/lib/python/Shared/DC/Scripts/Bindings.py",
line 283, in _bindAndExec
return self._exec(bound_data, args, kw)
File
"/home/andreas/Zope/lib/python/Products/PythonScripts/PythonScript.py",
line 315, in _exec
result = apply(f, args, kw)
File "Script (Python)", line 9, in setStandorte
File "/home/andreas/Zope/lib/python/OFS/PropertyManager.py", line 289,
in manage_changeProperties
return
self.manage_propertiesForm(self,REQUEST,manage_tabs_message=message)
File "/home/andreas/Zope/lib/python/Shared/DC/Scripts/Bindings.py",
line 252, in __call__
return self._bindAndExec(args, kw, None)
File "/home/andreas/Zope/lib/python/Shared/DC/Scripts/Bindings.py",
line 283, in _bindAndExec
return self._exec(bound_data, args, kw)
File "/home/andreas/Zope/lib/python/App/special_dtml.py", line 174, in
_exec
try: result = render_blocks(self._v_blocks, ns)
File "/home/andreas/Zope/lib/python/Shared/DC/Scripts/Bindings.py",
line 266, in __render_with_namespace__
return self._bindAndExec((), namevals, namespace)
File "/home/andreas/Zope/lib/python/Shared/DC/Scripts/Bindings.py",
line 283, in _bindAndExec
return self._exec(bound_data, args, kw)
File "/home/andreas/Zope/lib/python/App/special_dtml.py", line 174, in
_exec
try: result = render_blocks(self._v_blocks, ns)
File "/home/andreas/Zope/lib/python/DocumentTemplate/DT_Util.py", line
201, in eval
return eval(code, d)
File "<string>", line 0, in ?
File "/home/andreas/Zope/lib/python/ZPublisher/HTTPResponse.py", line
245, in setHeader
traceback.print_stack()
The related PythonScript does a
return context.index_html(context,request) at this place. Further
investigation asserts that the value returned from this expression is a
plain text with 8bit characters in it. In fact adding u'' to it breaks
of this.
Andreas
--
Andreas Kostyrka <andreas@kostyrka.priv.at>