示例#1
0
    def test_boolean(self):
        b = etree.Element('test')
        XmlObject().to_parent_element(Boolean, True, ns_test, b)
        b = b[0]
        self.assertEquals('true', b.text)

        b = etree.Element('test')
        XmlObject().to_parent_element(Boolean, 0, ns_test, b)
        b = b[0]
        self.assertEquals('false', b.text)

        b = etree.Element('test')
        XmlObject().to_parent_element(Boolean, 1, ns_test, b)
        b = b[0]
        self.assertEquals('true', b.text)

        b = XmlObject().from_element(Boolean, b)
        self.assertEquals(b, True)

        b = etree.Element('test')
        XmlObject().to_parent_element(Boolean, False, ns_test, b)
        b = b[0]
        self.assertEquals('false', b.text)

        b = XmlObject().from_element(Boolean, b)
        self.assertEquals(b, False)

        b = etree.Element('test')
        XmlObject().to_parent_element(Boolean, None, ns_test, b)
        b = b[0]
        self.assertEquals('true', b.get('{%s}nil' % ns.xsi))

        b = XmlObject().from_element(Boolean, b)
        self.assertEquals(b, None)
示例#2
0
文件: xml.py 项目: 66ru/spyne
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 = XmlObject()

    return xml_object.from_element(cls, elt)
示例#3
0
文件: soap11.py 项目: leobispo/spyne
    def __init__(self, app=None, validator=None, wrapped=True,
                                xml_declaration=True, cleanup_namespaces=False):
        XmlObject.__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
0
文件: soap11.py 项目: leekchan/spyne
    def __init__(self, app=None, validator=None, wrapped=True,
                                xml_declaration=True, cleanup_namespaces=False):
        """Soap 1.1 Protocol with validators.

        :param app: A spyne.application.Application instance.
        :param validator: The validator to use. Currently the only supported
            value is 'lxml'
        :param wrapped: Whether the return type should be wrapped in another
            object. Default is 'True'.
        :param xml_declaration: Whether to add xml_declaration to the responses
            Default is 'True'.
        :param cleanup_namespaces: Whether to add clean up namespace declarations
            in the response document. Default is 'False'.
        """
        XmlObject.__init__(self, app, validator, xml_declaration,
                                                             cleanup_namespaces)

        self.__wrapped = wrapped
示例#5
0
文件: xml.py 项目: 66ru/spyne
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 = XmlObject()
    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]