[mod_python] How to change charset on the Content-Type line throu mod_python.publisher

Graham Dumpleton grahamd at dscpl.com.au
Fri May 12 18:19:21 EDT 2006


On 13/05/2006, at 5:06 AM, Martin MOKREJŠ wrote:

> Hi,
>   I am trying to figure out how to affect my charset other than use
> AddCharset Apache directive, which works over file extensions.
> I don't think it makes sense to assign say 'utf8' to .html file  
> extension.
> When the HTML code is generated through mod_python.publisher, I should
> be able to do it.
>   The only examples how to alter Content-Type: is to use your own
> handler. No, I don't need it, thanks. I'd immediately fall into the  
> trap
> with need to use 'req.write', 'return apache.OK', etc. somewhere in my
> code.
>
>
> http://www.modpython.org/live/current/doc-html/pyapi-mprequest- 
> mem.html
>
> <QUOTE>
> content_languages
>     Tuple. List of strings representing the content languages.
>
> handler
>     The name of the handler currently being processed. This is the  
> handler
>     set by mod_mime, not the mod_python handler. In most cases it  
> will be
>     ""mod_python". (Read-Only)
>
> content_encoding
>     String. Content encoding. (Read-Only)
> </QUOTE>

I believe that content_encoding is only relevant to the received  
request.
Even if settable, nothing consults it in respect of updating anything  
in a
response.

>
>   I awfully lack examples in the documentation. So, how can I make  
> publisher
> change my charset away from the site-wide defined value?

If using mod_python.publisher and returning your page content as the
return value, add "req" as one of the function input parameters and do:

   def index(req):
     req.content_type = 'text/html; charset=UTF8'
     return "<html>....</html>"

Provided you are using mod_python 3.2.8, if the publisher function  
returns
a Unicode string, then mod_python.publisher will automatically attempt
to fill out the charset in the content type header for you.

> Please update the
> docs. I very much appreciate the effort Graham and Nicolas does to  
> support
> this email list but save yourself some time and fix the docs for  
> yourself! ;)

Some updates are made, but because they in source code repository copy
of documentation, you will not see them until next major release of  
mod_python.

Also, Nicolas, Jim and I all have limited time. Our job would be made  
easier
though if users of mod_python would like to offer up the examples and  
show
where to put them in the documentation. Remember, our focus is not  
likely
to be where your focus lies and so we wouldn't even think to update a  
certain
bit of documentation unless it is pointed out to us specifically with  
examples
of what to put in it to make it better.

Any documentation changes/enhancements can be logged at:

   http://issues.apache.org/jira/browse/MODPYTHON

There is no point posting them just to the mailing list as they  
inevitably get lost.
If on JIRA, they have to be dealt with eventually.

Graham


More information about the Mod_python mailing list