I just upgraded web.py and Python, and, for the most part, my application
works fine. But it seems as though my app is now feeding unicode strings to
web.py in a couple unexpected places. I can't tell whether it's a bug or
whether I'm doing something systemically wrong:
>>> import web
>>> web.__version__
'0.31'
>>> web.db.sqlquote(u"I'm a unicode string")
<sql: 'u"I\'m a unicode string"'>
>>> 'select * from %s' % web.db.sqlquote(u'my_table')
"select * from u'my_table'"
This causes a syntax error in MySQL, because of the extra 'u'.
>>> web.ctx.headers = [] #hack so that it's possible to set cookies
>>> web.setcookie(u'key', u'value')
Traceback (most recent call last):
(elided -- see the bottom of this mail for the full stack trace)
File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/string.py",
line 491, in translate
return s.translate(table, deletions)
TypeError: translate() takes exactly one argument (2 given)
(I observed this same error in the running app, too.) Two-argument
translate() is only defined for str, not for unicode.
Is this a known issue? Am I misusing strings?
Thanks,
Paul
P.S. The promised backtrace:
>>> web.setcookie(u'key', u'value')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/web/webapi.py",
line 244, in setcookie
cookie[name] = urllib.quote(utf8(value))
File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/Cookie.py",
line 585, in __setitem__
self.__set(key, rval, cval)
File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/Cookie.py",
line 578, in __set
M.set(key, real_value, coded_value)
File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/Cookie.py",
line 454, in set
if "" != translate(key, idmap, LegalChars):
File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/string.py",
line 491, in translate
return s.translate(table, deletions)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"web.py" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [email protected]
For more options, visit this group at http://groups.google.com/group/webpy?hl=en
-~----------~----~----~----~------~----~------~--~---