本文整理汇总了Python中spyne.protocol.xml.XmlDocument类的典型用法代码示例。如果您正苦于以下问题:Python XmlDocument类的具体用法?Python XmlDocument怎么用?Python XmlDocument使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XmlDocument类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_boolean
def test_boolean(self):
b = etree.Element('test')
XmlDocument().to_parent(None, Boolean, True, b, ns_test)
b = b[0]
self.assertEquals('true', b.text)
b = etree.Element('test')
XmlDocument().to_parent(None, Boolean, 0, b, ns_test)
b = b[0]
self.assertEquals('false', b.text)
b = etree.Element('test')
XmlDocument().to_parent(None, Boolean, 1, b, ns_test)
b = b[0]
self.assertEquals('true', b.text)
b = XmlDocument().from_element(None, Boolean, b)
self.assertEquals(b, True)
b = etree.Element('test')
XmlDocument().to_parent(None, Boolean, False, b, ns_test)
b = b[0]
self.assertEquals('false', b.text)
b = XmlDocument().from_element(None, Boolean, b)
self.assertEquals(b, False)
b = etree.Element('test')
XmlDocument().to_parent(None, Boolean, None, b, ns_test)
b = b[0]
self.assertEquals('true', b.get('{%s}nil' % ns.xsi))
b = XmlDocument().from_element(None, Boolean, b)
self.assertEquals(b, None)
示例2: get_xml_as_object
def get_xml_as_object(elt, cls):
'''Returns a native :class:`spyne.model.complex.ComplexModel` child from an
ElementTree representation of the same class.
:param value: The class the xml document represents.
:param value: The xml document to be deserialized.
'''
xml_object = XmlDocument()
return xml_object.from_element(cls, elt)
示例3: __init__
def __init__(self, app=None, validator=None, wrapped=True,
xml_declaration=True, cleanup_namespaces=True):
XmlDocument.__init__(self, app, validator, xml_declaration,
cleanup_namespaces)
self.__wrapped = wrapped
# SOAP requires DateTime strings to be in iso format. This function
# bypasses datetime formatting via DateTime(format="...") string.
self.serialization_handlers[DateTime] = _datetime_to_parent_element
self.deserialization_handlers[DateTime] = _datetime_from_element
示例4: __init__
def __init__(self, app=None, validator=None, xml_declaration=True,
cleanup_namespaces=True, encoding='UTF-8', pretty_print=False):
XmlDocument.__init__(self, app, validator, xml_declaration,
cleanup_namespaces, encoding, pretty_print)
# SOAP requires DateTime strings to be in iso format. The following
# lines make sure custom datetime formatting via DateTime(format="...")
# string is bypassed.
self._to_string_handlers[Time] = lambda cls, value: value.isoformat()
self._to_string_handlers[DateTime] = lambda cls, value: value.isoformat()
self._from_string_handlers[Date] = date_from_string_iso
self._from_string_handlers[DateTime] = datetime_from_string_iso
示例5: test_datetime_timezone
def test_datetime_timezone(self):
import pytz
n = datetime.datetime.now(pytz.timezone('EST'))
element = etree.Element('test')
cls = DateTime(as_timezone=pytz.utc, timezone=False)
XmlDocument().to_parent(None, cls, n, element, ns_test)
element = element[0]
c = n.astimezone(pytz.utc).replace(tzinfo=None)
self.assertEquals(element.text, c.isoformat())
dt = XmlDocument().from_element(None, cls, element)
assert dt.tzinfo is not None
dt = dt.replace(tzinfo=None)
self.assertEquals(c, dt)
示例6: get_object_as_xml
def get_object_as_xml(value, cls=None, root_tag_name=None, no_namespace=False):
'''Returns an ElementTree representation of a :class:`spyne.model.complex.ComplexModel`
child.
:param value: The instance of the class to be serialized.
:param value: The root tag string to use. Defaults to the output of
``value.__class__.get_type_name_ns()``.
'''
if cls is None:
cls = value.__class__
xml_object = XmlDocument()
parent = etree.Element("parent")
xml_object.to_parent_element(cls, value, cls.get_namespace(),
parent, root_tag_name)
if no_namespace:
_dig(parent)
etree.cleanup_namespaces(parent)
return parent[0]
示例7: __init__
def __init__(self, app=None, validator=None, wrapped=True,
xml_declaration=True, cleanup_namespaces=True):
XmlDocument.__init__(self, app, validator, xml_declaration,
cleanup_namespaces)
self.__wrapped = wrapped