| 272 | assert state.x == 1 and state.y == 2, repr(state) |
| 273 | |
| 274 | def testUnicodeInput(self): |
| 275 | urls = ("(/.*)", "foo") |
| 276 | |
| 277 | class foo: |
| 278 | def GET(self, path): |
| 279 | i = web.input(name="") |
| 280 | return repr(i.name) |
| 281 | |
| 282 | def POST(self, path): |
| 283 | if path == "/multipart": |
| 284 | i = web.input(file={}) |
| 285 | return i.file.value |
| 286 | else: |
| 287 | i = web.input() |
| 288 | return repr(dict(i)).replace("u", "") |
| 289 | |
| 290 | app = web.application(urls, locals()) |
| 291 | |
| 292 | def f(name): |
| 293 | path = "/?" + urlencode({"name": name.encode("utf-8")}) |
| 294 | self.assertEqual(app.request(path).data.decode("utf-8"), repr(name)) |
| 295 | |
| 296 | f("\u1234") |
| 297 | f("foo") |
| 298 | |
| 299 | response = app.request("/", method="POST", data=dict(name="foo")) |
| 300 | |
| 301 | self.assertEqual(response.data, b"{'name': 'foo'}") |
| 302 | |
| 303 | data = '--boundary\r\nContent-Disposition: form-data; name="x"\r\n\r\nfoo\r\n--boundary\r\nContent-Disposition: form-data; name="file"; filename="a.txt"\r\nContent-Type: text/plain\r\n\r\na\r\n--boundary--\r\n' |
| 304 | headers = {"Content-Type": "multipart/form-data; boundary=boundary"} |
| 305 | response = app.request("/multipart", method="POST", data=data, headers=headers) |
| 306 | |
| 307 | self.assertEqual(response.data, b"a") |
| 308 | |
| 309 | def testCustomNotFound(self): |
| 310 | urls_a = ("/", "a") |