handler_test.py 文件源码

python
阅读 17 收藏 0 点赞 0 评论 0

项目:webapp2 作者: GoogleCloudPlatform 项目源码 文件源码
def test_encoding(self):
        class PostHandler(webapp2.RequestHandler):
            def post(self):
                foo = self.request.POST['foo']
                if not foo:
                    foo = 'empty'

                self.response.write(foo)

        app = webapp2.WSGIApplication([
            webapp2.Route('/', PostHandler),
        ], debug=True)

        # foo with umlauts in the vowels.
        value = b'f\xc3\xb6\xc3\xb6'

        rsp = app.get_response(
            '/',
            POST={'foo': value},
            headers=[('Content-Type',
                      'application/x-www-form-urlencoded; charset=utf-8')]
        )
        self.assertEqual(rsp.unicode_body, u'föö')
        self.assertEqual(rsp.body, value)

        rsp = app.get_response(
            '/',
            POST={'foo': value},
            headers=[('Content-Type', 'application/x-www-form-urlencoded')]
        )
        self.assertEqual(rsp.unicode_body, u'föö')
        self.assertEqual(rsp.body, value)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号