Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

unicodify web.input

  • Loading branch information...
commit 3ba0911ea26043ff4826e30480a564a1ccabef12 1 parent d5c39b2
@anandology anandology authored
View
30 test/application.py
@@ -2,6 +2,7 @@
import time
import web
+import urllib
data = """
import web
@@ -162,7 +163,34 @@ def g():
assert state.x == 1 and state.y == 1, repr(state)
app.request('/foo')
assert state.x == 1 and state.y == 2, repr(state)
+
+ def testUnicodeInput(self):
+ urls = (
+ "/.*", "foo"
+ )
+ class foo:
+ def GET(self):
+ i = web.input(name='')
+ return repr(i.name)
+
+ def POST(self):
+ return repr(web.data())
+ i = web.input(name={})
+ return repr(i)
+
+ app = web.application(urls, locals())
+
+ def f(name):
+ path = '/?' + urllib.urlencode({"name": name})
+ self.assertEquals(app.request(path).data, repr(name))
+
+ f(u'\u1234')
+ f(u'foo')
+
+ data = '--boundary\r\nContent-Disposition: form-data; name="name"; filename="a.txt"\r\nContent-Type: text/plain\r\n\r\na\r\n--boundary--\r\n'
+ headers = {'Content-Type': 'multipart/form-data; boundary=--boundary'}
+ response = app.request('/', method="POST", data=data, headers=headers)
+ print response.data
if __name__ == '__main__':
webtest.main()
-
View
15 test/db.py
@@ -13,6 +13,14 @@ def tearDown(self):
# there might be some error with the current connection, delete from a new connection
self.db = webtest.setup_database(self.dbname)
self.db.query('DROP TABLE person')
+
+ def _testable(self):
+ try:
+ webtest.setup_database(self.dbname)
+ return True
+ except ImportError, e:
+ print >> web.debug, str(e), "(ignoring the %s tests)" % self.dbname
+ return False
def testUnicode(self):
"""Bug#177265: unicode queries throw errors"""
@@ -94,5 +102,12 @@ def setUp(self):
# In mysql, transactions are supported only with INNODB engine.
self.db.query("CREATE TABLE person (name text, email text) ENGINE=INNODB")
+
+# ignore db tests when the required db adapter is not found.
+for t in [DBTest, MySQLTest, SqliteTest]:
+ if not t('_testable')._testable():
+ del globals()[t.__name__]
+ pass
+
if __name__ == '__main__':
webtest.main()
View
5 web/application.py
@@ -158,7 +158,10 @@ def request(self, localpart='/', method='GET', data=None,
if data:
import StringIO
- q = urllib.urlencode(data)
+ if isinstance(data, dict):
+ q = urllib.urlencode(data)
+ else:
+ q = data
env['wsgi.input'] = StringIO.StringIO(q)
response = web.storage()
def start_response(status, headers):
View
4 web/utils.py
@@ -113,6 +113,10 @@ def storify(mapping, *requireds, **defaults):
>>> storify({'x': 'a'}, _unicode=True)
<Storage {'x': u'a'}>
+ >>> storify({'x': storage(value='a')}, x={}, _unicode=True)
+ <Storage {'x': <Storage {'value': 'a'}>}>
+ >>> storify({'x': storage(value='a')}, _unicode=True)
+ <Storage {'x': u'a'}>
"""
_unicode = defaults.pop('_unicode', False)
def unicodify(s):
View
3  web/webapi.py
@@ -196,8 +196,7 @@ def dictify(fs): return dict([(k, fs[k]) for k in fs.keys()])
out = dictadd(b, a)
try:
- #@@ disabled because this is causing failure on file uploads
- #defaults.setdefault('_unicode', True) # force unicode conversion by default.
+ defaults.setdefault('_unicode', True) # force unicode conversion by default.
return storify(out, *requireds, **defaults)
except KeyError:
raise badrequest()
Please sign in to comment.
Something went wrong with that request. Please try again.