本文整理汇总了Python中tastypie.serializers.Serializer.to_jsonp方法的典型用法代码示例。如果您正苦于以下问题:Python Serializer.to_jsonp方法的具体用法?Python Serializer.to_jsonp怎么用?Python Serializer.to_jsonp使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tastypie.serializers.Serializer
的用法示例。
在下文中一共展示了Serializer.to_jsonp方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_to_jsonp
# 需要导入模块: from tastypie.serializers import Serializer [as 别名]
# 或者: from tastypie.serializers.Serializer import to_jsonp [as 别名]
def test_to_jsonp(self):
serializer = Serializer()
sample_1 = self.get_sample1()
options = {'callback': 'myCallback'}
serialized = serializer.to_jsonp(sample_1, options=options)
serialized_json = serializer.to_json(sample_1)
self.assertEqual('myCallback(%s)' % serialized_json,
serialized)
示例2: test_invalid_jsonp_characters
# 需要导入模块: from tastypie.serializers import Serializer [as 别名]
# 或者: from tastypie.serializers.Serializer import to_jsonp [as 别名]
def test_invalid_jsonp_characters(self):
"""
The newline characters \u2028 and \u2029 need to be escaped
in JSONP.
"""
serializer = Serializer()
jsonp = serializer.to_jsonp({'foo': u'Hello \u2028\u2029world!'},
{'callback': 'callback'})
self.assertEqual(jsonp, u'callback({"foo": "Hello \\u2028\\u2029world!"})')
示例3: test_to_jsonp
# 需要导入模块: from tastypie.serializers import Serializer [as 别名]
# 或者: from tastypie.serializers.Serializer import to_jsonp [as 别名]
def test_to_jsonp(self):
serializer = Serializer()
sample_1 = self.get_sample1()
options = {'callback': 'myCallback'}
self.assertEqual(serializer.to_jsonp(sample_1, options), 'myCallback({"age": 27, "date_joined": "27 Mar 2010", "name": "Daniel"})')