Pyxb错误地识别简单类型

时间:2017-05-10 11:07:41

标签: python pyxb

在架构出价的基础上构建xml后,我遇到了pyxb的问题 我发现根据对某些简单('原子简单类型')元素赋值的方法,我得到了不同的类型。

这就是我所说的细节:
Python 2.7
PyXB版本1.2.5
操作系统: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+?/:()\.,&apos;\-][A-Za-z0-9+?/:()\.,&apos; \-]*"/>
    </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 

1 个答案:

答案 0 :(得分:0)

此行为是由于bug in PyXB未正确检测到您已覆盖Nm的基类元素声明。