Pyxb 错误地识别简单类型
Pyxb wrongly recognises simple type
我在基于模式投标构建 xml 后遇到 pyxb 问题。
我发现根据对一些简单 ('An atomic simple type') 元素赋值的方法,我得到了不同类型的赋值。
这是我的意思,我的详细信息:
Python2.7
PyXB 版本 1.2.5
OS: Windows 7
部分架构:
<xs:simpleType name="Max140Text_DE_customized">
<xs:restriction base="Max140Text">
<xs:minLength value="1"/>
<xs:maxLength value="140"/>
<xs:pattern value="[ ]*[A-Za-z0-9+?/:()\.,'\-][A-Za-z0-9+?/:()\.,' \-]*"/>
</xs:restriction>
</xs:simpleType>
(...)
<xs:simpleType name="Max140Text">
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="140"/>
</xs:restriction>
</xs:simpleType>
更新:
使用 Max140Text_DE_customized
:
的模式元素
<xs:complexType name="PartyIdentification32_CH_pacs008">
<xs:complexContent>
<xs:restriction base="PartyIdentification32">
<xs:sequence>
<xs:element name="Nm" type="Max140Text_DE_customized" minOccurs="0"/>
<xs:element name="PstlAdr" type="PostalAddress6_customized" minOccurs="0"/>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
pyxb 生成的出价:
# Atomic simple type: {http://www.schema-uri/de/MySchema}Max140Text
class Max140Text (pyxb.binding.datatypes.string):
"""An atomic simple type."""
_ExpandedName = pyxb.namespace.ExpandedName(Namespace, 'Max140Text')
_XSDLocation = pyxb.utils.utility.Location('C:\Python27\Scripts\MySchema.xsd', 1032, 2)
_Documentation = None
Max140Text._CF_minLength = pyxb.binding.facets.CF_minLength(value=pyxb.binding.datatypes.nonNegativeInteger(1))
Max140Text._CF_maxLength = pyxb.binding.facets.CF_maxLength(value=pyxb.binding.datatypes.nonNegativeInteger(140))
Max140Text._InitializeFacetMap(Max140Text._CF_minLength,
Max140Text._CF_maxLength)
Namespace.addCategoryObject('typeBinding', 'Max140Text', Max140Text)
_module_typeBindings.Max140Text = Max140Text
# Atomic simple type: {http://www.schema-uri/de/MySchema}Max140Text_DE_customized
class Max140Text_DE_customized (Max140Text):
"""An atomic simple type."""
_ExpandedName = pyxb.namespace.ExpandedName(Namespace, 'Max140Text_DE_customized')
_XSDLocation = pyxb.utils.utility.Location('C:\Python27\Scripts\MySchema.xsd', 1038, 2)
_Documentation = None
Max140Text_DE_customized._CF_minLength = pyxb.binding.facets.CF_minLength(value=pyxb.binding.datatypes.nonNegativeInteger(1))
Max140Text_DE_customized._CF_pattern = pyxb.binding.facets.CF_pattern()
Max140Text_DE_customized._CF_pattern.addPattern(pattern="[ ]*[A-Za-z0-9+?/:()\.,'\-][A-Za-z0-9+?/:()\.,' \-]*")
Max140Text_DE_customized._CF_maxLength = pyxb.binding.facets.CF_maxLength(value=pyxb.binding.datatypes.nonNegativeInteger(140))
Max140Text_DE_customized._InitializeFacetMap(Max140Text_DE_customized._CF_minLength,
Max140Text_DE_customized._CF_pattern, Max140Text_DE_customized._CF_maxLength)
Namespace.addCategoryObject('typeBinding', 'Max140Text_DE_customized', Max140Text_DE_customized)
_module_typeBindings.Max140Text_DE_customized = Max140Text_DE_customized
当我为 Max140Text_DE_customized
类型的复杂元素(按模式)赋值时,只是传递一个字符串,此元素的类型被错误识别。
一旦构建文档(由于类型错误),这不会执行模式验证。
my_elem = myschema_biddings() # some complex element
my_elem.Nm = "Foo" # no pattern validation !
type(my_elem.Nm) = <class'myschema_bidddings.Max140Text'> # wrong
my_elem.Nm = myschema_biddings.Max140Text_DE_customized("Bar")
type(my_elem.Nm) = <class'myschema_bidddings.Max140Text_DE_customized'> # correct
此行为是由于 bug in PyXB 未正确检测到您已覆盖 Nm
.
的基本 class 元素声明所致
我在基于模式投标构建 xml 后遇到 pyxb 问题。
我发现根据对一些简单 ('An atomic simple type') 元素赋值的方法,我得到了不同类型的赋值。
这是我的意思,我的详细信息:
Python2.7
PyXB 版本 1.2.5
OS: Windows 7
部分架构:
<xs:simpleType name="Max140Text_DE_customized">
<xs:restriction base="Max140Text">
<xs:minLength value="1"/>
<xs:maxLength value="140"/>
<xs:pattern value="[ ]*[A-Za-z0-9+?/:()\.,'\-][A-Za-z0-9+?/:()\.,' \-]*"/>
</xs:restriction>
</xs:simpleType>
(...)
<xs:simpleType name="Max140Text">
<xs:restriction base="xs:string">
<xs:minLength value="1"/>
<xs:maxLength value="140"/>
</xs:restriction>
</xs:simpleType>
更新:
使用 Max140Text_DE_customized
:
<xs:complexType name="PartyIdentification32_CH_pacs008">
<xs:complexContent>
<xs:restriction base="PartyIdentification32">
<xs:sequence>
<xs:element name="Nm" type="Max140Text_DE_customized" minOccurs="0"/>
<xs:element name="PstlAdr" type="PostalAddress6_customized" minOccurs="0"/>
</xs:sequence>
</xs:restriction>
</xs:complexContent>
</xs:complexType>
pyxb 生成的出价:
# Atomic simple type: {http://www.schema-uri/de/MySchema}Max140Text
class Max140Text (pyxb.binding.datatypes.string):
"""An atomic simple type."""
_ExpandedName = pyxb.namespace.ExpandedName(Namespace, 'Max140Text')
_XSDLocation = pyxb.utils.utility.Location('C:\Python27\Scripts\MySchema.xsd', 1032, 2)
_Documentation = None
Max140Text._CF_minLength = pyxb.binding.facets.CF_minLength(value=pyxb.binding.datatypes.nonNegativeInteger(1))
Max140Text._CF_maxLength = pyxb.binding.facets.CF_maxLength(value=pyxb.binding.datatypes.nonNegativeInteger(140))
Max140Text._InitializeFacetMap(Max140Text._CF_minLength,
Max140Text._CF_maxLength)
Namespace.addCategoryObject('typeBinding', 'Max140Text', Max140Text)
_module_typeBindings.Max140Text = Max140Text
# Atomic simple type: {http://www.schema-uri/de/MySchema}Max140Text_DE_customized
class Max140Text_DE_customized (Max140Text):
"""An atomic simple type."""
_ExpandedName = pyxb.namespace.ExpandedName(Namespace, 'Max140Text_DE_customized')
_XSDLocation = pyxb.utils.utility.Location('C:\Python27\Scripts\MySchema.xsd', 1038, 2)
_Documentation = None
Max140Text_DE_customized._CF_minLength = pyxb.binding.facets.CF_minLength(value=pyxb.binding.datatypes.nonNegativeInteger(1))
Max140Text_DE_customized._CF_pattern = pyxb.binding.facets.CF_pattern()
Max140Text_DE_customized._CF_pattern.addPattern(pattern="[ ]*[A-Za-z0-9+?/:()\.,'\-][A-Za-z0-9+?/:()\.,' \-]*")
Max140Text_DE_customized._CF_maxLength = pyxb.binding.facets.CF_maxLength(value=pyxb.binding.datatypes.nonNegativeInteger(140))
Max140Text_DE_customized._InitializeFacetMap(Max140Text_DE_customized._CF_minLength,
Max140Text_DE_customized._CF_pattern, Max140Text_DE_customized._CF_maxLength)
Namespace.addCategoryObject('typeBinding', 'Max140Text_DE_customized', Max140Text_DE_customized)
_module_typeBindings.Max140Text_DE_customized = Max140Text_DE_customized
当我为 Max140Text_DE_customized
类型的复杂元素(按模式)赋值时,只是传递一个字符串,此元素的类型被错误识别。
一旦构建文档(由于类型错误),这不会执行模式验证。
my_elem = myschema_biddings() # some complex element
my_elem.Nm = "Foo" # no pattern validation !
type(my_elem.Nm) = <class'myschema_bidddings.Max140Text'> # wrong
my_elem.Nm = myschema_biddings.Max140Text_DE_customized("Bar")
type(my_elem.Nm) = <class'myschema_bidddings.Max140Text_DE_customized'> # correct
此行为是由于 bug in PyXB 未正确检测到您已覆盖 Nm
.