Request and response default charset

10 views
Skip to first unread message

Rodrigo Alves Lima

unread,
Dec 26, 2013, 10:50:55 PM12/26/13
to paste...@googlegroups.com
Hi,

I'm developing a lightweight framework based on WebOb request and response objects for learning purpose (another!) and I'm facing some problems with charset configuration in Python 3.

May I assume that 'GET', 'POST', 'cookies' and 'headers' keys and values are unicode by default (class 'str' in Python 3)?

I've looked at the code but it's still not clear to me. According to the documentation, submissions are non-unicode strings and you should force a charset (>>> req.charset = 'utf-8') but even on requests that charset is set to None, attributes are encoded in UTF-8. The 'body' attribute is not unicode, instead.


[ ]s
Rodrigo A. Lima

Michael Merickel

unread,
Dec 26, 2013, 11:39:45 PM12/26/13
to Rodrigo Alves Lima, paste...@googlegroups.com
In webob 1.2+ the request object always uses utf-8 and if you want to change the charset you must decode that request into a new request object via req.decode(..), and yes these values will always be unicode and raise exceptions when other types are expected. For example, request.body is bytes, but request.text is unicode. The response object is similar except that you may specify the charset in the constructor.


--
You received this message because you are subscribed to the Google Groups "Paste Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to paste-users...@googlegroups.com.
To post to this group, send email to paste...@googlegroups.com.
Visit this group at http://groups.google.com/group/paste-users.
For more options, visit https://groups.google.com/groups/opt_out.

Rodrigo Alves Lima

unread,
Dec 27, 2013, 9:00:23 AM12/27/13
to paste...@googlegroups.com
Thanks!
Reply all
Reply to author
Forward
0 new messages