本文整理汇总了Python中tornado.escape.json_decode方法的典型用法代码示例。如果您正苦于以下问题:Python escape.json_decode方法的具体用法?Python escape.json_decode怎么用?Python escape.json_decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.escape
的用法示例。
在下文中一共展示了escape.json_decode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_get_argument
# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import json_decode [as 别名]
def test_get_argument(self):
response = self.fetch("/get_argument?foo=bar")
self.assertEqual(response.body, b"bar")
response = self.fetch("/get_argument?foo=")
self.assertEqual(response.body, b"")
response = self.fetch("/get_argument")
self.assertEqual(response.body, b"default")
# Test merging of query and body arguments.
# In singular form, body arguments take precedence over query arguments.
body = urllib_parse.urlencode(dict(foo="hello"))
response = self.fetch("/get_argument?foo=bar", method="POST", body=body)
self.assertEqual(response.body, b"hello")
# In plural methods they are merged.
response = self.fetch("/get_arguments?foo=bar",
method="POST", body=body)
self.assertEqual(json_decode(response.body),
dict(default=['bar', 'hello'],
query=['bar'],
body=['hello']))
示例2: test_decode_argument
# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import json_decode [as 别名]
def test_decode_argument(self):
# These urls all decode to the same thing
urls = ["/decode_arg/%C3%A9?foo=%C3%A9&encoding=utf-8",
"/decode_arg/%E9?foo=%E9&encoding=latin1",
"/decode_arg_kw/%E9?foo=%E9&encoding=latin1",
]
for req_url in urls:
response = self.fetch(req_url)
response.rethrow()
data = json_decode(response.body)
self.assertEqual(data, {u('path'): [u('unicode'), u('\u00e9')],
u('query'): [u('unicode'), u('\u00e9')],
})
response = self.fetch("/decode_arg/%C3%A9?foo=%C3%A9")
response.rethrow()
data = json_decode(response.body)
self.assertEqual(data, {u('path'): [u('bytes'), u('c3a9')],
u('query'): [u('bytes'), u('c3a9')],
})
示例3: test_multipart_form
# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import json_decode [as 别名]
def test_multipart_form(self):
# Encodings here are tricky: Headers are latin1, bodies can be
# anything (we use utf8 by default).
response = self.raw_fetch([
b"POST /multipart HTTP/1.0",
b"Content-Type: multipart/form-data; boundary=1234567890",
b"X-Header-encoding-test: \xe9",
],
b"\r\n".join([
b"Content-Disposition: form-data; name=argument",
b"",
u("\u00e1").encode("utf-8"),
b"--1234567890",
u('Content-Disposition: form-data; name="files"; filename="\u00f3"').encode("utf8"),
b"",
u("\u00fa").encode("utf-8"),
b"--1234567890--",
b"",
]))
data = json_decode(response)
self.assertEqual(u("\u00e9"), data["header"])
self.assertEqual(u("\u00e1"), data["argument"])
self.assertEqual(u("\u00f3"), data["filename"])
self.assertEqual(u("\u00fa"), data["filebody"])
示例4: test_chunked_request_body
# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import json_decode [as 别名]
def test_chunked_request_body(self):
# Chunked requests are not widely supported and we don't have a way
# to generate them in AsyncHTTPClient, but HTTPServer will read them.
self.stream.write(b"""\
POST /echo HTTP/1.1
Transfer-Encoding: chunked
Content-Type: application/x-www-form-urlencoded
4
foo=
3
bar
0
""".replace(b"\n", b"\r\n"))
read_stream_body(self.stream, self.stop)
headers, response = self.wait()
self.assertEqual(json_decode(response), {u('foo'): [u('bar')]})
示例5: test_twitter_get_user
# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import json_decode [as 别名]
def test_twitter_get_user(self):
response = self.fetch(
"/twitter/client/login?oauth_token=zxcv",
headers={"Cookie": "_oauth_request_token=enhjdg==|MTIzNA=="},
)
response.rethrow()
parsed = json_decode(response.body)
self.assertEqual(
parsed,
{
u"access_token": {
u"key": u"hjkl",
u"screen_name": u"foo",
u"secret": u"vbnm",
},
u"name": u"Foo",
u"screen_name": u"foo",
u"username": u"foo",
},
)
示例6: get_current_user
# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import json_decode [as 别名]
def get_current_user(self):
user_json = self.get_secure_cookie(self.COOKIE_NAME)
if not user_json:
return None
return json_decode(user_json)
示例7: _on_oauth2_request
# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import json_decode [as 别名]
def _on_oauth2_request(self, future, response):
if response.error:
future.set_exception(AuthError("Error response %s fetching %s" %
(response.error, response.request.url)))
return
future.set_result(escape.json_decode(response.body))
示例8: _on_twitter_request
# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import json_decode [as 别名]
def _on_twitter_request(self, future, response):
if response.error:
future.set_exception(AuthError(
"Error response %s fetching %s" % (response.error,
response.request.url)))
return
future.set_result(escape.json_decode(response.body))
示例9: _on_access_token
# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import json_decode [as 别名]
def _on_access_token(self, future, response):
"""Callback function for the exchange to the access token."""
if response.error:
future.set_exception(AuthError('Google auth error: %s' % str(response)))
return
args = escape.json_decode(response.body)
future.set_result(args)
示例10: test_openid_get_user
# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import json_decode [as 别名]
def test_openid_get_user(self):
response = self.fetch('/openid/client/login?openid.mode=blah&openid.ns.ax=http://openid.net/srv/ax/1.0&openid.ax.type.email=http://axschema.org/contact/email&openid.ax.value.email=foo@example.com')
response.rethrow()
parsed = json_decode(response.body)
self.assertEqual(parsed["email"], "foo@example.com")
示例11: test_oauth10_request_parameters
# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import json_decode [as 别名]
def test_oauth10_request_parameters(self):
response = self.fetch('/oauth10/client/request_params')
response.rethrow()
parsed = json_decode(response.body)
self.assertEqual(parsed['oauth_consumer_key'], 'asdf')
self.assertEqual(parsed['oauth_token'], 'uiop')
self.assertTrue('oauth_nonce' in parsed)
self.assertTrue('oauth_signature' in parsed)
示例12: test_oauth10a_get_user
# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import json_decode [as 别名]
def test_oauth10a_get_user(self):
response = self.fetch(
'/oauth10a/client/login?oauth_token=zxcv',
headers={'Cookie': '_oauth_request_token=enhjdg==|MTIzNA=='})
response.rethrow()
parsed = json_decode(response.body)
self.assertEqual(parsed['email'], 'foo@example.com')
self.assertEqual(parsed['access_token'], dict(key='uiop', secret='5678'))
示例13: test_oauth10a_request_parameters
# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import json_decode [as 别名]
def test_oauth10a_request_parameters(self):
response = self.fetch('/oauth10a/client/request_params')
response.rethrow()
parsed = json_decode(response.body)
self.assertEqual(parsed['oauth_consumer_key'], 'asdf')
self.assertEqual(parsed['oauth_token'], 'uiop')
self.assertTrue('oauth_nonce' in parsed)
self.assertTrue('oauth_signature' in parsed)
示例14: test_twitter_get_user
# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import json_decode [as 别名]
def test_twitter_get_user(self):
response = self.fetch(
'/twitter/client/login?oauth_token=zxcv',
headers={'Cookie': '_oauth_request_token=enhjdg==|MTIzNA=='})
response.rethrow()
parsed = json_decode(response.body)
self.assertEqual(parsed,
{u('access_token'): {u('key'): u('hjkl'),
u('screen_name'): u('foo'),
u('secret'): u('vbnm')},
u('name'): u('Foo'),
u('screen_name'): u('foo'),
u('username'): u('foo')})
示例15: test_twitter_show_user
# 需要导入模块: from tornado import escape [as 别名]
# 或者: from tornado.escape import json_decode [as 别名]
def test_twitter_show_user(self):
response = self.fetch('/twitter/client/show_user?name=somebody')
response.rethrow()
self.assertEqual(json_decode(response.body),
{'name': 'Somebody', 'screen_name': 'somebody'})