本文整理汇总了Python中tastypie.serializers.Serializer.to_xml方法的典型用法代码示例。如果您正苦于以下问题:Python Serializer.to_xml方法的具体用法?Python Serializer.to_xml怎么用?Python Serializer.to_xml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tastypie.serializers.Serializer
的用法示例。
在下文中一共展示了Serializer.to_xml方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_to_xml_single
# 需要导入模块: from tastypie.serializers import Serializer [as 别名]
# 或者: from tastypie.serializers.Serializer import to_xml [as 别名]
def test_to_xml_single(self):
serializer = Serializer()
resource = self.obj_list[0]
self.assertEqual(
serializer.to_xml(resource),
"<?xml version='1.0' encoding='utf-8'?>\n<object><updated>2010-03-30T20:05:00</updated><created>2010-03-30T20:05:00</created><title>First Post!</title><is_active type=\"boolean\">True</is_active><slug>first-post</slug><content>This is my very first post using my shiny new API. Pretty sweet, huh?</content><id>1</id><resource_uri></resource_uri></object>",
)
示例2: test_to_xml2
# 需要导入模块: from tastypie.serializers import Serializer [as 别名]
# 或者: from tastypie.serializers.Serializer import to_xml [as 别名]
def test_to_xml2(self):
serializer = Serializer()
sample_2 = self.get_sample2()
self.assertEqual(
serializer.to_xml(sample_2),
'<?xml version=\'1.0\' encoding=\'utf-8\'?>\n<response><somelist type="list"><value>hello</value><value type="integer">1</value><value type="null"/></somelist><somehash type="hash"><pi type="float">3.14</pi><foo>bar</foo></somehash><false type="boolean">False</false><true type="boolean">True</true><somestring>hello</somestring></response>',
)
示例3: test_to_xml
# 需要导入模块: from tastypie.serializers import Serializer [as 别名]
# 或者: from tastypie.serializers.Serializer import to_xml [as 别名]
def test_to_xml(self):
serializer = Serializer()
sample_1 = self.get_sample1()
self.assertEqual(
serializer.to_xml(sample_1),
"<?xml version='1.0' encoding='utf-8'?>\n<response><age type=\"integer\">27</age><name>Daniel</name><date_joined>2010-03-27</date_joined></response>",
)
示例4: test_to_xml_nested
# 需要导入模块: from tastypie.serializers import Serializer [as 别名]
# 或者: from tastypie.serializers.Serializer import to_xml [as 别名]
def test_to_xml_nested(self):
serializer = Serializer()
resource = self.obj_list[0]
data = {"stuff": {"foo": "bar", "object": resource}}
self.assertEqual(
serializer.to_xml(data),
"<?xml version='1.0' encoding='utf-8'?>\n<response><stuff type=\"hash\"><foo>bar</foo><object><updated>2010-03-30T20:05:00</updated><created>2010-03-30T20:05:00</created><title>First Post!</title><is_active type=\"boolean\">True</is_active><slug>first-post</slug><content>This is my very first post using my shiny new API. Pretty sweet, huh?</content><id>1</id><resource_uri></resource_uri></object></stuff></response>",
)
示例5: test_round_trip_xml
# 需要导入模块: from tastypie.serializers import Serializer [as 别名]
# 或者: from tastypie.serializers.Serializer import to_xml [as 别名]
def test_round_trip_xml(self):
serializer = Serializer()
sample_data = self.get_sample2()
serialized = serializer.to_xml(sample_data)
# "response" tags need to be changed to "request" to deserialize properly.
# A string substitution works here.
serialized = serialized.replace('response', 'request')
unserialized = serializer.from_xml(serialized)
self.assertEqual(sample_data, unserialized)
示例6: test_to_xml_nested
# 需要导入模块: from tastypie.serializers import Serializer [as 别名]
# 或者: from tastypie.serializers.Serializer import to_xml [as 别名]
def test_to_xml_nested(self):
serializer = Serializer()
resource = self.obj_list[0]
data = {
'stuff': {
'foo': 'bar',
'object': resource,
}
}
self.assertEqual(serializer.to_xml(data), '<?xml version=\'1.0\' encoding=\'utf-8\'?>\n<response><stuff type="hash"><foo>bar</foo><object><updated>2010-03-30T20:05:00</updated><created>2010-03-30T20:05:00</created><title>First Post!</title><is_active type="boolean">True</is_active><slug>first-post</slug><content>This is my very first post using my shiny new API. Pretty sweet, huh?</content><id>1</id><resource_uri></resource_uri></object></stuff></response>')
示例7: test_to_xml
# 需要导入模块: from tastypie.serializers import Serializer [as 别名]
# 或者: from tastypie.serializers.Serializer import to_xml [as 别名]
def test_to_xml(self):
serializer = Serializer()
sample_1 = self.get_sample1()
# This needs a little explanation.
# From http://lxml.de/parsing.html, what comes out of ``tostring``
# (despite encoding as UTF-8) is a bytestring. This is because that's
# what other libraries expect (& will do the decode). We decode here
# so we can make extra special sure it looks right.
binary_xml = serializer.to_xml(sample_1)
unicode_xml = binary_xml.decode('utf-8')
self.assertEqual(unicode_xml, u'<?xml version=\'1.0\' encoding=\'utf-8\'?>\n<response><age type="integer">27</age><date_joined>2010-03-27</date_joined><name>Daniel</name><snowman>☃</snowman></response>')
示例8: test_to_xml_multirepr
# 需要导入模块: from tastypie.serializers import Serializer [as 别名]
# 或者: from tastypie.serializers.Serializer import to_xml [as 别名]
def test_to_xml_multirepr(self):
serializer = Serializer()
self.assertEqual(serializer.to_xml(self.obj_list), '<?xml version=\'1.0\' encoding=\'utf-8\'?>\n<objects><object><updated>2010-03-30T20:05:00</updated><created>2010-03-30T20:05:00</created><title>First Post!</title><is_active type="boolean">True</is_active><slug>first-post</slug><content>This is my very first post using my shiny new API. Pretty sweet, huh?</content><id>1</id><resource_uri></resource_uri></object><object><updated>2010-03-31T20:05:00</updated><created>2010-03-31T20:05:00</created><title>Another Post</title><is_active type="boolean">True</is_active><slug>another-post</slug><content>The dog ate my cat today. He looks seriously uncomfortable.</content><id>2</id><resource_uri></resource_uri></object><object><updated>2010-04-01T20:05:00</updated><created>2010-04-01T20:05:00</created><title>Recent Volcanic Activity.</title><is_active type="boolean">True</is_active><slug>recent-volcanic-activity</slug><content>My neighborhood\'s been kinda weird lately, especially after the lava flow took out the corner store. Granny can hardly outrun the magma with her walker.</content><id>4</id><resource_uri></resource_uri></object><object><updated>2010-04-02T10:05:00</updated><created>2010-04-02T10:05:00</created><title>Granny\'s Gone</title><is_active type="boolean">True</is_active><slug>grannys-gone</slug><content>Man, the second eruption came on fast. Granny didn\'t have a chance. On the upshot, I was able to save her walker and I got a cool shawl out of the deal!</content><id>6</id><resource_uri></resource_uri></object></objects>')
示例9: test_to_xml
# 需要导入模块: from tastypie.serializers import Serializer [as 别名]
# 或者: from tastypie.serializers.Serializer import to_xml [as 别名]
def test_to_xml(self):
serializer = Serializer()
sample_1 = self.get_sample1()
self.assertEqual(serializer.to_xml(sample_1), '<?xml version=\'1.0\' encoding=\'utf-8\'?>\n<response><age type="integer">27</age><name>Daniel</name><date_joined>27 Mar 2010</date_joined></response>')
示例10: test_to_xml_single
# 需要导入模块: from tastypie.serializers import Serializer [as 别名]
# 或者: from tastypie.serializers.Serializer import to_xml [as 别名]
def test_to_xml_single(self):
serializer = Serializer()
representation = NoteRepresentation.get_list()[0]
self.assertEqual(serializer.to_xml(representation), '<?xml version=\'1.0\' encoding=\'utf-8\'?>\n<object><content>This is my very first post using my shiny new API. Pretty sweet, huh?</content><updated>Tue, 30 Mar 2010 20:05:00 -0500</updated><created>Tue, 30 Mar 2010 20:05:00 -0500</created><title>First Post!</title><is_active type="boolean">True</is_active><slug>first-post</slug><resource_uri></resource_uri></object>')
示例11: test_to_xml_single
# 需要导入模块: from tastypie.serializers import Serializer [as 别名]
# 或者: from tastypie.serializers.Serializer import to_xml [as 别名]
def test_to_xml_single(self):
serializer = Serializer()
resource = self.obj_list[0]
binary_xml = serializer.to_xml(resource)
unicode_xml = binary_xml.decode('utf-8')
self.assertEqual(unicode_xml, '<?xml version=\'1.0\' encoding=\'utf-8\'?>\n<object><content>This is my very first post using my shiny new API. Pretty sweet, huh?</content><created>2010-03-30T20:05:00</created><id type="integer">1</id><is_active type="boolean">True</is_active><resource_uri></resource_uri><slug>first-post</slug><title>First Post!</title><updated>2010-03-30T20:05:00</updated></object>')