[Zope3-Users] Re: why does HTTPResponse insist on a text mime type
for unicode?
Philipp von Weitershausen
philipp at weitershausen.de
Thu Jun 29 14:58:57 EDT 2006
Stefan Rank wrote:
> I am trying to make my content object IExternallyEditable, and I ran up
> against the following code in
> zope.publisher.http.HTTPResult._implicitResult (line 849ff)::
>
> if isinstance(body, unicode):
> try:
> if not content_type.startswith('text/'):
> raise ValueError(
> 'Unicode results must have a text content type,'
> 'got %s.' % content_type)
> except AttributeError:
> raise ValueError(
> 'Unicode results must have a text content type.')
>
> (note: the first raise originally did not give the feedback about the
> received content type.)
>
> And my question is: Why? (do unicode results need to have a text/* type)
Unicode can't be sent over the wire. Hence the publisher will have to
encode it with a proper encoding (e.g. UTF-8) before transmitting the
data. When doing so, it will have to set the charset in the response.
AFAIK only text/* responses are supposed to have a charset parameter,
because everything else is just byte strings.
> The reason AFAICT is that my content object just stores its source as
> unicode object and simply provides that in its IReadFile adapter.
IReadFile should really return byte strings, not unicode.
Philipp
More information about the Zope3-users
mailing list