get_xml_as_object 函数不适用于多态性 - spyne 2.13.12 alpha0
get_xml_as_object function not working with polymorphism - spyne 2.13.12 alpha0
在 spyne 2.13.12 alpha0 中加载多态对象时返回 spyne 错误。您能否看一下下面的示例并指出应该使用哪个函数从 xml 文件加载对象?
import sys
from lxml import etree
from spyne.util import six
from spyne import ComplexModel, Unicode
from spyne.util.xml import get_object_as_xml_polymorphic, get_xml_as_object
class B(ComplexModel):
_type_info = {
'_b': Unicode,
}
def __init__(self):
super().__init__()
self._b = "b"
class C(B):
_type_info = {
'_c': Unicode,
}
def __init__(self):
super().__init__()
self._c = "c"
class A(ComplexModel):
_type_info = {
'_a': Unicode,
'_b': B,
}
def __init__(self, b=None):
super().__init__()
self._a = 'a'
self._b = b
a = A(b=C())
elt = get_object_as_xml_polymorphic(a, A, no_namespace=True)
xml_string = etree.tostring(elt, pretty_print=True)
if six.PY2:
print(xml_string, end="")
else:
sys.stdout.buffer.write(xml_string)
element_tree = etree.fromstring(xml_string)
new_a = get_xml_as_object(elt, A)
错误在最后一行,消息是
raise ValidationError(xsi_type)
spyne.error.ValidationError: ValidationError(Client.ValidationError: "The value 'C' could not be validated.")
感谢您的帮助
您的代码被用作 test and example as part of PR #635 to fix the issue you were having. Please test with >=spyne-2.13.14 并报告回来。
谢谢!
在 spyne 2.13.12 alpha0 中加载多态对象时返回 spyne 错误。您能否看一下下面的示例并指出应该使用哪个函数从 xml 文件加载对象?
import sys
from lxml import etree
from spyne.util import six
from spyne import ComplexModel, Unicode
from spyne.util.xml import get_object_as_xml_polymorphic, get_xml_as_object
class B(ComplexModel):
_type_info = {
'_b': Unicode,
}
def __init__(self):
super().__init__()
self._b = "b"
class C(B):
_type_info = {
'_c': Unicode,
}
def __init__(self):
super().__init__()
self._c = "c"
class A(ComplexModel):
_type_info = {
'_a': Unicode,
'_b': B,
}
def __init__(self, b=None):
super().__init__()
self._a = 'a'
self._b = b
a = A(b=C())
elt = get_object_as_xml_polymorphic(a, A, no_namespace=True)
xml_string = etree.tostring(elt, pretty_print=True)
if six.PY2:
print(xml_string, end="")
else:
sys.stdout.buffer.write(xml_string)
element_tree = etree.fromstring(xml_string)
new_a = get_xml_as_object(elt, A)
错误在最后一行,消息是
raise ValidationError(xsi_type)
spyne.error.ValidationError: ValidationError(Client.ValidationError: "The value 'C' could not be validated.")
感谢您的帮助
您的代码被用作 test and example as part of PR #635 to fix the issue you were having. Please test with >=spyne-2.13.14 并报告回来。
谢谢!