Package pyxb :: Package binding :: Module facets |
[hide private]
[frames] | no frames]

# Source Code for Module pyxb.binding.facets

       1  # -*- coding: utf-8 -*-
       2  # Copyright 2009-2013, Peter A. Bigot
       3  #
       4  # Licensed under the Apache License, Version 2.0 (the "License"); you may
       5  # not use this file except in compliance with the License. You may obtain a
       6  # copy of the License at:
       7  #
       8  #            http://www.apache.org/licenses/LICENSE-2.0
       9  #
      10  # Unless required by applicable law or agreed to in writing, software
      11  # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
      12  # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
      13  # License for the specific language governing permissions and limitations
      14  # under the License.
      15
      16  """Classes related to XMLSchema facets.
      17
      18  The definitions herein are from sections U{4.2<http://www.w3.org/TR/xmlschema-2/index.html#rf-facets>}
      19  and U{4.3<http://www.w3.org/TR/xmlschema-2/index.html#rf-facets>} of
      20  U{XML Schema Part 2: Datatypes<http://www.w3.org/TR/xmlschema-2/>}.
      21  Facets are attributes of a datatype that constrain its lexical and
      22  value spaces.
      23
      24  """
      25
      26  import pyxb
      27  import types
      28  from . import datatypes
      29  from . import basis
      30  from pyxb.utils import utility
      31  import re
      32  import logging
      33
      34  _log = logging.getLogger(__name__)
      35
      36 -class Facet (pyxb.cscRoot):
      37      """The base class for facets.
      38
      39      This provides association with STDs, a name, and a value for the facet.
      40      """
      41
      42      _Name = None
      43      @classmethod
      44 -    def Name (self):
      45          """The name of a facet is a class constant."""
      46          return self._Name
      47
      48      __baseTypeDefinition = None
      49 -    def baseTypeDefinition (self):
      50          """The SimpleTypeDefinition component restricted by this facet.
      51
      52          Note: this is NOT the STD to which the facet belongs, but is
      53          usually that STD's base type.  I.e., this jumps us through all
      54          the containing restrictions and extensions to get to the core
      55          type definition."""
      56          return self.__baseTypeDefinition
      57
      58      __ownerTypeDefinition = None
      59 -    def ownerTypeDefinition (self):
      60          """The SimpleTypeDefinition component to which this facet belongs.
      61
      62          I.e., the one in which the hasFacet specification was found.
      63          This value is None if the facet is not associated with an
      64          STD."""
      65          return self.__ownerTypeDefinition
      66
      67      # The default valueDatatype to use for instances of this class.
      68      # This is overridden in subclasses that do not use late value
      69      # datatype bindings.
      70      _ValueDatatype = None
      71
      72      # The datatype used for facet values.
      73      __valueDatatype = None
      74 -    def valueDatatype (self):
      75          """Get the datatype used to represent values of the facet.
      76
      77          This usually has nothing to do with the owner datatype; for
      78          example, the length facet may apply to any STD but the value
      79          of the facet is an integer.  In generated bindings this is
      80          usually set explicitly in the facet constructor; when
      81          processing a schema, it is derived from the value's type
      82          definition.
      83          """
      84          if self.__valueDatatype is None:
      85              assert self.baseTypeDefinition() is not None
      86              return self.baseTypeDefinition().pythonSupport()
      87          return self.__valueDatatype
      88
      89      __value = None
      90 -    def _value (self, v): self.__value = v
      91 -    def value (self): return self.__value
      92
      93      __annotation = None
      94 -    def annotation (self): return self.__annotation
      95
      96 -    def __init__ (self, **kw):
      97          """Create a facet instance, initializing it from the keyword parameters."""
      98          super(Facet, self).__init__(**kw)
      99          # Can't create base class instances
     100          assert Facet != self.__class__
     101          self.setFromKeywords(_reset=True, _constructor=True, **kw)
     102
     103 -    def _setFromKeywords_vb (self, **kw):
     104          """Configure values of the facet from a set of keywords.
     105
     106          This method is pre-extended; subclasses should invoke the
     107          parent method after setting their local configuration.
     108
     109          @keyword _reset: If C{False} or missing, existing values will
     110                           be retained if they do not appear in the
     111                           keywords.  If C{True}, members not defined in
     112                           the keywords are set to a default.
     113          @keyword base_type_definition:
     114          @keyword owner_type_definition:
     115          @keyword value_datatype:
     116          """
     117
     118          if not kw.get('_reset', False):
     119              kw.setdefault('base_type_definition', self.__baseTypeDefinition)
     120              kw.setdefault('owner_type_definition', self.__ownerTypeDefinition)
     121              kw.setdefault('value_datatype', self.__valueDatatype)
     122          self.__baseTypeDefinition = kw.get('base_type_definition')
     123          self.__ownerTypeDefinition = kw.get('owner_type_definition')
     124          self.__valueDatatype = kw.get('value_datatype', self._ValueDatatype)
     125          # Verify that there's enough information that we should be
     126          # able to identify a PST suitable for representing facet
     127          # values.
     128          assert (self.__valueDatatype is not None) or (self.__baseTypeDefinition is not None)
     129          super_fn = getattr(super(Facet, self), '_setFromKeywords_vb', lambda *a,**kw: self)
     130          return super_fn(**kw)
     131
     132 -    def setFromKeywords (self, **kw):
     133          """Public entrypoint to the _setFromKeywords_vb call hierarchy."""
     134          return self._setFromKeywords_vb(**kw)
     135
     136      @classmethod
     137 -    def ClassForFacet (cls, name):
     138          """Given the name of a facet, return the Facet subclass that represents it."""
     139          assert cls != Facet
     140          if 0 <= name.find(':'):
     141              name = name.split(':', 1)[1]
     142          facet_class = globals().get('%s_%s' % (cls._FacetPrefix, name))
     143          if facet_class is None:
     144              raise pyxb.LogicError('Unrecognized facet name %s: expect %s' % (name, ','.join([_f._Name for _f in cls.Facets])))
     145          assert facet_class is not None
     146          return facet_class
     147
     148 -    def _valueString (self):
     149          if isinstance(self, _CollectionFacet_mixin):
     150              return u','.join([ unicode(_i) for _i in self.iteritems() ])
     151          if (self.valueDatatype() is not None) and (self.value() is not None):
     152              try:
     153                  return self.valueDatatype().XsdLiteral(self.value())
     154              except Exception:
     155                  _log.exception('Stringize facet %s produced exception', self.Name())
     156                  raise
     157          return unicode(self.value())
     158
     159 -    def __str__ (self):
     160          rv = []
     161          rv.append('%s="%s"' % (self.Name(), self._valueString()))
     162          if isinstance(self, _Fixed_mixin) and self.fixed():
     163              rv.append('[fixed]')
     164          return ''.join(rv)
     165
     166 -class ConstrainingFacet (Facet):
     167      """One of the facets defined in section 4.3, which provide
     168      constraints on the lexical space of a type definition."""
     169
     170      # The prefix used for Python classes used for a constraining
     171      # facet.  Note that this is not the prefix used when generating a
     172      # Python class member that specifies a constraining instance, even
     173      # if it happens to be the same digraph.
     174      _FacetPrefix = 'CF'
     175
     176 -    def __init__ (self, **kw):
     177          super(ConstrainingFacet, self).__init__(**kw)
     178
     179 -    def _validateConstraint_vx (self, value):
     180          raise pyxb.LogicError("Facet %s does not implement constraints" % (self.Name(),))
     181
     182 -    def validateConstraint (self, value):
     183          """Return True iff the given value satisfies the constraint represented by this facet instance.
     184
     185          The actual test is delegated to the subclasses."""
     186          return self._validateConstraint_vx(value)
     187
     188 -    def __setFromKeywords(self, **kw):
     189          kwv = kw.get('value')
     190          if kwv is not None:
     191              if not isinstance(kwv, self.valueDatatype()):
     192                  kwv = self.valueDatatype()(kwv)
     193              self._value(kwv)
     194
     195 -    def _setFromKeywords_vb (self, **kw):
     196          """Extend base class.
     197
     198          Additional keywords:
     199          * value
     200          """
     201          # NB: This uses post-extension because it makes reference to the value_data_type
     202          super_fn = getattr(super(ConstrainingFacet, self), '_setFromKeywords_vb', lambda *a,**kw: self)
     203          rv = super_fn(**kw)
     204          self.__setFromKeywords(**kw)
     205          return rv
     206
     207 -class _LateDatatype_mixin (pyxb.cscRoot):
     208      """Marker class to indicate that the facet instance must be told
     209      its datatype when it is constructed.
     210
     211      This is necessary for facets like L{CF_minInclusive} and
     212      L{CF_minExclusive}, for which the value is determined by the base
     213      type definition of the associated STD.  In some cases the value
     214      that must be used in the facet cannot be represented in the Python
     215      type used for the facet; see L{LateDatatypeBindsSuperclass}.
     216      """
     217
     218      _LateDatatypeBindsSuperclass = None
     219      """The class variable that indicates that the Subclasses must
     220      override this variable with a value of C{True} or C{False}.  The
     221      value is C{True} iff the value used for the facet is not within
     222      the value space of the corresponding value datatype; for example,
     223      L{CF_minExclusive}."""
     224
     225
     226      @classmethod
     227 -    def LateDatatypeBindsSuperclass (cls):
     228          """Return true if false if the proposed datatype should be
     229          used, or True if the base type definition of the proposed
     230          datatype should be used."""
     231          if cls._LateDatatypeBindsSuperclass is None:
     232              raise pyxb.LogicError('Class %s did not set _LateDatatypeBindsSuperclass variable.')
     233          return cls._LateDatatypeBindsSuperclass
     234
     235      @classmethod
     236 -    def BindingValueDatatype (cls, value_type):
     237          """Find the datatype for facet values when this facet is bound
     238          to the given value_type.
     239
     240          If the C{value_type} is an STD, the associated Python support
     241          datatype from this value_type scanning up through the base
     242          type hierarchy is used.
     243          """
     244
     245          import pyxb.xmlschema.structures as structures
     246          if isinstance(value_type, structures.SimpleTypeDefinition):
     247              # Back up until we find something that actually has a
     248              # datatype
     249              while not value_type.hasPythonSupport():
     250                  value_type = value_type.baseTypeDefinition()
     251              value_type = value_type.pythonSupport()
     252          assert issubclass(value_type, basis.simpleTypeDefinition)
     253          if cls.LateDatatypeBindsSuperclass():
     254              value_type = value_type.XsdSuperType()
     255          return value_type
     256
     257 -    def bindValueDatatype (self, value_datatype):
     258          self.setFromKeywords(_constructor=True, value_datatype=self.BindingValueDatatype(value_datatype))
     259
     260 -class _Fixed_mixin (pyxb.cscRoot):
     261      """Mix-in to a constraining facet that adds support for the 'fixed' property."""
     262      __fixed = None
     263 -    def fixed (self): return self.__fixed
     264
     265 -    def __setFromKeywords (self, **kw):
     266          if kw.get('_reset', False):
     267              self.__fixed = None
     268          kwv = kw.get('fixed')
     269          if kwv is not None:
     270              self.__fixed = datatypes.boolean(kwv)
     271
     272 -    def _setFromKeywords_vb (self, **kw):
     273          """Extend base class.
     274
     275          Additional keywords:
     276          * fixed
     277          """
     278          self.__setFromKeywords(**kw)
     279          super_fn = getattr(super(_Fixed_mixin, self), '_setFromKeywords_vb', lambda *a,**kw: self)
     280          return super_fn(**kw)
     281
     282 -class _CollectionFacet_mixin (pyxb.cscRoot):
     283      """Mix-in to handle facets whose values are collections, not scalars.
     284
     285      For example, the enumeration and pattern facets maintain a list of
     286      enumeration values and patterns, respectively, as their value
     287      space.
     288
     289      Subclasses must define a class variable _CollectionFacet_itemType
     290      which is a reference to a class that is used to construct members
     291      of the collection.
     292      """
     293
     294      __items = None
     295 -    def _setFromKeywords_vb (self, **kw):
     296          """Extend base class.
     297
     298          @keyword _constructor: If C{False} or absent, the object being
     299                                 set is a member of the collection.  If
     300                                 C{True}, the object being set is the
     301                                 collection itself.
     302          """
     303          if kw.get('_reset', False):
     304              self.__items = []
     305          if not kw.get('_constructor', False):
     306              self.__items.append(self._CollectionFacet_itemType(facet_instance=self, **kw))
     307          super_fn = getattr(super(_CollectionFacet_mixin, self), '_setFromKeywords_vb', lambda *a,**kw: self)
     308          return super_fn(**kw)
     309
     310 -    def _items (self):
     311          """The members of the collection, as a reference."""
     312          return self.__items
     313
     314 -    def items (self):
     315          """The members of the collection, as a copy."""
     316          return self.__items[:]
     317
     318 -    def iteritems (self):
     319          """The members of the collection as an iterator"""
     320          return iter(self.__items)
     321
     322 -class CF_length (ConstrainingFacet, _Fixed_mixin):
     323      """A facet that specifies the length of the lexical representation of a value.
     324
     325      See U{http://www.w3.org/TR/xmlschema-2/#rf-length}
     326      """
     327      _Name = 'length'
     328      _ValueDatatype = datatypes.nonNegativeInteger
     329
     330 -    def _validateConstraint_vx (self, value):
     331          value_length = value.xsdValueLength()
     332          return (value_length is None) or (self.value() is None) or (value_length == self.value())
     333
     334 -class CF_minLength (ConstrainingFacet, _Fixed_mixin):
     335      """A facet that constrains the length of the lexical representation of a value.
     336
     337      See U{http://www.w3.org/TR/xmlschema-2/#rf-minLength}
     338      """
     339      _Name = 'minLength'
     340      _ValueDatatype = datatypes.nonNegativeInteger
     341
     342 -    def _validateConstraint_vx (self, value):
     343          value_length = value.xsdValueLength()
     344          return (value_length is None) or (self.value() is None) or (value_length >= self.value())
     345
     346 -class CF_maxLength (ConstrainingFacet, _Fixed_mixin):
     347      """A facet that constrains the length of the lexical representation of a value.
     348
     349      See U{http://www.w3.org/TR/xmlschema-2/#rf-minLength}
     350      """
     351      _Name = 'maxLength'
     352      _ValueDatatype = datatypes.nonNegativeInteger
     353
     354 -    def _validateConstraint_vx (self, value):
     355          value_length = value.xsdValueLength()
     356          return (value_length is None) or (self.value() is None) or (value_length <= self.value())
     357
     358  import pyxb.utils.xmlre
     359
     360 -class _PatternElement (utility.PrivateTransient_mixin):
     361      """This class represents individual patterns that appear within a CF_pattern collection."""
     362
     363      # The compiled regular expression is marked transient because we
     364      # normally do development with Python 2.5, and consequently save
     365      # the pickled namespace archives that go into the distribution
     366      # with that version.  Compiled regular expressions in Python 2.5
     367      # include a reference to the re._compile method, which does not
     368      # exist in Python 2.4.  As a result, attempts to load a namespace
     369      # which includes types with pattern restrictions fail.
     370      __PrivateTransient = set()
     371
     372      __compiledExpression = None
     373      __PrivateTransient.add('compiledExpression')
     374
     375      __pythonExpression = None
     376
     377      pattern = None
     378      annotation = None
     379 -    def __init__ (self, pattern=None, value=None, annotation=None, **kw):
     380          if pattern is None:
     381              assert value is not None
     382              pattern = value
     383          assert isinstance(pattern, types.StringTypes)
     384          self.pattern = pattern
     385          if isinstance(annotation, types.StringTypes):
     386              self.annotation = annotation
     387          self.__pythonExpression = pyxb.utils.xmlre.XMLToPython(pattern)
     388          super(_PatternElement, self).__init__()
     389
     390 -    def __str__ (self): return self.pattern
     391
     392 -    def matches (self, text):
     393          if self.__compiledExpression is None:
     394              self.__compiledExpression = re.compile(self.__pythonExpression)
     395          return self.__compiledExpression.match(text)
     396
     397 -class CF_pattern (ConstrainingFacet, _CollectionFacet_mixin):
     398      """A facet that constrains the lexical representation of a value
     399      to match one of a set of patterns.
     400
     401      See U{http://www.w3.org/TR/xmlschema-2/#rf-pattern}
     402
     403      @note: In PyXB, pattern constraints are ignored for any type with
     404      a Python representation that does not derive from C{basestring}.
     405      This is due to the difficulty in reconstructing the lexical
     406      representation of a non-string type after it has been converted to
     407      its value space.
     408
     409      @todo: On creating new instances of non-string simple types from
     410      string representations, we could apply pattern constraints.  That
     411      would mean checking them prior to invoking the Factory method.
     412      """
     413      _Name = 'pattern'
     414      _CollectionFacet_itemType = _PatternElement
     415      _ValueDatatype = datatypes.string
     416
     417      __patternElements = None
     418 -    def patternElements (self): return self.__patternElements
     419
     420 -    def __init__ (self, **kw):
     421          super(CF_pattern, self).__init__(**kw)
     422          self.__patternElements = []
     423
     424 -    def addPattern (self, **kw):
     425          pattern = self._CollectionFacet_itemType(**kw)
     426          self.__patternElements.append(pattern)
     427          return pattern
     428
     429 -    def _validateConstraint_vx (self, value):
     430          # If validation is inhibited, or if the facet hasn't had any
     431          # restrictions applied yet, return True.
     432          if 0 == len(self.__patternElements):
     433              return True
     434          if not isinstance(value, basestring):
     435              return True
     436          for pe in self.__patternElements:
     437              if pe.matches(value):
     438                  return True
     439          return False
     440
     441 -class _EnumerationElement (object):
     442      """This class represents individual values that appear within a
     443      L{CF_enumeration} collection."""
     444
     445      __value = None
     446 -    def value (self):
     447          """The Python value that is used for equality testing
     448          against this enumeration.
     449
     450          This is an instance of L{enumeration.valueDatatype()<CF_enumeration.valueDatatype>},
     451          initialized from the unicodeValue."""
     452          return self.__value
     453
     454      __tag = None
     455 -    def tag (self):
     456          """The Python identifier used for the named constant representing
     457          the enumeration value.
     458
     459          This should include any desired prefix, since it must be
     460          unique within its binding class.  If C{None}, no enumeration
     461          constant will be generated."""
     462          return self.__tag
     463 -    def _setTag (self, tag):
     464          """Set the tag to be used for this enumeration."""
     465          self.__tag = tag
     466
     467      __enumeration = None
     468 -    def enumeration (self):
     469          """A reference to the L{CF_enumeration} instance that owns this element."""
     470          return self.__enumeration
     471
     472      __unicodeValue = None
     473 -    def unicodeValue (self):
     474          """The unicode string that defines the enumeration value."""
     475          return self.__unicodeValue
     476
     477 -    def __init__ (self, enumeration=None, unicode_value=None,
     478                    description=None, annotation=None, tag=None,
     479                    **kw):
     480          # The preferred keyword is "unicode_value", but when being
     481          # generically applied by
     482          # structures.SimpleTypeDefinition.__updateFacets, the unicode
     483          # value comes in through the keyword "value".  Similarly for
     484          # "enumeration" and "facet_instance".
     485          if unicode_value is None:
     486              unicode_value = kw['value']
     487          if enumeration is None:
     488              enumeration = kw['facet_instance']
     489          self.__unicodeValue = unicode_value
     490          self.__enumeration = enumeration
     491          self.__description = description
     492          self.__annotation = annotation
     493          self.__tag = tag
     494
     495          assert self.__enumeration is not None
     496
     497          value_datatype = self.enumeration().valueDatatype()
     498          self.__value = value_datatype.Factory(self.unicodeValue(), _validate_constraints=False, _from_xml=True)
     499
     500          if (self.__description is None) and (self.__annotation is not None):
     501              self.__description = unicode(self.__annotation)
     502
     503 -    def __str__ (self):
     504          return utility.QuotedEscaped(self.unicodeValue())
     505
     506 -class CF_enumeration (ConstrainingFacet, _CollectionFacet_mixin, _LateDatatype_mixin):
     507      """Capture a constraint that restricts valid values to a fixed set.
     508
     509      A STD that has an enumeration restriction should mix-in
     510      L{pyxb.binding.basis.enumeration_mixin}, and should have a class
     511      variable titled C{_CF_enumeration} that is an instance of this
     512      class.
     513
     514      "unicode" refers to the Unicode string by which the value is
     515      represented in XML.
     516
     517      "tag" refers to the Python member reference associated with the
     518      enumeration.  The value is derived from the unicode value of the
     519      enumeration element and an optional prefix that identifies the
     520      owning simple type when the tag is promoted to module-level
     521      visibility.
     522
     523      "value" refers to the Python value held in the tag
     524
     525      See U{http://www.w3.org/TR/xmlschema-2/#rf-enumeration}
     526      """
     527      _Name = 'enumeration'
     528      _CollectionFacet_itemType = _EnumerationElement
     529      _LateDatatypeBindsSuperclass = False
     530
     531      __tagToElement = None
     532      __valueToElement = None
     533      __unicodeToElement = None
     534
     535      # The prefix to be used when making enumeration tags visible at
     536      # the module level.  If None, tags are not made visible.
     537      __enumPrefix = None
     538
     539 -    def __init__ (self, **kw):
     540          super(CF_enumeration, self).__init__(**kw)
     541          self.__enumPrefix = kw.get('enum_prefix', self.__enumPrefix)
     542          self.__tagToElement = { }
     543          self.__valueToElement = { }
     544          self.__unicodeToElement = { }
     545
     546 -    def enumPrefix (self):
     547          return self.__enumPrefix
     548
     549 -    def elements (self):
     550          """@deprecated: Use L{items} or L{iteritems} instead."""
     551          return self.items()
     552
     553 -    def values (self):
     554          """Return a list of enumeration values."""
     555          return [ _ee.value() for _ee in self.iteritems() ]
     556
     557 -    def itervalues (self):
     558          """Generate the enumeration values."""
     559          for ee in self.iteritems():
     560              yield ee.value()
     561
     562 -    def addEnumeration (self, **kw):
     563          kw['enumeration'] = self
     564          ee = _EnumerationElement(**kw)
     565          assert not (ee.tag in self.__tagToElement)
     566          self.__tagToElement[ee.tag()] = ee
     567          self.__unicodeToElement[ee.unicodeValue()] = ee
     568          value = ee.value()
     569          # Not just issubclass(self.valueDatatype(), basis.STD_list);
     570          # this may be a union with one of those as a member type.
     571          if isinstance(value, list):
     572              value = ' '.join([ _v.xsdLiteral() for _v in value ])
     573          self.__valueToElement[value] = ee
     574          self._items().append(ee)
     575          return value
     576
     577 -    def elementForValue (self, value):
     578          """Return the L{_EnumerationElement} instance that has the given value.
     579
     580          @raise KeyError: the value is not valid for the enumeration."""
     581          return self.__valueToElement[value]
     582
     583 -    def valueForUnicode (self, ustr):
     584          """Return the enumeration value corresponding to the given unicode string.
     585
     586          If ustr is not a valid option for this enumeration, return None."""
     587          rv = self.__unicodeToElement.get(ustr)
     588          if rv is not None:
     589              rv = rv.value()
     590          return rv
     591
     592 -    def _validateConstraint_vx (self, value):
     593          # If validation is inhibited, or if the facet hasn't had any
     594          # restrictions applied yet, return True.
     595          if 0 == len(self._items()):
     596              return True
     597          for ee in self.iteritems():
     598              if ee.value() == value:
     599                  return True
     600          return False
     601
     602 -class _Enumeration_mixin (pyxb.cscRoot):
     603      """Marker class to indicate that the generated binding has enumeration members."""
     604      @classmethod
     605 -    def valueForUnicode (cls, ustr):
     606          return cls._CF_enumeration.valueForUnicode(ustr)
     607
     608 -class _WhiteSpace_enum (datatypes.NMTOKEN, _Enumeration_mixin):
     609      """The enumeration used to constrain the whiteSpace facet"""
     610      pass
     611  _WhiteSpace_enum._CF_enumeration = CF_enumeration(value_datatype=_WhiteSpace_enum)
     612  _WhiteSpace_enum.preserve = _WhiteSpace_enum._CF_enumeration.addEnumeration(unicode_value=u'preserve', tag='preserve')
     613  _WhiteSpace_enum.replace = _WhiteSpace_enum._CF_enumeration.addEnumeration(unicode_value=u'replace', tag='replace')
     614  _WhiteSpace_enum.collapse = _WhiteSpace_enum._CF_enumeration.addEnumeration(unicode_value=u'collapse', tag='collapse')
     615  # NOTE: For correctness we really need to initialize the facet map for
     616  # WhiteSpace_enum, even though at the moment it isn't necessary.  We
     617  # can't right now, because its parent datatypes.NMTOKEN hasn't been
     618  # initialized yet
     619  _WhiteSpace_enum._InitializeFacetMap(_WhiteSpace_enum._CF_enumeration)
     620
     621 -class CF_whiteSpace (ConstrainingFacet, _Fixed_mixin):
     622      """Specify the value-space interpretation of whitespace.
     623
     624      See U{http://www.w3.org/TR/xmlschema-2/#rf-whiteSpace}
     625      """
     626      _Name = 'whiteSpace'
     627      _ValueDatatype = _WhiteSpace_enum
     628
     629      __TabCRLF_re = re.compile("[\t\n\r]")
     630      __MultiSpace_re = re.compile(" +")
     631 -    def normalizeString (self, value):
     632          """Normalize the given string in accordance with the configured whitespace interpretation."""
     633          if self.value() is None:
     634              return value
     635          if self.value() == _WhiteSpace_enum.preserve:
     636              return utility.NormalizeWhitespace(value, preserve=True)
     637          if self.value() == _WhiteSpace_enum.replace:
     638              return utility.NormalizeWhitespace(value, replace=True)
     639          assert self.value() == _WhiteSpace_enum.collapse, 'Unexpected value "%s" for whiteSpace facet' % (self.value(),)
     640          return utility.NormalizeWhitespace(value, collapse=True)
     641
     642 -    def _validateConstraint_vx (self, value):
     643          """No validation rules for whitespace facet."""
     644          return True
     645
     646 -class CF_minInclusive (ConstrainingFacet, _Fixed_mixin, _LateDatatype_mixin):
     647      """Specify the minimum legal value for the constrained type.
     648
     649      See U{http://www.w3.org/TR/xmlschema-2/#rf-minInclusive}
     650      """
     651      _Name = 'minInclusive'
     652      _LateDatatypeBindsSuperclass = False
     653
     654 -    def _validateConstraint_vx (self, value):
     655          return (self.value() is None) or (self.value() <= value)
     656
     657
     658 -class CF_maxInclusive (ConstrainingFacet, _Fixed_mixin, _LateDatatype_mixin):
     659      """Specify the maximum legal value for the constrained type.
     660
     661      See U{http://www.w3.org/TR/xmlschema-2/#rf-maxInclusive}
     662      """
     663      _Name = 'maxInclusive'
     664      _LateDatatypeBindsSuperclass = False
     665
     666 -    def _validateConstraint_vx (self, value):
     667          return (self.value() is None) or (self.value() >= value)
     668
     669 -class CF_minExclusive (ConstrainingFacet, _Fixed_mixin, _LateDatatype_mixin):
     670      """Specify the exclusive lower bound of legal values for the constrained type.
     671
     672      See U{http://www.w3.org/TR/xmlschema-2/#rf-minExclusive}
     673      """
     674      _Name = 'minExclusive'
     675      _LateDatatypeBindsSuperclass = True
     676
     677 -    def _validateConstraint_vx (self, value):
     678          return (self.value() is None) or (self.value() < value)
     679
     680 -class CF_maxExclusive (ConstrainingFacet, _Fixed_mixin, _LateDatatype_mixin):
     681      """Specify the exclusive upper bound of legal values for the constrained type.
     682
     683      See U{http://www.w3.org/TR/xmlschema-2/#rf-maxExclusive}
     684      """
     685      _Name = 'maxExclusive'
     686      _LateDatatypeBindsSuperclass = True
     687
     688 -    def _validateConstraint_vx (self, value):
     689          return (self.value() is None) or (self.value() > value)
     690
     691 -class CF_totalDigits (ConstrainingFacet, _Fixed_mixin):
     692      """Specify the number of digits in the *value* space of the type.
     693
     694      See U{http://www.w3.org/TR/xmlschema-2/#rf-totalDigits}
     695      """
     696      _Name = 'totalDigits'
     697      _ValueDatatype = datatypes.positiveInteger
     698
     699 -    def _validateConstraint_vx (self, value):
     700          if self.value() is None:
     701              return True
     702          n = 0
     703          scale = 1
     704          match = False
     705          v = None
     706          while (n <= self.value()) and (not match):
     707              v = long(value * scale)
     708              match = ((value * scale) == v)
     709              if self.value() == n:
     710                  break
     711              n += 1
     712              scale *= 10
     713          while n < self.value():
     714              n += 1
     715              scale *= 10
     716          return match and (v is not None) and (abs(v) < scale)
     717
     718 -class CF_fractionDigits (ConstrainingFacet, _Fixed_mixin):
     719      """Specify the number of sub-unit digits in the *value* space of the type.
     720
     721      See U{http://www.w3.org/TR/xmlschema-2/#rf-fractionDigits}
     722      """
     723      _Name = 'fractionDigits'
     724      _ValueDatatype = datatypes.nonNegativeInteger
     725
     726 -    def _validateConstraint_vx (self, value):
     727          if self.value() is None:
     728              return True
     729          n = 0
     730          scale = 1
     731          while n <= self.value():
     732              if ((value * scale) == long(value * scale)):
     733                  return True
     734              n += 1
     735              scale *= 10
     736          return False
     737
     738 -class FundamentalFacet (Facet):
     739      """A fundamental facet provides information on the value space of the associated type."""
     740
     741      _FacetPrefix = 'FF'
     742
     743      @classmethod
     744 -    def CreateFromDOM (cls, node, owner_type_definition, base_type_definition=None):
     745          facet_class = cls.ClassForFacet(node.getAttribute('name'))
     746          rv = facet_class(base_type_definition=base_type_definition,
     747                           owner_type_definition=owner_type_definition)
     748          rv.updateFromDOM(node)
     749
     750 -    def updateFromDOM (self, node):
     751          if not node.hasAttribute('name'):
     752              raise pyxb.SchemaValidationError('No name attribute in facet')
     753          assert node.getAttribute('name') == self.Name()
     754          self._updateFromDOM(node)
     755
     756 -    def _updateFromDOM (self, node):
     757          try:
     758              super(FundamentalFacet, self)._updateFromDOM(node)
     759          except AttributeError:
     760              pass
     761          if (self.valueDatatype() is not None) and node.hasAttribute('value'):
     762              self._value(self.valueDatatype()(node.getAttribute('value')))
     763          # @todo
     764          self.__annotation = None
     765          return self
     766
     767 -class FF_equal (FundamentalFacet):
     768      """Specifies that the associated type supports a notion of equality.
     769
     770      See U{http://www.w3.org/TR/xmlschema-2/#equal}
     771      """
     772
     773      _Name = 'equal'
     774
     775 -class FF_ordered (FundamentalFacet):
     776      """Specifies that the associated type supports a notion of order.
     777
     778      See U{http://www.w3.org/TR/xmlschema-2/#rf-ordered}
     779      """
     780
     781      _LegalValues = ( 'false', 'partial', 'total' )
     782      _Name = 'ordered'
     783      _ValueDatatype = datatypes.string
     784
     785 -    def __init__ (self, **kw):
     786          # @todo: correct value type definition
     787          super(FF_ordered, self).__init__(**kw)
     788
     789 -class FF_bounded (FundamentalFacet):
     790      """Specifies that the associated type supports a notion of bounds.
     791
     792      See U{http://www.w3.org/TR/xmlschema-2/#rf-bounded}
     793      """
     794
     795      _Name = 'bounded'
     796      _ValueDatatype = datatypes.boolean
     797
     798 -class FF_cardinality (FundamentalFacet):
     799      """Specifies that the associated type supports a notion of length.
     800
     801      See U{http://www.w3.org/TR/xmlschema-2/#rf-cardinality}
     802      """
     803
     804      _LegalValues = ( 'finite', 'countably infinite' )
     805      _Name = 'cardinality'
     806      _ValueDatatype = datatypes.string
     807 -    def __init__ (self, **kw):
     808          # @todo correct value type definition
     809          super(FF_cardinality, self).__init__(value_datatype=datatypes.string, **kw)
     810
     811 -class FF_numeric (FundamentalFacet):
     812      """Specifies that the associated type represents a number.
     813
     814      See U{http://www.w3.org/TR/xmlschema-2/#rf-numeric}
     815      """
     816
     817      _Name = 'numeric'
     818      _ValueDatatype = datatypes.boolean
     819
     820  # The fixed set of expected facets
     821  ConstrainingFacet.Facets = [
     822      CF_length, CF_minLength, CF_maxLength, CF_pattern, CF_enumeration,
     823      CF_whiteSpace, CF_minInclusive, CF_maxInclusive, CF_minExclusive,
     824      CF_maxExclusive, CF_totalDigits, CF_fractionDigits ]
     825
     826  FundamentalFacet.Facets = [
     827      FF_equal, FF_ordered, FF_bounded, FF_cardinality, FF_numeric ]
     828
     829  Facet.Facets = []
     830  Facet.Facets.extend(ConstrainingFacet.Facets)
     831  Facet.Facets.extend(FundamentalFacet.Facets)
     832
     833  # Facet details from a hacked generator reading the normative schema
     834  # and only printing the facet-related code.
     835  datatypes.ENTITIES._CF_pattern = CF_pattern()
     836  datatypes.ENTITIES._CF_maxLength = CF_maxLength()
     837  datatypes.ENTITIES._CF_enumeration = CF_enumeration(value_datatype=datatypes.ENTITIES)
     838  datatypes.ENTITIES._CF_minLength = CF_minLength(value=datatypes.nonNegativeInteger(1L))
     839  datatypes.ENTITIES._CF_whiteSpace = CF_whiteSpace()
     840  datatypes.ENTITIES._CF_length = CF_length()
     841  datatypes.ENTITIES._InitializeFacetMap(datatypes.ENTITIES._CF_pattern,
     842     datatypes.ENTITIES._CF_maxLength,
     843     datatypes.ENTITIES._CF_enumeration,
     844     datatypes.ENTITIES._CF_minLength,
     845     datatypes.ENTITIES._CF_whiteSpace,
     846     datatypes.ENTITIES._CF_length)
     847  datatypes.ENTITY._InitializeFacetMap()
     848  datatypes.ID._InitializeFacetMap()
     849  datatypes.IDREF._InitializeFacetMap()
     850  datatypes.IDREFS._CF_pattern = CF_pattern()
     851  datatypes.IDREFS._CF_maxLength = CF_maxLength()
     852  datatypes.IDREFS._CF_enumeration = CF_enumeration(value_datatype=datatypes.IDREFS)
     853  datatypes.IDREFS._CF_minLength = CF_minLength(value=datatypes.nonNegativeInteger(1L))
     854  datatypes.IDREFS._CF_whiteSpace = CF_whiteSpace()
     855  datatypes.IDREFS._CF_length = CF_length()
     856  datatypes.IDREFS._InitializeFacetMap(datatypes.IDREFS._CF_pattern,
     857     datatypes.IDREFS._CF_maxLength,
     858     datatypes.IDREFS._CF_enumeration,
     859     datatypes.IDREFS._CF_minLength,
     860     datatypes.IDREFS._CF_whiteSpace,
     861     datatypes.IDREFS._CF_length)
     862  datatypes.NCName._CF_pattern = CF_pattern()
     863  datatypes.NCName._CF_pattern.addPattern(pattern=u'[\\i-[:]][\\c-[:]]*')
     864  datatypes.NCName._InitializeFacetMap(datatypes.NCName._CF_pattern)
     865  datatypes.NMTOKEN._CF_pattern = CF_pattern()
     866  datatypes.NMTOKEN._CF_pattern.addPattern(pattern=u'\\c+')
     867  datatypes.NMTOKEN._InitializeFacetMap(datatypes.NMTOKEN._CF_pattern)
     868  datatypes.NMTOKENS._CF_pattern = CF_pattern()
     869  datatypes.NMTOKENS._CF_maxLength = CF_maxLength()
     870  datatypes.NMTOKENS._CF_enumeration = CF_enumeration(value_datatype=datatypes.NMTOKENS)
     871  datatypes.NMTOKENS._CF_minLength = CF_minLength(value=datatypes.nonNegativeInteger(1L))
     872  datatypes.NMTOKENS._CF_whiteSpace = CF_whiteSpace()
     873  datatypes.NMTOKENS._CF_length = CF_length()
     874  datatypes.NMTOKENS._InitializeFacetMap(datatypes.NMTOKENS._CF_pattern,
     875     datatypes.NMTOKENS._CF_maxLength,
     876     datatypes.NMTOKENS._CF_enumeration,
     877     datatypes.NMTOKENS._CF_minLength,
     878     datatypes.NMTOKENS._CF_whiteSpace,
     879     datatypes.NMTOKENS._CF_length)
     880  datatypes.NOTATION._CF_minLength = CF_minLength()
     881  datatypes.NOTATION._CF_maxLength = CF_maxLength()
     882  datatypes.NOTATION._CF_enumeration = CF_enumeration(value_datatype=datatypes.NOTATION)
     883  datatypes.NOTATION._CF_pattern = CF_pattern()
     884  datatypes.NOTATION._CF_whiteSpace = CF_whiteSpace(value=_WhiteSpace_enum.collapse)
     885  datatypes.NOTATION._CF_length = CF_length()
     886  datatypes.NOTATION._InitializeFacetMap(datatypes.NOTATION._CF_minLength,
     887     datatypes.NOTATION._CF_maxLength,
     888     datatypes.NOTATION._CF_enumeration,
     889     datatypes.NOTATION._CF_pattern,
     890     datatypes.NOTATION._CF_whiteSpace,
     891     datatypes.NOTATION._CF_length)
     892  datatypes.Name._CF_pattern = CF_pattern()
     893  datatypes.Name._CF_pattern.addPattern(pattern=u'\\i\\c*')
     894  datatypes.Name._InitializeFacetMap(datatypes.Name._CF_pattern)
     895  datatypes.QName._CF_minLength = CF_minLength()
     896  datatypes.QName._CF_maxLength = CF_maxLength()
     897  datatypes.QName._CF_enumeration = CF_enumeration(value_datatype=datatypes.QName)
     898  datatypes.QName._CF_pattern = CF_pattern()
     899  datatypes.QName._CF_whiteSpace = CF_whiteSpace(value=_WhiteSpace_enum.collapse)
     900  datatypes.QName._CF_length = CF_length()
     901  datatypes.QName._InitializeFacetMap(datatypes.QName._CF_minLength,
     902     datatypes.QName._CF_maxLength,
     903     datatypes.QName._CF_enumeration,
     904     datatypes.QName._CF_pattern,
     905     datatypes.QName._CF_whiteSpace,
     906     datatypes.QName._CF_length)
     907  datatypes.anyURI._CF_minLength = CF_minLength()
     908  datatypes.anyURI._CF_maxLength = CF_maxLength()
     909  datatypes.anyURI._CF_enumeration = CF_enumeration(value_datatype=datatypes.anyURI)
     910  datatypes.anyURI._CF_pattern = CF_pattern()
     911  datatypes.anyURI._CF_whiteSpace = CF_whiteSpace(value=_WhiteSpace_enum.collapse)
     912  datatypes.anyURI._CF_length = CF_length()
     913  datatypes.anyURI._InitializeFacetMap(datatypes.anyURI._CF_minLength,
     914     datatypes.anyURI._CF_maxLength,
     915     datatypes.anyURI._CF_enumeration,
     916     datatypes.anyURI._CF_pattern,
     917     datatypes.anyURI._CF_whiteSpace,
     918     datatypes.anyURI._CF_length)
     919  datatypes.base64Binary._CF_minLength = CF_minLength()
     920  datatypes.base64Binary._CF_maxLength = CF_maxLength()
     921  datatypes.base64Binary._CF_enumeration = CF_enumeration(value_datatype=datatypes.base64Binary)
     922  datatypes.base64Binary._CF_pattern = CF_pattern()
     923  datatypes.base64Binary._CF_whiteSpace = CF_whiteSpace(value=_WhiteSpace_enum.collapse)
     924  datatypes.base64Binary._CF_length = CF_length()
     925  datatypes.base64Binary._InitializeFacetMap(datatypes.base64Binary._CF_minLength,
     926     datatypes.base64Binary._CF_maxLength,
     927     datatypes.base64Binary._CF_enumeration,
     928     datatypes.base64Binary._CF_pattern,
     929     datatypes.base64Binary._CF_whiteSpace,
     930     datatypes.base64Binary._CF_length)
     931  datatypes.boolean._CF_whiteSpace = CF_whiteSpace(value=_WhiteSpace_enum.collapse)
     932  datatypes.boolean._CF_pattern = CF_pattern()
     933  datatypes.boolean._InitializeFacetMap(datatypes.boolean._CF_whiteSpace,
     934     datatypes.boolean._CF_pattern)
     935  datatypes.byte._CF_minInclusive = CF_minInclusive(value_datatype=datatypes.byte, value=datatypes.anySimpleType(u'-128'))
     936  datatypes.byte._CF_maxInclusive = CF_maxInclusive(value_datatype=datatypes.byte, value=datatypes.anySimpleType(u'127'))
     937  datatypes.byte._InitializeFacetMap(datatypes.byte._CF_minInclusive,
     938     datatypes.byte._CF_maxInclusive)
     939  datatypes.date._CF_pattern = CF_pattern()
     940  datatypes.date._CF_minInclusive = CF_minInclusive(value_datatype=datatypes.date)
     941  datatypes.date._CF_maxExclusive = CF_maxExclusive(value_datatype=datatypes.anySimpleType)
     942  datatypes.date._CF_minExclusive = CF_minExclusive(value_datatype=datatypes.anySimpleType)
     943  datatypes.date._CF_enumeration = CF_enumeration(value_datatype=datatypes.date)
     944  datatypes.date._CF_whiteSpace = CF_whiteSpace(value=_WhiteSpace_enum.collapse)
     945  datatypes.date._CF_maxInclusive = CF_maxInclusive(value_datatype=datatypes.date)
     946  datatypes.date._InitializeFacetMap(datatypes.date._CF_pattern,
     947     datatypes.date._CF_minInclusive,
     948     datatypes.date._CF_maxExclusive,
     949     datatypes.date._CF_minExclusive,
     950     datatypes.date._CF_enumeration,
     951     datatypes.date._CF_whiteSpace,
     952     datatypes.date._CF_maxInclusive)
     953  datatypes.dateTime._CF_pattern = CF_pattern()
     954  datatypes.dateTime._CF_minInclusive = CF_minInclusive(value_datatype=datatypes.dateTime)
     955  datatypes.dateTime._CF_maxExclusive = CF_maxExclusive(value_datatype=datatypes.anySimpleType)
     956  datatypes.dateTime._CF_minExclusive = CF_minExclusive(value_datatype=datatypes.anySimpleType)
     957  datatypes.dateTime._CF_enumeration = CF_enumeration(value_datatype=datatypes.dateTime)
     958  datatypes.dateTime._CF_whiteSpace = CF_whiteSpace(value=_WhiteSpace_enum.collapse)
     959  datatypes.dateTime._CF_maxInclusive = CF_maxInclusive(value_datatype=datatypes.dateTime)
     960  datatypes.dateTime._InitializeFacetMap(datatypes.dateTime._CF_pattern,
     961     datatypes.dateTime._CF_minInclusive,
     962     datatypes.dateTime._CF_maxExclusive,
     963     datatypes.dateTime._CF_minExclusive,
     964     datatypes.dateTime._CF_enumeration,
     965     datatypes.dateTime._CF_whiteSpace,
     966     datatypes.dateTime._CF_maxInclusive)
     967  datatypes.decimal._CF_totalDigits = CF_totalDigits()
     968  datatypes.decimal._CF_pattern = CF_pattern()
     969  datatypes.decimal._CF_minInclusive = CF_minInclusive(value_datatype=datatypes.decimal)
     970  datatypes.decimal._CF_maxExclusive = CF_maxExclusive(value_datatype=datatypes.anySimpleType)
     971  datatypes.decimal._CF_minExclusive = CF_minExclusive(value_datatype=datatypes.anySimpleType)
     972  datatypes.decimal._CF_enumeration = CF_enumeration(value_datatype=datatypes.decimal)
     973  datatypes.decimal._CF_whiteSpace = CF_whiteSpace(value=_WhiteSpace_enum.collapse)
     974  datatypes.decimal._CF_fractionDigits = CF_fractionDigits()
     975  datatypes.decimal._CF_maxInclusive = CF_maxInclusive(value_datatype=datatypes.decimal)
     976  datatypes.decimal._InitializeFacetMap(datatypes.decimal._CF_totalDigits,
     977     datatypes.decimal._CF_pattern,
     978     datatypes.decimal._CF_minInclusive,
     979     datatypes.decimal._CF_maxExclusive,
     980     datatypes.decimal._CF_minExclusive,
     981     datatypes.decimal._CF_enumeration,
     982     datatypes.decimal._CF_whiteSpace,
     983     datatypes.decimal._CF_fractionDigits,
     984     datatypes.decimal._CF_maxInclusive)
     985  datatypes.double._CF_pattern = CF_pattern()
     986  datatypes.double._CF_minInclusive = CF_minInclusive(value_datatype=datatypes.double)
     987  datatypes.double._CF_maxExclusive = CF_maxExclusive(value_datatype=datatypes.anySimpleType)
     988  datatypes.double._CF_minExclusive = CF_minExclusive(value_datatype=datatypes.anySimpleType)
     989  datatypes.double._CF_enumeration = CF_enumeration(value_datatype=datatypes.double)
     990  datatypes.double._CF_whiteSpace = CF_whiteSpace(value=_WhiteSpace_enum.collapse)
     991  datatypes.double._CF_maxInclusive = CF_maxInclusive(value_datatype=datatypes.double)
     992  datatypes.double._InitializeFacetMap(datatypes.double._CF_pattern,
     993     datatypes.double._CF_minInclusive,
     994     datatypes.double._CF_maxExclusive,
     995     datatypes.double._CF_minExclusive,
     996     datatypes.double._CF_enumeration,
     997     datatypes.double._CF_whiteSpace,
     998     datatypes.double._CF_maxInclusive)
     999  datatypes.duration._CF_pattern = CF_pattern()
    1000  datatypes.duration._CF_minInclusive = CF_minInclusive(value_datatype=datatypes.duration)
    1001  datatypes.duration._CF_maxExclusive = CF_maxExclusive(value_datatype=datatypes.anySimpleType)
    1002  datatypes.duration._CF_minExclusive = CF_minExclusive(value_datatype=datatypes.anySimpleType)
    1003  datatypes.duration._CF_enumeration = CF_enumeration(value_datatype=datatypes.duration)
    1004  datatypes.duration._CF_whiteSpace = CF_whiteSpace(value=_WhiteSpace_enum.collapse)
    1005  datatypes.duration._CF_maxInclusive = CF_maxInclusive(value_datatype=datatypes.duration)
    1006  datatypes.duration._InitializeFacetMap(datatypes.duration._CF_pattern,
    1007     datatypes.duration._CF_minInclusive,
    1008     datatypes.duration._CF_maxExclusive,
    1009     datatypes.duration._CF_minExclusive,
    1010     datatypes.duration._CF_enumeration,
    1011     datatypes.duration._CF_whiteSpace,
    1012     datatypes.duration._CF_maxInclusive)
    1013  datatypes.float._CF_pattern = CF_pattern()
    1014  datatypes.float._CF_minInclusive = CF_minInclusive(value_datatype=datatypes.float)
    1015  datatypes.float._CF_maxExclusive = CF_maxExclusive(value_datatype=datatypes.anySimpleType)
    1016  datatypes.float._CF_minExclusive = CF_minExclusive(value_datatype=datatypes.anySimpleType)
    1017  datatypes.float._CF_enumeration = CF_enumeration(value_datatype=datatypes.float)
    1018  datatypes.float._CF_whiteSpace = CF_whiteSpace(value=_WhiteSpace_enum.collapse)
    1019  datatypes.float._CF_maxInclusive = CF_maxInclusive(value_datatype=datatypes.float)
    1020  datatypes.float._InitializeFacetMap(datatypes.float._CF_pattern,
    1021     datatypes.float._CF_minInclusive,
    1022     datatypes.float._CF_maxExclusive,
    1023     datatypes.float._CF_minExclusive,
    1024     datatypes.float._CF_enumeration,
    1025     datatypes.float._CF_whiteSpace,
    1026     datatypes.float._CF_maxInclusive)
    1027  datatypes.gDay._CF_pattern = CF_pattern()
    1028  datatypes.gDay._CF_minInclusive = CF_minInclusive(value_datatype=datatypes.gDay)
    1029  datatypes.gDay._CF_maxExclusive = CF_maxExclusive(value_datatype=datatypes.anySimpleType)
    1030  datatypes.gDay._CF_minExclusive = CF_minExclusive(value_datatype=datatypes.anySimpleType)
    1031  datatypes.gDay._CF_enumeration = CF_enumeration(value_datatype=datatypes.gDay)
    1032  datatypes.gDay._CF_whiteSpace = CF_whiteSpace(value=_WhiteSpace_enum.collapse)
    1033  datatypes.gDay._CF_maxInclusive = CF_maxInclusive(value_datatype=datatypes.gDay)
    1034  datatypes.gDay._InitializeFacetMap(datatypes.gDay._CF_pattern,
    1035     datatypes.gDay._CF_minInclusive,
    1036     datatypes.gDay._CF_maxExclusive,
    1037     datatypes.gDay._CF_minExclusive,
    1038     datatypes.gDay._CF_enumeration,
    1039     datatypes.gDay._CF_whiteSpace,
    1040     datatypes.gDay._CF_maxInclusive)
    1041  datatypes.gMonth._CF_pattern = CF_pattern()
    1042  datatypes.gMonth._CF_minInclusive = CF_minInclusive(value_datatype=datatypes.gMonth)
    1043  datatypes.gMonth._CF_maxExclusive = CF_maxExclusive(value_datatype=datatypes.anySimpleType)
    1044  datatypes.gMonth._CF_minExclusive = CF_minExclusive(value_datatype=datatypes.anySimpleType)
    1045  datatypes.gMonth._CF_enumeration = CF_enumeration(value_datatype=datatypes.gMonth)
    1046  datatypes.gMonth._CF_whiteSpace = CF_whiteSpace(value=_WhiteSpace_enum.collapse)
    1047  datatypes.gMonth._CF_maxInclusive = CF_maxInclusive(value_datatype=datatypes.gMonth)
    1048  datatypes.gMonth._InitializeFacetMap(datatypes.gMonth._CF_pattern,
    1049     datatypes.gMonth._CF_minInclusive,
    1050     datatypes.gMonth._CF_maxExclusive,
    1051     datatypes.gMonth._CF_minExclusive,
    1052     datatypes.gMonth._CF_enumeration,
    1053     datatypes.gMonth._CF_whiteSpace,
    1054     datatypes.gMonth._CF_maxInclusive)
    1055  datatypes.gMonthDay._CF_pattern = CF_pattern()
    1056  datatypes.gMonthDay._CF_minInclusive = CF_minInclusive(value_datatype=datatypes.gMonthDay)
    1057  datatypes.gMonthDay._CF_maxExclusive = CF_maxExclusive(value_datatype=datatypes.anySimpleType)
    1058  datatypes.gMonthDay._CF_minExclusive = CF_minExclusive(value_datatype=datatypes.anySimpleType)
    1059  datatypes.gMonthDay._CF_enumeration = CF_enumeration(value_datatype=datatypes.gMonthDay)
    1060  datatypes.gMonthDay._CF_whiteSpace = CF_whiteSpace(value=_WhiteSpace_enum.collapse)
    1061  datatypes.gMonthDay._CF_maxInclusive = CF_maxInclusive(value_datatype=datatypes.gMonthDay)
    1062  datatypes.gMonthDay._InitializeFacetMap(datatypes.gMonthDay._CF_pattern,
    1063     datatypes.gMonthDay._CF_minInclusive,
    1064     datatypes.gMonthDay._CF_maxExclusive,
    1065     datatypes.gMonthDay._CF_minExclusive,
    1066     datatypes.gMonthDay._CF_enumeration,
    1067     datatypes.gMonthDay._CF_whiteSpace,
    1068     datatypes.gMonthDay._CF_maxInclusive)
    1069  datatypes.gYear._CF_pattern = CF_pattern()
    1070  datatypes.gYear._CF_minInclusive = CF_minInclusive(value_datatype=datatypes.gYear)
    1071  datatypes.gYear._CF_maxExclusive = CF_maxExclusive(value_datatype=datatypes.anySimpleType)
    1072  datatypes.gYear._CF_minExclusive = CF_minExclusive(value_datatype=datatypes.anySimpleType)
    1073  datatypes.gYear._CF_enumeration = CF_enumeration(value_datatype=datatypes.gYear)
    1074  datatypes.gYear._CF_whiteSpace = CF_whiteSpace(value=_WhiteSpace_enum.collapse)
    1075  datatypes.gYear._CF_maxInclusive = CF_maxInclusive(value_datatype=datatypes.gYear)
    1076  datatypes.gYear._InitializeFacetMap(datatypes.gYear._CF_pattern,
    1077     datatypes.gYear._CF_minInclusive,
    1078     datatypes.gYear._CF_maxExclusive,
    1079     datatypes.gYear._CF_minExclusive,
    1080     datatypes.gYear._CF_enumeration,
    1081     datatypes.gYear._CF_whiteSpace,
    1082     datatypes.gYear._CF_maxInclusive)
    1083  datatypes.gYearMonth._CF_pattern = CF_pattern()
    1084  datatypes.gYearMonth._CF_minInclusive = CF_minInclusive(value_datatype=datatypes.gYearMonth)
    1085  datatypes.gYearMonth._CF_maxExclusive = CF_maxExclusive(value_datatype=datatypes.anySimpleType)
    1086  datatypes.gYearMonth._CF_minExclusive = CF_minExclusive(value_datatype=datatypes.anySimpleType)
    1087  datatypes.gYearMonth._CF_enumeration = CF_enumeration(value_datatype=datatypes.gYearMonth)
    1088  datatypes.gYearMonth._CF_whiteSpace = CF_whiteSpace(value=_WhiteSpace_enum.collapse)
    1089  datatypes.gYearMonth._CF_maxInclusive = CF_maxInclusive(value_datatype=datatypes.gYearMonth)
    1090  datatypes.gYearMonth._InitializeFacetMap(datatypes.gYearMonth._CF_pattern,
    1091     datatypes.gYearMonth._CF_minInclusive,
    1092     datatypes.gYearMonth._CF_maxExclusive,
    1093     datatypes.gYearMonth._CF_minExclusive,
    1094     datatypes.gYearMonth._CF_enumeration,
    1095     datatypes.gYearMonth._CF_whiteSpace,
    1096     datatypes.gYearMonth._CF_maxInclusive)
    1097  datatypes.hexBinary._CF_minLength = CF_minLength()
    1098  datatypes.hexBinary._CF_maxLength = CF_maxLength()
    1099  datatypes.hexBinary._CF_enumeration = CF_enumeration(value_datatype=datatypes.hexBinary)
    1100  datatypes.hexBinary._CF_pattern = CF_pattern()
    1101  datatypes.hexBinary._CF_whiteSpace = CF_whiteSpace(value=_WhiteSpace_enum.collapse)
    1102  datatypes.hexBinary._CF_length = CF_length()
    1103  datatypes.hexBinary._InitializeFacetMap(datatypes.hexBinary._CF_minLength,
    1104     datatypes.hexBinary._CF_maxLength,
    1105     datatypes.hexBinary._CF_enumeration,
    1106     datatypes.hexBinary._CF_pattern,
    1107     datatypes.hexBinary._CF_whiteSpace,
    1108     datatypes.hexBinary._CF_length)
    1109  datatypes.int._CF_minInclusive = CF_minInclusive(value_datatype=datatypes.int, value=datatypes.anySimpleType(u'-2147483648'))
    1110  datatypes.int._CF_maxInclusive = CF_maxInclusive(value_datatype=datatypes.int, value=datatypes.anySimpleType(u'2147483647'))
    1111  datatypes.int._InitializeFacetMap(datatypes.int._CF_minInclusive,
    1112     datatypes.int._CF_maxInclusive)
    1113  datatypes.integer._CF_pattern = CF_pattern()
    1114  datatypes.integer._CF_pattern.addPattern(pattern=u'[\\-+]?[0-9]+')
    1115  datatypes.integer._CF_fractionDigits = CF_fractionDigits(value=datatypes.nonNegativeInteger(0L))
    1116  datatypes.integer._InitializeFacetMap(datatypes.integer._CF_pattern,
    1117     datatypes.integer._CF_fractionDigits)
    1118  datatypes.language._CF_pattern = CF_pattern()
    1119  datatypes.language._CF_pattern.addPattern(pattern=u'[a-zA-Z]{1,8}(-[a-zA-Z0-9]{1,8})*')
    1120  datatypes.language._InitializeFacetMap(datatypes.language._CF_pattern)
    1121  datatypes.long._CF_minInclusive = CF_minInclusive(value_datatype=datatypes.long, value=datatypes.anySimpleType(u'-9223372036854775808'))
    1122  datatypes.long._CF_maxInclusive = CF_maxInclusive(value_datatype=datatypes.long, value=datatypes.anySimpleType(u'9223372036854775807'))
    1123  datatypes.long._InitializeFacetMap(datatypes.long._CF_minInclusive,
    1124     datatypes.long._CF_maxInclusive)
    1125  datatypes.negativeInteger._CF_maxInclusive = CF_maxInclusive(value_datatype=datatypes.negativeInteger, value=datatypes.anySimpleType(u'-1'))
    1126  datatypes.negativeInteger._InitializeFacetMap(datatypes.negativeInteger._CF_maxInclusive)
    1127  datatypes.nonNegativeInteger._CF_minInclusive = CF_minInclusive(value_datatype=datatypes.nonNegativeInteger, value=datatypes.anySimpleType(u'0'))
    1128  datatypes.nonNegativeInteger._InitializeFacetMap(datatypes.nonNegativeInteger._CF_minInclusive)
    1129  datatypes.nonPositiveInteger._CF_maxInclusive = CF_maxInclusive(value_datatype=datatypes.nonPositiveInteger, value=datatypes.anySimpleType(u'0'))
    1130  datatypes.nonPositiveInteger._InitializeFacetMap(datatypes.nonPositiveInteger._CF_maxInclusive)
    1131  datatypes.normalizedString._CF_whiteSpace = CF_whiteSpace(value=_WhiteSpace_enum.replace)
    1132  datatypes.normalizedString._InitializeFacetMap(datatypes.normalizedString._CF_whiteSpace)
    1133  datatypes.positiveInteger._CF_minInclusive = CF_minInclusive(value_datatype=datatypes.positiveInteger, value=datatypes.anySimpleType(u'1'))
    1134  datatypes.positiveInteger._InitializeFacetMap(datatypes.positiveInteger._CF_minInclusive)
    1135  datatypes.short._CF_minInclusive = CF_minInclusive(value_datatype=datatypes.short, value=datatypes.anySimpleType(u'-32768'))
    1136  datatypes.short._CF_maxInclusive = CF_maxInclusive(value_datatype=datatypes.short, value=datatypes.anySimpleType(u'32767'))
    1137  datatypes.short._InitializeFacetMap(datatypes.short._CF_minInclusive,
    1138     datatypes.short._CF_maxInclusive)
    1139  datatypes.string._CF_minLength = CF_minLength()
    1140  datatypes.string._CF_maxLength = CF_maxLength()
    1141  datatypes.string._CF_enumeration = CF_enumeration(value_datatype=datatypes.string)
    1142  datatypes.string._CF_pattern = CF_pattern()
    1143  datatypes.string._CF_whiteSpace = CF_whiteSpace(value=_WhiteSpace_enum.preserve)
    1144  datatypes.string._CF_length = CF_length()
    1145  datatypes.string._InitializeFacetMap(datatypes.string._CF_minLength,
    1146     datatypes.string._CF_maxLength,
    1147     datatypes.string._CF_enumeration,
    1148     datatypes.string._CF_pattern,
    1149     datatypes.string._CF_whiteSpace,
    1150     datatypes.string._CF_length)
    1151  datatypes.time._CF_pattern = CF_pattern()
    1152  datatypes.time._CF_minInclusive = CF_minInclusive(value_datatype=datatypes.time)
    1153  datatypes.time._CF_maxExclusive = CF_maxExclusive(value_datatype=datatypes.anySimpleType)
    1154  datatypes.time._CF_minExclusive = CF_minExclusive(value_datatype=datatypes.anySimpleType)
    1155  datatypes.time._CF_enumeration = CF_enumeration(value_datatype=datatypes.time)
    1156  datatypes.time._CF_whiteSpace = CF_whiteSpace(value=_WhiteSpace_enum.collapse)
    1157  datatypes.time._CF_maxInclusive = CF_maxInclusive(value_datatype=datatypes.time)
    1158  datatypes.time._InitializeFacetMap(datatypes.time._CF_pattern,
    1159     datatypes.time._CF_minInclusive,
    1160     datatypes.time._CF_maxExclusive,
    1161     datatypes.time._CF_minExclusive,
    1162     datatypes.time._CF_enumeration,
    1163     datatypes.time._CF_whiteSpace,
    1164     datatypes.time._CF_maxInclusive)
    1165  datatypes.token._CF_whiteSpace = CF_whiteSpace(value=_WhiteSpace_enum.collapse)
    1166  datatypes.token._InitializeFacetMap(datatypes.token._CF_whiteSpace)
    1167  datatypes.unsignedByte._CF_maxInclusive = CF_maxInclusive(value_datatype=datatypes.unsignedByte, value=datatypes.anySimpleType(u'255'))
    1168  datatypes.unsignedByte._InitializeFacetMap(datatypes.unsignedByte._CF_maxInclusive)
    1169  datatypes.unsignedInt._CF_maxInclusive = CF_maxInclusive(value_datatype=datatypes.unsignedInt, value=datatypes.anySimpleType(u'4294967295'))
    1170  datatypes.unsignedInt._InitializeFacetMap(datatypes.unsignedInt._CF_maxInclusive)
    1171  datatypes.unsignedLong._CF_maxInclusive = CF_maxInclusive(value_datatype=datatypes.unsignedLong, value=datatypes.anySimpleType(u'18446744073709551615'))
    1172  datatypes.unsignedLong._InitializeFacetMap(datatypes.unsignedLong._CF_maxInclusive)
    1173  datatypes.unsignedShort._CF_maxInclusive = CF_maxInclusive(value_datatype=datatypes.unsignedShort, value=datatypes.anySimpleType(u'65535'))
    1174  datatypes.unsignedShort._InitializeFacetMap(datatypes.unsignedShort._CF_maxInclusive)
    1175