當前位置: 首頁>>代碼示例>>Python>>正文


Python xml.XmlDocument類代碼示例

本文整理匯總了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)
開發者ID:jpunwin,項目名稱:spyne,代碼行數:34,代碼來源:test_primitive.py

示例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)
開發者ID:Bluehorn,項目名稱:spyne,代碼行數:11,代碼來源:xml.py

示例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
開發者ID:rahims,項目名稱:spyne,代碼行數:11,代碼來源:soap11.py

示例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
開發者ID:hartror,項目名稱:spyne,代碼行數:13,代碼來源:soap11.py

示例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)
開發者ID:jpunwin,項目名稱:spyne,代碼行數:15,代碼來源:test_primitive.py

示例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]
開發者ID:Bluehorn,項目名稱:spyne,代碼行數:22,代碼來源:xml.py

示例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
開發者ID:amgibson,項目名稱:spyne,代碼行數:6,代碼來源:soap11.py


注:本文中的spyne.protocol.xml.XmlDocument類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。