Request parameters as unicode Strings?

38 views
Skip to first unread message

Bjoern

unread,
Nov 16, 2009, 1:16:48 PM11/16/09
to bottlepy
Hi,

sorry if this question is yet again very noobish... I am developing a
small app for Google App Engine and I noticed that request parameters
seem to be of type str. Is there a way to make them all be unicode by
default? Not sure if the problem lies with App Engine or bottle.py

Thanks!


Björn

Marcel Hellkamp

unread,
Nov 16, 2009, 2:06:39 PM11/16/09
to bott...@googlegroups.com
Request parameters are byte strings because URLs are byte strings.
Neither Bottle nor AppEngine are in a position to guess or force an
encoding. If you need the values as unicode, you have to explicitly
encode them and catch encoding errors in your app code. I'd use a
decorator to do that.

def unicodeparam(encoding):
def decorator(func):
def wrapper(**kargs):
for key in kargs:
kargs[key] = kargs[key].decode(encoding)
return func(**kargs)
return wrapper
return decorator

(untested)

--
Hope that helped

Marcel

Bjoern

unread,
Nov 16, 2009, 5:53:57 PM11/16/09
to bottlepy
Thanks - somehow I never encountered this before... Will look into the
decorator pattern, not yet sure how it is applied in Python web
services.

My parameters are multipart-formencoded, but it is true, the browser
does not seem to send a specification of a charset along.

Björn
Reply all
Reply to author
Forward
0 new messages