1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 """This module contains support classes from which schema-specific bindings
17 inherit, and that describe the content models of those schema."""
18
19 import logging
20 import pyxb
21 import xml.dom
22 import pyxb.utils.domutils as domutils
23 import pyxb.utils.utility as utility
24 import types
25 import pyxb.namespace
26 import collections
27 from pyxb.namespace.builtin import XMLSchema_instance as XSI
28
29 _log = logging.getLogger(__name__)
32
33
34
35
36 _validationConfig_ = pyxb.GlobalValidationConfig
37
38 @classmethod
40 """Set the validation configuration for this class."""
41 cls._validationConfig_ = validation_config
42
43 @classmethod
45 """The L{pyxb.ValidationConfig} instance that applies to this class.
46
47 By default this will reference L{pyxb.GlobalValidationConfig}."""
48 return cls._validationConfig_
49
51 """Set the validation configuration for this instance."""
52 self._validationConfig_ = validation_config
53
55 """The L{pyxb.ValidationConfig} instance that applies to this instance.
56
57 By default this will reference the class value from
58 L{_GetValidationConfig}, which defaults to
59 L{pyxb.GlobalValidationConfig}."""
60 return self._validationConfig_
61
62
63 _validationConfig = property(__getValidationConfig)
64
65 @classmethod
76
87
88 _ExpandedName = None
89 """The expanded name of the component."""
90
91 _XSDLocation = None
92 """Where the definition can be found in the originating schema."""
93
94 _ReservedSymbols = set([ 'validateBinding', 'toDOM', 'toxml', 'Factory', 'property' ])
95
96 if pyxb._CorruptionDetectionEnabled:
101
102 _PyXBFactoryKeywords = ( '_dom_node', '_fallback_namespace', '_from_xml',
103 '_apply_whitespace_facet', '_validate_constraints',
104 '_require_value', '_nil', '_element', '_apply_attributes',
105 '_convert_string_values', '_location' )
106 """Keywords that are interpreted by __new__ or __init__ in one or more
107 classes in the PyXB type hierarchy. All these keywords must be removed
108 before invoking base Python __init__ or __new__."""
109
110
111
112
113 _Abstract = False
114
116 """Return a L{namespace context <pyxb.binding.NamespaceContext>}
117 associated with the binding instance.
118
119 This will return C{None} unless something has provided a context to
120 the instance. Context is provided when instances are generated by the
121 DOM and SAX-based translators."""
122 return self.__namespaceContext
123 - def _setNamespaceContext (self, namespace_context):
124 """Associate a L{namespace context <pyxb.binding.NamespaceContext>}
125 with the binding instance."""
126 self.__namespaceContext = namespace_context
127 return self
128 __namespaceContext = None
129
131 """Associate an element binding with the instance.
132
133 Since the value of a binding instance reflects only its content, an
134 associated element is necessary to generate an XML document or DOM
135 tree.
136
137 @param elt: the L{pyxb.binding.basis.element} instance associated with
138 the value. This may be C{None} when disassociating a value from a
139 specific element."""
140 import pyxb.binding.content
141 assert (elt is None) or isinstance(elt, element)
142 self.__element = elt
143 return self
145 """Return a L{pyxb.binding.basis.element} associated with the binding
146 instance.
147
148 This will return C{None} unless an element has been associated.
149 Constructing a binding instance using the element instance will add
150 this association.
151 """
152 return self.__element
153 __element = None
154
155 __xsiNil = None
157 """Indicate whether this instance is U{nil
158 <http://www.w3.org/TR/xmlschema-1/#xsi_nil>}.
159
160 The value is set by the DOM and SAX parsers when building an instance
161 from a DOM element with U{xsi:nil
162 <http://www.w3.org/TR/xmlschema-1/#xsi_nil>} set to C{true}.
163
164 @return: C{None} if the element used to create the instance is not
165 U{nillable<http://www.w3.org/TR/xmlschema-1/#nillable>}.
166 If it is nillable, returns C{True} or C{False} depending on
167 whether the instance itself is U{nil<http://www.w3.org/TR/xmlschema-1/#xsi_nil>}.
168 """
169 return self.__xsiNil
171 """Set the xsi:nil property of the instance.
172
173 @param nil: C{True} if the value of xsi:nil should be C{true},
174 C{False} if the value of xsi:nil should be C{false}.
175
176 @raise pyxb.NoNillableSupportError: the instance is not associated
177 with an element that is L{nillable
178 <pyxb.binding.basis.element.nillable>}.
179 """
180 if self.__xsiNil is None:
181 raise pyxb.NoNillableSupportError(self)
182 self.__xsiNil = not not nil
183 if self.__xsiNil:
184
185
186 self._resetContent(reset_elements=True)
187
188 - def _resetContent (self, reset_elements=False):
189 """Reset the content of an element value.
190
191 This is not a public method.
192
193 For simple types, this does nothing. For complex types, this clears the
194 L{content<complexTypeDefinition.content>} array, removing all
195 non-element content from the instance. It optionally also removes all
196 element content.
197
198 @param reset_elements: If C{False} (default) only the content array is
199 cleared, which has the effect of removing any preference for element
200 order when generating a document. If C{True}, the element content
201 stored within the binding is also cleared, leaving it with no content
202 at all.
203
204 @note: This is not the same thing as L{complexTypeDefinition.reset},
205 which unconditionally resets attributes and element and non-element
206 content.
207 """
208 pass
209
210 __constructedWithValue = False
224
225
226
227
228 __WarnedUnassociatedElement = False
229
240
241 @classmethod
243 """Method invoked upon entry to the Factory method.
244
245 This method is entitled to modify the keywords array. It can also
246 return a state value which is passed to _postFactory_vx."""
247 return None
248
249 - def _postFactory_vx (cls, state):
250 """Method invoked prior to leaving the Factory method.
251
252 This is an instance method, and is given the state that was returned
253 by _PreFactory_vx."""
254 return None
255
256 @classmethod
258 """Provide a common mechanism to create new instances of this type.
259
260 The class constructor won't do, because you can't create
261 instances of union types.
262
263 This method may be overridden in subclasses (like STD_union). Pre-
264 and post-creation actions can be customized on a per-class instance by
265 overriding the L{_PreFactory_vx} and L{_postFactory_vx} methods.
266
267 @keyword _dom_node: If provided, the value must be a DOM node, the
268 content of which will be used to set the value of the instance.
269
270 @keyword _location: An optional instance of
271 L{pyxb.utils.utility.Location} showing the origin the binding. If
272 C{None}, a value from C{_dom_node} is used if available.
273
274 @keyword _from_xml: If C{True}, the input must be either a DOM node or
275 a unicode string comprising a lexical representation of a value. This
276 is a further control on C{_apply_whitespace_facet} and arises from
277 cases where the lexical and value representations cannot be
278 distinguished by type. The default value is C{True} iff C{_dom_node}
279 is not C{None}.
280
281 @keyword _apply_whitespace_facet: If C{True} and this is a
282 simpleTypeDefinition with a whiteSpace facet, the first argument will
283 be normalized in accordance with that facet prior to invoking the
284 parent constructor. The value is always C{True} if text content is
285 extracted from a C{_dom_node}, and otherwise defaults to the defaulted
286 value of C{_from_xml}.
287
288 @keyword _validate_constraints: If C{True}, any constructed value is
289 checked against constraints applied to the union as well as the member
290 type.
291
292 @keyword _require_value: If C{False} (default), it is permitted to
293 create a value without an initial value. If C{True} and no initial
294 value was provided, causes L{pyxb.SimpleContentAbsentError} to be raised.
295 Only applies to simpleTypeDefinition instances; this is used when
296 creating values from DOM nodes.
297 """
298
299
300 dom_node = kw.get('_dom_node')
301 location = kw.get('_location')
302 if (location is None) and isinstance(dom_node, utility.Locatable_mixin):
303 location = dom_node._location()
304 kw.setdefault('_from_xml', dom_node is not None)
305 used_cls = cls._SupersedingClass()
306 state = used_cls._PreFactory_vx(args, kw)
307 rv = cls._DynamicCreate(*args, **kw)
308 rv._postFactory_vx(state)
309 if (rv._location is None) and (location is not None):
310 rv._setLocation(location)
311 return rv
312
317
318 @classmethod
320 """Return C{True} iff this is the ur-type.
321
322 The only ur-type is {http://www.w3.org/2001/XMLSchema}anyType. The
323 implementation of this method is overridden for
324 L{pyxb.binding.datatypes.anyType}."""
325 return False
326
327 @classmethod
333
334 @classmethod
336 """Return a variant of the value that is compatible with this type.
337
338 Compatibility is defined relative to the type definition associated
339 with the element. The value C{None} is always compatible. If
340 C{value} has a Python type (e.g., C{int}) that is a superclass of the
341 required L{_TypeBinding_mixin} class (e.g., C{xs:byte}), C{value} is
342 used as a constructor parameter to return a new instance of the
343 required type. Note that constraining facets are applied here if
344 necessary (e.g., although a Python C{int} with value C{500} is
345 type-compatible with C{xs:byte}, it is outside the value space, and
346 compatibility will fail).
347
348 @keyword _convert_string_values: If C{True} (default) and the incoming value is
349 a string, an attempt will be made to form a compatible value by using
350 the string as a constructor argument to the this class. This flag is
351 set to C{False} when testing automaton transitions.
352
353 @raise pyxb.SimpleTypeValueError: if the value is not both
354 type-consistent and value-consistent with the element's type.
355 """
356 convert_string_values = kw.get('_convert_string_values', True)
357
358 if value is None:
359 return None
360
361 if isinstance(value, cls):
362
363
364 return value
365 value_type = type(value)
366
367 if str == value_type:
368 value_type = unicode
369
370
371
372 if issubclass(cls, value_type):
373 return cls(value)
374
375
376
377 if isinstance(value, int) and issubclass(cls, long):
378 return cls(value)
379
380
381 if isinstance(value, bool) and issubclass(cls, pyxb.binding.datatypes.boolean):
382 return cls(value)
383
384
385
386 if convert_string_values and (unicode == value_type):
387 return cls(value)
388
389
390 if issubclass(cls, STD_union):
391 for mt in cls._MemberTypes:
392 try:
393 return mt._CompatibleValue(value, **kw)
394 except:
395 pass
396
397
398 if (pyxb.binding.datatypes.anySimpleType == cls) and issubclass(value_type, simpleTypeDefinition):
399 return value
400 if pyxb.binding.datatypes.anyType == cls:
401 if not isinstance(value, _TypeBinding_mixin):
402 _log.info('Created %s instance from value of type %s', cls._ExpandedName, type(value))
403 value = cls(value)
404 return value
405
406
407
408 if isinstance(value, pyxb.BIND):
409 return value.createInstance(cls.Factory, **kw)
410
411
412 if cls._IsSimpleTypeContent():
413
414
415
416 rv = cls.Factory(value)
417 if isinstance(rv, simpleTypeDefinition) and (rv == value):
418 return rv
419 if isinstance(rv, complexTypeDefinition) and (rv.value() == value):
420 return rv
421
422
423
424
425
426
427 raise pyxb.SimpleTypeValueError(cls, value)
428
429 @classmethod
431 """Return True iff the content of this binding object is a simple type.
432
433 This is true only for descendents of simpleTypeDefinition and instances
434 of complexTypeDefinition that have simple type content."""
435 raise pyxb.LogicError('Failed to override _TypeBinding_mixin._IsSimpleTypeContent')
436
437
438
439
440 _AttributeWildcard = None
441
442 _AttributeMap = { }
443 """Map from expanded names to AttributeUse instances. Non-empty only in
444 L{complexTypeDefinition} subclasses."""
445
446 @classmethod
466
468 """Invoke self._setAttribute based on node attributes and keywords.
469
470 Though attributes can only legally appear in complexTypeDefinition
471 instances, delayed conditional validation requires caching them in
472 simpleTypeDefinition.
473
474 @param kw: keywords passed to the constructor. This map is mutated by
475 the call: keywords corresponding to recognized attributes are removed.
476
477 @param dom_node: an xml.dom Node instance, possibly C{None}
478 """
479
480
481 attribute_settings = { }
482 if dom_node is not None:
483 attribute_settings.update(self.__AttributesFromDOM(dom_node))
484 for fu in self._AttributeMap.values():
485 iv = kw.pop(fu.id(), None)
486 if iv is not None:
487 attribute_settings[fu.name()] = iv
488 for (attr_en, value) in attribute_settings.items():
489 self._setAttribute(attr_en, value)
490
491 - def toDOM (self, bds=None, parent=None, element_name=None):
492 """Convert this instance to a DOM node.
493
494 The name of the top-level element is either the name of the L{element}
495 instance associated with this instance, or the XML name of the type of
496 this instance.
497
498 @param bds: Support for customizing the generated document
499 @type bds: L{pyxb.utils.domutils.BindingDOMSupport}
500 @param parent: If C{None}, a standalone document is created;
501 otherwise, the created element is a child of the given element.
502 @type parent: C{xml.dom.Element} or C{None}
503 @rtype: C{xml.dom.Document}
504 """
505
506 if bds is None:
507 bds = domutils.BindingDOMSupport()
508 need_xsi_type = bds.requireXSIType()
509 if isinstance(element_name, (str, unicode)):
510 element_name = pyxb.namespace.ExpandedName(bds.defaultNamespace(), element_name)
511 if (element_name is None) and (self._element() is not None):
512 element_binding = self._element()
513 element_name = element_binding.name()
514 need_xsi_type = need_xsi_type or element_binding.typeDefinition()._RequireXSIType(type(self))
515 if element_name is None:
516 element_name = self._ExpandedName
517 element = bds.createChildElement(element_name, parent)
518 if need_xsi_type:
519 val_type_qname = self._ExpandedName.localName()
520 tns_prefix = bds.namespacePrefix(self._ExpandedName.namespace())
521 if tns_prefix is not None:
522 val_type_qname = '%s:%s' % (tns_prefix, val_type_qname)
523 bds.addAttribute(element, XSI.type, val_type_qname)
524 self._toDOM_csc(bds, element)
525 bds.finalize()
526 return bds.document()
527
528 - def toxml (self, encoding=None, bds=None, root_only=False):
529 """Shorthand to get the object as an XML document.
530
531 If you want to set the default namespace, pass in a pre-configured
532 C{bds}.
533
534 @param encoding: The encoding to be used. See
535 @C{xml.dom.Node.toxml()} for a description of why you should always
536 pass @C{'utf-8'} here. Because this method follows the contract of
537 the corresponding C{xml.dom.Node} method, it does not automatically
538 get the default PyXB output encoding.
539
540 @param bds: Optional L{pyxb.utils.domutils.BindingDOMSupport} instance
541 to use for creation. If not provided (default), a new generic one is
542 created.
543 """
544 dom = self.toDOM(bds)
545 if root_only:
546 dom = dom.documentElement
547 return dom.toxml(encoding)
548
554
556 """Override in subclasses for type-specific validation of instance
557 content.
558
559 @return: C{True} if the instance validates
560 @raise pyxb.BatchContentValidationError: complex content does not match model
561 @raise pyxb.SimpleTypeValueError: simple content fails to satisfy constraints
562 """
563 raise NotImplementedError('%s._validateBinding_vx' % (type(self).__name__,))
564
566 """Check whether the binding content matches its content model.
567
568 @return: C{True} if validation succeeds.
569 @raise pyxb.BatchContentValidationError: complex content does not match model
570 @raise pyxb.SimpleTypeValueError: attribute or simple content fails to satisfy constraints
571 """
572 if self._performValidation():
573 self._validateBinding_vx()
574 return True
575
577 """Inform content model that all additions have been provided.
578
579 This is used to resolve any pending non-determinism when the content
580 of an element is provided through a DOM assignment or through
581 positional arguments in a constructor."""
582 return self
583
584 - def _postDOMValidate (self):
585 self.validateBinding()
586 return self
587
588 @classmethod
590 """Return the best descriptive name for the type of the instance.
591
592 This is intended to be a human-readable value used in diagnostics, and
593 is the expanded name if the type has one, or the Python type name if
594 it does not."""
595 if cls._ExpandedName is not None:
596 return unicode(cls._ExpandedName)
597 return unicode(cls)
598
600 """The best name available for this instance in diagnostics.
601
602 If the instance is associated with an element, it is the element name;
603 otherwise it is the best name for the type of the instance per L{_Name}."""
604 if self.__element is None:
605 return self._Name()
606 return unicode(self.__element.name())
607
609 """Helper to allow overriding the implementation class.
610
611 Generally we'll want to augment the generated bindings by subclassing
612 them, and adding functionality to the subclass. This mix-in provides a
613 way to communicate the existence of the superseding subclass back to the
614 binding infrastructure, so that when it creates an instance it uses the
615 subclass rather than the unaugmented binding class.
616
617 When a raw generated binding is subclassed, L{_SetSupersedingClass} should be
618 invoked on the raw class passing in the superseding subclass. E.g.::
619
620 class mywsdl (raw.wsdl):
621 pass
622 raw.wsdl._SetSupersedingClass(mywsdl)
623
624 """
625
626 @classmethod
628 return '_%s__SupersedingClass' % (cls.__name__,)
629
630 @classmethod
632 return '_%s__AlternativeConstructor' % (cls.__name__,)
633
634 @classmethod
638
639 @classmethod
641 """Return the class stored in the class reference attribute."""
642 rv = getattr(cls, cls.__AlternativeConstructorAttribute(), None)
643 if isinstance(rv, tuple):
644 rv = rv[0]
645 return rv
646
647 @classmethod
649 """Set the class reference attribute.
650
651 @param superseding: A Python class that is a subclass of this class.
652 """
653 assert (superseding is None) or issubclass(superseding, cls)
654 if superseding is None:
655 cls.__dict__.pop(cls.__SupersedingClassAttribute(), None)
656 else:
657 setattr(cls, cls.__SupersedingClassAttribute(), superseding)
658 return superseding
659
660 @classmethod
662 attr = cls.__AlternativeConstructorAttribute()
663 if alternative_constructor is None:
664 cls.__dict__.pop(attr, None)
665 else:
666
667
668
669 setattr(cls, attr, (alternative_constructor,))
670 assert cls._AlternativeConstructor() == alternative_constructor
671 return alternative_constructor
672
673 @classmethod
683
684 -class simpleTypeDefinition (_TypeBinding_mixin, utility._DeconflictSymbols_mixin, _DynamicCreate_mixin):
685 """L{simpleTypeDefinition} is a base class that is part of the
686 hierarchy of any class that represents the Python datatype for a
687 L{SimpleTypeDefinition<pyxb.xmlschema.structures.SimpleTypeDefinition>}.
688
689 @note: This class, or a descendent of it, must be the first class
690 in the method resolution order when a subclass has multiple
691 parents. Otherwise, constructor keyword arguments may not be
692 removed before passing them on to Python classes that do not
693 accept them.
694 """
695
696
697
698
699 __FacetMap = {}
700
701 _ReservedSymbols = _TypeBinding_mixin._ReservedSymbols.union(set([ 'XsdLiteral', 'xsdLiteral',
702 'XsdSuperType', 'XsdPythonType', 'XsdConstraintsOK',
703 'xsdConstraintsOK', 'XsdValueLength', 'xsdValueLength',
704 'PythonLiteral', 'pythonLiteral',
705 'SimpleTypeDefinition' ]))
706 """Symbols that remain the responsibility of this class. Any
707 public symbols in generated binding subclasses are deconflicted
708 by providing an alternative name in the subclass. (There
709 currently are no public symbols in generated SimpleTypeDefinion
710 bindings."""
711
712
713
714
715
716 __FacetMapAttributeNameMap = { }
717 @classmethod
719 """ """
720 '''
721 if cls == simpleTypeDefinition:
722 return '_%s__FacetMap' % (cls.__name__.strip('_'),)
723
724 # It is not uncommon for a class in one namespace to extend a class of
725 # the same name in a different namespace, so encode the namespace URI
726 # in the attribute name (if it is part of a namespace).
727 ns_uri = ''
728 try:
729 ns_uri = cls._ExpandedName.namespaceURI()
730 except Exception:
731 pass
732 nm = '_' + utility.MakeIdentifier('%s_%s_FacetMap' % (ns_uri, cls.__name__.strip('_')))
733 '''
734 nm = cls.__FacetMapAttributeNameMap.get(cls)
735 if nm is None:
736 nm = cls.__name__
737 if nm.endswith('_'):
738 nm += '1'
739 if cls == simpleTypeDefinition:
740 nm = '_%s__FacetMap' % (nm,)
741 else:
742
743
744
745 ns_uri = ''
746 try:
747 ns_uri = cls._ExpandedName.namespaceURI()
748 except Exception:
749 pass
750 nm = '_' + utility.MakeIdentifier('%s_%s_FacetMap' % (ns_uri, nm))
751 cls.__FacetMapAttributeNameMap[cls] = nm
752 return nm
753
754 @classmethod
756 """Return a reference to the facet map for this datatype.
757
758 The facet map is a map from leaf facet classes to instances of those
759 classes that constrain or otherwise apply to the lexical or value
760 space of the datatype. Classes may inherit their facet map from their
761 superclass, or may create a new class instance if the class adds a new
762 constraint type.
763
764 @raise AttributeError: if the facet map has not been defined"""
765 return getattr(cls, cls.__FacetMapAttributeName())
766
767 @classmethod
769 """Initialize the facet map for this datatype.
770
771 This must be called exactly once, after all facets belonging to the
772 datatype have been created.
773
774 @raise pyxb.LogicError: if called multiple times (on the same class)
775 @raise pyxb.LogicError: if called when a parent class facet map has not been initialized
776 :return: the facet map"""
777 fm = None
778 try:
779 fm = cls._FacetMap()
780 except AttributeError:
781 pass
782 if fm is not None:
783 raise pyxb.LogicError('%s facet map initialized multiple times: %s' % (cls.__name__, cls.__FacetMapAttributeName()))
784
785
786
787
788
789 source_class = cls
790 while fm is None:
791
792
793 for super_class in source_class.mro():
794 assert super_class is not None
795 if (super_class == simpleTypeDefinition):
796 break
797 if issubclass(super_class, simpleTypeDefinition):
798 try:
799 fm = super_class._FacetMap()
800 break
801 except AttributeError:
802 pass
803 if fm is None:
804 try:
805 source_class = source_class.XsdSuperType()
806 except AttributeError:
807 source_class = None
808 if source_class is None:
809 fm = { }
810 if fm is None:
811 raise pyxb.LogicError('%s is not a child of simpleTypeDefinition' % (cls.__name__,))
812 fm = fm.copy()
813 for facet in args:
814 fm[type(facet)] = facet
815 setattr(cls, cls.__FacetMapAttributeName(), fm)
816 return fm
817
818 @classmethod
821
822 @classmethod
824 """Pre-process the arguments.
825
826 This is used before invoking the parent constructor. One application
827 is to apply the whitespace facet processing; if such a request is in
828 the keywords, it is removed so it does not propagate to the
829 superclass. Another application is to convert the arguments from a
830 string to a list. Binding-specific applications are performed in the
831 overloaded L{_ConvertArguments_vx} method."""
832 dom_node = kw.pop('_dom_node', None)
833 from_xml = kw.get('_from_xml', dom_node is not None)
834 if dom_node is not None:
835 text_content = domutils.ExtractTextContent(dom_node)
836 if text_content is not None:
837 args = (domutils.ExtractTextContent(dom_node),) + args
838 kw['_apply_whitespace_facet'] = True
839 apply_whitespace_facet = kw.pop('_apply_whitespace_facet', from_xml)
840 if (0 < len(args)) and isinstance(args[0], types.StringTypes) and apply_whitespace_facet:
841 cf_whitespace = getattr(cls, '_CF_whiteSpace', None)
842 if cf_whitespace is not None:
843 norm_str = unicode(cf_whitespace.normalizeString(args[0]))
844 args = (norm_str,) + args[1:]
845 kw['_from_xml'] = from_xml
846 return cls._ConvertArguments_vx(args, kw)
847
848
849
850
851
852
853
854
855
856
857
859
860 kw.pop('_validate_constraints', None)
861 kw.pop('_require_value', None)
862 kw.pop('_element', None)
863 kw.pop('_fallback_namespace', None)
864 kw.pop('_apply_attributes', None)
865 kw.pop('_nil', None)
866
867 dom_node = kw.get('_dom_node')
868 args = cls._ConvertArguments(args, kw)
869 kw.pop('_from_xml', dom_node is not None)
870 kw.pop('_location', None)
871 assert issubclass(cls, _TypeBinding_mixin)
872 try:
873 return super(simpleTypeDefinition, cls).__new__(cls, *args, **kw)
874 except ValueError as e:
875 raise pyxb.SimpleTypeValueError(cls, args)
876 except OverflowError as e:
877 raise pyxb.SimpleTypeValueError(cls, args)
878
879
880
882 """Initialize a newly created STD instance.
883
884 Usually there is one positional argument, which is a value that can be
885 converted to the underlying Python type.
886
887 @keyword _validate_constraints: If True (default if validation is
888 enabled), the newly constructed value is checked against its
889 constraining facets.
890 @type _validate_constraints: C{bool}
891
892 @keyword _apply_attributes: If C{True} (default), any attributes
893 present in the keywords or DOM node are applied. Normally presence of
894 such an attribute should produce an error; when creating simple
895 content for a complex type we need the DOM node, but do not want to
896 apply the attributes, so we bypass the application.
897 """
898
899 validate_constraints = kw.pop('_validate_constraints', self._validationConfig.forBinding)
900 require_value = kw.pop('_require_value', False)
901
902 dom_node = kw.get('_dom_node')
903 location = kw.get('_location')
904 if (location is None) and isinstance(dom_node, utility.Locatable_mixin):
905 location = dom_node._location()
906 apply_attributes = kw.pop('_apply_attributes', True)
907
908
909 args = self._ConvertArguments(args, kw)
910 try:
911 super(simpleTypeDefinition, self).__init__(*args, **kw)
912 except OverflowError as e:
913 raise pyxb.SimpleTypeValueError(type(self), args)
914 if apply_attributes and (dom_node is not None):
915 self._setAttributesFromKeywordsAndDOM(kw, dom_node)
916 if require_value and (not self._constructedWithValue()):
917 if location is None:
918 location = self._location()
919 raise pyxb.SimpleContentAbsentError(self, location)
920 if validate_constraints and not kw.pop('_nil', False):
921 self.xsdConstraintsOK(location)
922
923
924
925
926
927
928 @classmethod
930 return '_%s__SimpleTypeDefinition' % (cls.__name__,)
931
932 @classmethod
934 """Set the L{pyxb.xmlschema.structures.SimpleTypeDefinition} instance
935 associated with this binding."""
936 attr_name = cls.__STDAttrName()
937 if hasattr(cls, attr_name):
938 old_value = getattr(cls, attr_name)
939 if old_value != std:
940 raise pyxb.LogicError('%s: Attempt to override existing STD %s with %s' % (cls, old_value.name(), std.name()))
941 setattr(cls, attr_name, std)
942
943 @classmethod
945 """Return the SimpleTypeDefinition instance for the given
946 class.
947
948 This should only be invoked when generating bindings. An STD must
949 have been associated with the class using L{_SimpleTypeDefinition}."""
950 attr_name = cls.__STDAttrName()
951 assert hasattr(cls, attr_name)
952 return getattr(cls, attr_name)
953
954 @classmethod
956 """Convert from a python value to a string usable in an XML
957 document.
958
959 This should be implemented in the subclass."""
960 raise pyxb.LogicError('%s does not implement XsdLiteral' % (cls,))
961
963 """Return text suitable for representing the value of this
964 instance in an XML document.
965
966 The base class implementation delegates to the object class's
967 XsdLiteral method."""
968 if self._isNil():
969 return ''
970 return self.XsdLiteral(self)
971
972 @classmethod
974 """Find the nearest parent class in the PST hierarchy.
975
976 The value for anySimpleType is None; for all others, it's a
977 primitive or derived PST descendent (including anySimpleType)."""
978 for sc in cls.mro():
979 if sc == cls:
980 continue
981 if simpleTypeDefinition == sc:
982
983
984
985 return cls._XsdBaseType
986 if issubclass(sc, simpleTypeDefinition):
987 return sc
988 raise pyxb.LogicError('No supertype found for %s' % (cls,))
989
990 @classmethod
992 """Pre-extended class method to verify other things before
993 checking constraints.
994
995 This is used for list types, to verify that the values in the
996 list are acceptable, and for token descendents, to check the
997 lexical/value space conformance of the input.
998 """
999 super_fn = getattr(super(simpleTypeDefinition, cls), '_XsdConstraintsPreCheck_vb', lambda *a,**kw: value)
1000 return super_fn(value)
1001
1002
1003
1004 __ClassFacetSequence = { }
1005
1006 @classmethod
1008 """Validate the given value against the constraints on this class.
1009
1010 @raise pyxb.SimpleTypeValueError: if any constraint is violated.
1011 """
1012
1013 value = cls._XsdConstraintsPreCheck_vb(value)
1014
1015 facet_values = cls.__ClassFacetSequence.get(cls)
1016 if facet_values is None:
1017
1018
1019 classes = [ _x for _x in cls.mro() if issubclass(_x, simpleTypeDefinition) ]
1020 classes.reverse()
1021 cache_result = True
1022 facet_values = []
1023 for clazz in classes:
1024
1025
1026
1027
1028
1029
1030 try:
1031 clazz_facets = clazz._FacetMap().values()
1032 except AttributeError:
1033 cache_result = False
1034 clazz_facets = []
1035 for v in clazz_facets:
1036 if not (v in facet_values):
1037 facet_values.append(v)
1038 if cache_result:
1039 cls.__ClassFacetSequence[cls] = facet_values
1040 for f in facet_values:
1041 if not f.validateConstraint(value):
1042 raise pyxb.SimpleFacetValueError(cls, value, f, location)
1043 return value
1044
1046 """Validate the value of this instance against its constraints."""
1047 return self.XsdConstraintsOK(self, location)
1048
1053
1054 @classmethod
1056 """Return the length of the given value.
1057
1058 The length is calculated by a subclass implementation of
1059 _XsdValueLength_vx in accordance with
1060 http://www.w3.org/TR/xmlschema-2/#rf-length.
1061
1062 The return value is a non-negative integer, or C{None} if length
1063 constraints should be considered trivially satisfied (as with
1064 QName and NOTATION).
1065
1066 @raise pyxb.LogicError: the provided value is not an instance of cls.
1067 @raise pyxb.LogicError: an attempt is made to calculate a length for
1068 an instance of a type that does not support length calculations.
1069 """
1070 assert isinstance(value, cls)
1071 if not hasattr(cls, '_XsdValueLength_vx'):
1072 raise pyxb.LogicError('Class %s does not support length validation' % (cls.__name__,))
1073 return cls._XsdValueLength_vx(value)
1074
1076 """Return the length of this instance within its value space.
1077
1078 See XsdValueLength."""
1079 return self.XsdValueLength(self)
1080
1081 @classmethod
1083 """Return a string which can be embedded into Python source to
1084 represent the given value as an instance of this class."""
1085 class_name = cls.__name__
1086 return '%s(%s)' % (class_name, repr(value))
1087
1089 """Return a string which can be embedded into Python source to
1090 represent the value of this instance."""
1091 return self.PythonLiteral(self)
1092
1097
1098 @classmethod
1100 """STDs have simple type content."""
1101 return True
1102
1103 @classmethod
1111
1112 @classmethod
1114
1115 """NB: Invoking this on a value that is a list will, if necessary,
1116 replace the members of the list with new values that are of the
1117 correct item type. This is permitted because only with lists is it
1118 possible to bypass the normal content validation (by invoking
1119 append/extend on the list instance)."""
1120 if value is None:
1121 raise pyxb.SimpleTypeValueError(cls, value)
1122 value_class = cls
1123 if issubclass(cls, STD_list):
1124 if not isinstance(value, collections.Iterable):
1125 raise pyxb.SimpleTypeValueError(cls, value)
1126 for v in value:
1127 if not cls._ItemType._IsValidValue(v):
1128 raise pyxb.SimpleListValueError(cls, v)
1129 else:
1130 if issubclass(cls, STD_union):
1131 value_class = None
1132 for mt in cls._MemberTypes:
1133 if mt._IsValidValue(value):
1134 value_class = mt
1135 break
1136 if value_class is None:
1137 raise pyxb.SimpleUnionValueError(cls, value)
1138
1139 if not isinstance(value, value_class):
1140 raise pyxb.SimpleTypeValueError(cls, value)
1141 value_class.XsdConstraintsOK(value)
1142
1145
1148
1154
1155 @classmethod
1156 - def _description (cls, name_only=False, user_documentation=True):
1157 name = cls._Name()
1158 if name_only:
1159 return name
1160 desc = [ name, ' restriction of ', cls.XsdSuperType()._description(name_only=True) ]
1161 if user_documentation and (cls._Documentation is not None):
1162 desc.extend(["\n", cls._Documentation])
1163 return ''.join(desc)
1164
1166 """Base class for union datatypes.
1167
1168 This class descends only from simpleTypeDefinition. A pyxb.LogicError is
1169 raised if an attempt is made to construct an instance of a subclass of
1170 STD_union. Values consistent with the member types are constructed using
1171 the Factory class method. Values are validated using the _ValidatedMember
1172 class method.
1173
1174 Subclasses must provide a class variable _MemberTypes which is a
1175 tuple of legal members of the union."""
1176
1177 _MemberTypes = None
1178 """A list of classes which are permitted as values of the union."""
1179
1180
1181
1182
1183 __FacetMap = {}
1184
1185 @classmethod
1187 """Given a value, attempt to create an instance of some member of this
1188 union. The first instance which can be legally created is returned.
1189
1190 @keyword _validate_constraints: If C{True} (default if validation is
1191 enabled), any constructed value is checked against constraints applied
1192 to the union as well as the member type.
1193
1194 @raise pyxb.SimpleTypeValueError: no member type will permit creation of
1195 an instance from the parameters in C{args} and C{kw}.
1196 """
1197
1198 used_cls = cls._SupersedingClass()
1199 state = used_cls._PreFactory_vx(args, kw)
1200
1201 rv = None
1202
1203 validate_constraints = kw.get('_validate_constraints', cls._GetValidationConfig().forBinding)
1204 assert isinstance(validate_constraints, bool)
1205 if 0 < len(args):
1206 arg = args[0]
1207 try:
1208 rv = cls._ValidatedMember(arg)
1209 except pyxb.SimpleTypeValueError:
1210 pass
1211 if rv is None:
1212 kw['_validate_constraints'] = True
1213 for mt in cls._MemberTypes:
1214 try:
1215 rv = mt.Factory(*args, **kw)
1216 break
1217 except pyxb.SimpleTypeValueError:
1218 pass
1219 except (ValueError, OverflowError):
1220 pass
1221 except:
1222 pass
1223 location = None
1224 if kw is not None:
1225 location = kw.get('_location')
1226 if rv is not None:
1227 if validate_constraints:
1228 cls.XsdConstraintsOK(rv, location)
1229 rv._postFactory_vx(state)
1230 return rv
1231
1232
1233 raise pyxb.SimpleUnionValueError(cls, args, location)
1234
1235 @classmethod
1252
1254 raise pyxb.LogicError('%s: cannot construct instances of union' % (self.__class__.__name__,))
1255
1256 @classmethod
1257 - def _description (cls, name_only=False, user_documentation=True):
1264
1265 @classmethod
1269
1270
1271 -class STD_list (simpleTypeDefinition, types.ListType):
1272 """Base class for collection datatypes.
1273
1274 This class descends from the Python list type, and incorporates
1275 simpleTypeDefinition. Subclasses must define a class variable _ItemType
1276 which is a reference to the class of which members must be instances."""
1277
1278 _ItemType = None
1279 """A reference to the binding class for items within this list."""
1280
1281
1282
1283 __FacetMap = {}
1284
1285 @classmethod
1287 """Verify that the given value is permitted as an item of this list.
1288
1289 This may convert the value to the proper type, if it is
1290 compatible but not an instance of the item type. Returns the
1291 value that should be used as the item, or raises an exception
1292 if the value cannot be converted.
1293
1294 @param kw: optional dictionary of standard constructor keywords used
1295 when exceptions must be built. In particular, C{_location} may be
1296 useful.
1297 """
1298 if isinstance(value, cls._ItemType):
1299 pass
1300 elif issubclass(cls._ItemType, STD_union):
1301 value = cls._ItemType._ValidatedMember(value)
1302 else:
1303 try:
1304 value = cls._ItemType(value)
1305 except (pyxb.SimpleTypeValueError, TypeError):
1306 location = None
1307 if kw is not None:
1308 location = kw.get('_location')
1309 raise pyxb.SimpleListValueError(cls, value, location)
1310 return value
1311
1312 @classmethod
1314
1315
1316 if 0 < len(args):
1317 arg1 = args[0]
1318 if isinstance(arg1, types.StringTypes):
1319 args = (arg1.split(),) + args[1:]
1320 arg1 = args[0]
1321 if isinstance(arg1, collections.Iterable):
1322 new_arg1 = [ cls._ValidatedItem(_v, kw) for _v in arg1 ]
1323 args = (new_arg1,) + args[1:]
1324 super_fn = getattr(super(STD_list, cls), '_ConvertArguments_vx', lambda *a,**kw: args)
1325 return super_fn(args, kw)
1326
1327 @classmethod
1330
1331 @classmethod
1333 """Convert from a binding value to a string usable in an XML document."""
1334 return ' '.join([ cls._ItemType.XsdLiteral(_v) for _v in value ])
1335
1336 @classmethod
1337 - def _description (cls, name_only=False, user_documentation=True):
1343
1344
1345 @classmethod
1348
1349
1352
1358
1361
1364
1365
1366
1369
1370 - def extend (self, x, _from_xml=False):
1372
1375
1376 - def index (self, x, *args):
1378
1381
1384
1385 -class element (utility._DeconflictSymbols_mixin, _DynamicCreate_mixin):
1386 """Class that represents a schema element within a binding.
1387
1388 This gets a little confusing. Within a schema, the
1389 L{pyxb.xmlschema.structures.ElementDeclaration} type represents an
1390 U{element
1391 declaration<http://www.w3.org/TR/xmlschema-1/#cElement_Declarations>}.
1392 Those declarations may be global (have a name that is visible in the
1393 namespace), or local (have a name that is visible only within a complex
1394 type definition). Further, local (but not global) declarations may have a
1395 reference to a global declaration (which might be in a different
1396 namespace).
1397
1398 Within a PyXB binding, the element declarations from the original complex
1399 type definition that have the same
1400 U{QName<http://www.w3.org/TR/1999/REC-xml-names-19990114/#dt-qname>}
1401 (after deconflicting the
1402 U{LocalPart<http://www.w3.org/TR/1999/REC-xml-names-19990114/#NT-LocalPart>})
1403 are associated with an attribute in the class for the complex type. Each
1404 of these attributes is defined via a
1405 L{pyxb.binding.content.ElementDeclaration} which provides the mechanism by
1406 which the binding holds values associated with that element.
1407
1408 Furthermore, in the FAC-based content model each schema element
1409 declaration is associated with an
1410 L{ElementUse<pyxb.binding.content.ElementUse>} instance to locate the
1411 point in the schema where content came from. Instances that refer to the
1412 same schema element declaration share the same underlying
1413 L{pyxb.binding.content.ElementDeclaration}.
1414
1415 This element isn't any of those elements. This element is the type used
1416 for an attribute which associates the name of a element with data required
1417 to represent it, all within a particular scope (a module for global scope,
1418 the binding class for a complex type definition for local scope). From
1419 the perspective of a PyXB user they look almost like a class, in that you
1420 can call them to create instances of the underlying complex type.
1421
1422 Global and local elements are represented by instances of this class.
1423 """
1424
1426 """The expanded name of the element within its scope."""
1427 return self.__name
1428 __name = None
1429
1433 __typeDefinition = None
1434
1436 """The L{pyxb.utils.utility.Location} where the element appears in the schema."""
1437 return self.__xsdLocation
1438 __xsdLocation = None
1439
1441 """The scope of the element. This is either C{None}, representing a
1442 top-level element, or an instance of C{complexTypeDefinition} for
1443 local elements."""
1444 return self.__scope
1445 __scope = None
1446
1448 """Indicate whether values matching this element can have U{nil
1449 <http://www.w3.org/TR/xmlschema-1/#xsi_nil>} set."""
1450 return self.__nillable
1451 __nillable = False
1452
1454 """Indicate whether this element is abstract (must use substitution
1455 group members for matches)."""
1456 return self.__abstract
1457 __abstract = False
1458
1460 """Contents of any documentation annotation in the definition."""
1461 return self.__documentation
1462 __documentation = None
1463
1465 """The default value of the element.
1466
1467 C{None} if the element has no default value.
1468
1469 @note: A non-C{None} value is always an instance of a simple type,
1470 even if the element has complex content."""
1471 return self.__defaultValue
1472 __defaultValue = None
1473
1475 """C{True} if the element content cannot be changed"""
1476 return self.__fixed
1477 __fixed = False
1478
1480 """The L{element} instance to whose substitution group this element
1481 belongs. C{None} if this element is not part of a substitution
1482 group."""
1483 return self.__substitutionGroup
1489 __substitutionGroup = None
1490
1498
1500 """Determine whether an instance of this element can substitute for the other element.
1501
1502 See U{Substitution Group OK<http://www.w3.org/TR/xmlschema-1/#cos-equiv-derived-ok-rec>}.
1503
1504 @todo: Do something about blocking constraints. This ignores them, as
1505 does everything leading to this point.
1506 """
1507 if self.substitutionGroup() is None:
1508 return False
1509 if other is None:
1510 return False
1511 assert isinstance(other, element)
1512
1513
1514 if other.scope() is not None:
1515 other = other.name().elementBinding()
1516 if other is None:
1517 return False
1518 assert other.scope() is None
1519
1520 if self.name().elementBinding() == other:
1521 return True
1522 return (self.substitutionGroup() == other) or self.substitutionGroup().substitutesFor(other)
1523
1525 """Stub replaced by _real_substitutesFor when element supports substitution groups."""
1526 return False
1527
1529 """Return a reference to the element instance used for the given name
1530 within this element.
1531
1532 The type for this element must be a complex type definition."""
1533 return self.typeDefinition()._UseForTag(name).elementBinding()
1534
1535 - def __init__ (self, name, type_definition, scope=None, nillable=False, abstract=False, unicode_default=None, fixed=False, substitution_group=None, documentation=None, location=None):
1555
1557 """Invoke the Factory method on the type associated with this element.
1558
1559 @keyword _dom_node: This keyword is removed. If present, it must be C{None}.
1560
1561 @note: Other keywords are passed to L{_TypeBinding_mixin.Factory}.
1562
1563 @raise pyxb.AbstractElementError: This element is abstract and no DOM
1564 node was provided.
1565 """
1566 dom_node = kw.pop('_dom_node', None)
1567 assert dom_node is None, 'Cannot pass DOM node directly to element constructor; use createFromDOM'
1568 if '_element' in kw:
1569 raise pyxb.LogicError('Cannot set _element in element-based instance creation')
1570 kw['_element'] = self
1571
1572 if self.abstract():
1573 location = kw.get('_location')
1574 if (location is None) and isinstance(dom_node, utility.Locatable_mixin):
1575 location = dom_node._location()
1576 raise pyxb.AbstractElementError(self, location, args)
1577 if self.__defaultValue is not None:
1578 if 0 == len(args):
1579
1580 args = [ self.__defaultValue ]
1581 elif self.__fixed:
1582
1583 if 1 < len(args):
1584 raise ValueError(*args)
1585 args = [ self.compatibleValue(args[0], **kw) ]
1586 rv = self.typeDefinition().Factory(*args, **kw)
1587 rv._setElement(self)
1588 return rv
1589
1616
1617 @classmethod
1619 """Create a binding from a DOM node.
1620
1621 @param node: The DOM node
1622
1623 @param element_binding: An instance of L{element} that would normally
1624 be used to determine the type of the binding. The actual type of
1625 object returned is determined by the type definition associated with
1626 the C{element_binding} and the value of any U{xsi:type
1627 <http://www.w3.org/TR/xmlschema-1/#xsi_type>} attribute found in
1628 C{node}, modulated by
1629 L{XSI._InterpretTypeAttribute<pyxb.namespace.builtin._XMLSchema_instance._InterpretTypeAttribute>}.
1630
1631 @keyword _fallback_namespace: The namespace to use as the namespace for
1632 the node, if the node name is unqualified. This should be an absent
1633 namespace.
1634
1635 @return: A binding for the DOM node.
1636
1637 @raises pyxb.UnrecognizedDOMRootNodeError: if no underlying element or
1638 type for the node can be identified.
1639 """
1640
1641 if xml.dom.Node.ELEMENT_NODE != node.nodeType:
1642 raise ValueError('node is not an element')
1643
1644 fallback_namespace = kw.get('_fallback_namespace')
1645
1646
1647
1648 if '_element' in kw:
1649 raise pyxb.LogicError('Cannot set _element in element-based instance creation')
1650
1651 type_class = None
1652 if element_binding is not None:
1653
1654
1655
1656 if element_binding.abstract():
1657 location = kw.get('location')
1658 if (location is None) and isinstance(node, utility.Locatable_mixin):
1659 location = node._location()
1660 raise pyxb.AbstractElementError(element_binding, location, node)
1661 kw['_element'] = element_binding
1662 type_class = element_binding.typeDefinition()
1663
1664
1665
1666
1667
1668 ns_ctx = pyxb.namespace.resolution.NamespaceContext.GetNodeContext(node)
1669 (did_replace, type_class) = XSI._InterpretTypeAttribute(XSI.type.getAttribute(node), ns_ctx, fallback_namespace, type_class)
1670
1671 if type_class is None:
1672 raise pyxb.UnrecognizedDOMRootNodeError(node)
1673
1674
1675
1676
1677 is_nil = XSI.nil.getAttribute(node)
1678 if is_nil is not None:
1679 kw['_nil'] = pyxb.binding.datatypes.boolean(is_nil)
1680
1681 rv = type_class.Factory(_dom_node=node, **kw)
1682 assert rv._element() == element_binding
1683 rv._setNamespaceContext(pyxb.namespace.resolution.NamespaceContext.GetNodeContext(node))
1684 return rv._postDOMValidate()
1685
1686
1687 @classmethod
1689 """Create an instance of an element from a DOM node.
1690
1691 This method does minimal processing of C{node} and delegates to
1692 L{CreateDOMBinding}.
1693
1694 @param node: An C{xml.dom.Node} representing a root element. If the
1695 node is a document, that document's root node will be substituted.
1696 The name of the node is extracted as the name of the element to be
1697 created, and the node and the name are passed to L{CreateDOMBinding}.
1698
1699 @param fallback_namespace: The value to pass as C{_fallback_namespace}
1700 to L{CreateDOMBinding}
1701
1702 @return: As with L{CreateDOMBinding}"""
1703 if xml.dom.Node.DOCUMENT_NODE == node.nodeType:
1704 node = node.documentElement
1705 expanded_name = pyxb.namespace.ExpandedName(node, fallback_namespace=fallback_namespace)
1706 return cls.CreateDOMBinding(node, expanded_name.elementBinding(), _fallback_namespace=fallback_namespace)
1707
1709 """Return the element that should be used if this element binding is
1710 permitted and an element with the given name is encountered.
1711
1712 Normally, the incoming name matches the name of this binding, and
1713 C{self} is returned. If the incoming name is different, it is
1714 expected to be the name of a global element which is within this
1715 element's substitution group. In that case, the binding corresponding
1716 to the named element is return.
1717
1718 @return: An instance of L{element}, or C{None} if no element with the
1719 given name can be found.
1720 """
1721
1722
1723 if self.name() == name:
1724 return self
1725
1726
1727 top_elt = self.name().elementBinding()
1728 if top_elt is None:
1729 return None
1730
1731
1732
1733
1734 elt_en = top_elt.name().adoptName(name)
1735 assert 'elementBinding' in elt_en.namespace()._categoryMap(), 'No element bindings in %s' % (elt_en.namespace(),)
1736 named_elt = elt_en.elementBinding()
1737 if (named_elt is None) or (named_elt == top_elt):
1738 return None
1739 if named_elt.substitutesFor(top_elt):
1740 return named_elt
1741 return None
1742
1744 """Create an instance of this element using a DOM node as the source
1745 of its content.
1746
1747 This method does minimal processing of C{node} and delegates to
1748 L{_createFromDOM}.
1749
1750 @param node: An C{xml.dom.Node} representing a root element. If the
1751 node is a document, that document's root node will be substituted.
1752 The name of the node is extracted as the name of the element to be
1753 created, and the node and the name are passed to L{_createFromDOM}
1754
1755 @keyword fallback_namespace: Used as default for
1756 C{_fallback_namespace} in call to L{_createFromDOM}
1757
1758 @note: Keyword parameters are passed to L{CreateDOMBinding}.
1759
1760 @return: As with L{_createFromDOM}
1761 """
1762 if xml.dom.Node.DOCUMENT_NODE == node.nodeType:
1763 node = node.documentElement
1764 if fallback_namespace is not None:
1765 kw.setdefault('_fallback_namespace', fallback_namespace)
1766 expanded_name = pyxb.namespace.ExpandedName(node, fallback_namespace=fallback_namespace)
1767 return self._createFromDOM(node, expanded_name, **kw)
1768
1770 """Create an instance from a DOM node given the name of an element.
1771
1772 This method does minimal processing of C{node} and C{expanded_name}
1773 and delegates to L{CreateDOMBinding}.
1774
1775 @param node: An C{xml.dom.Node} representing a root element. If the
1776 node is a document, that document's root node will be substituted.
1777 The value is passed to L{CreateDOMBinding}.
1778
1779 @param expanded_name: The expanded name of the element to be used for
1780 content. This is passed to L{elementForName} to obtain the binding
1781 that is passed to L{CreateDOMBinding}, superseding any identification
1782 that might be inferred from C{node}. If no name is available, use
1783 L{createFromDOM}.
1784
1785 @note: Keyword parameters are passed to L{CreateDOMBinding}.
1786
1787 @return: As with L{CreateDOMBinding}.
1788 """
1789 if xml.dom.Node.DOCUMENT_NODE == node.nodeType:
1790 node = node.documentElement
1791 return element.CreateDOMBinding(node, self.elementForName(expanded_name), **kw)
1792
1794 return 'Element %s' % (self.name(),)
1795
1796 - def _description (self, name_only=False, user_documentation=True):
1810
1812 """Marker in case we need to know that a PST has an enumeration constraint facet."""
1813
1814 @classmethod
1816 """Return a list of values that the enumeration can take."""
1817 return cls._CF_enumeration.values()
1818
1819 @classmethod
1823
1824 @classmethod
1826 """Return the associated L{pyxb.binding.facet._EnumerationElement} instances."""
1827 return cls._CF_enumeration.items()
1828
1829 @classmethod
1831 """Generate the associated L{pyxb.binding.facet._EnumerationElement} instances."""
1832 return cls._CF_enumeration.iteritems()
1833
1834 -class _Content (object):
1835 """Base for any wrapper added to L{complexTypeDefinition.orderedContent}."""
1836
1837 - def __getValue (self):
1838 """The value of the content.
1839
1840 This is a unicode string for L{NonElementContent}, and (ideally) an
1841 instance of L{_TypeBinding_mixin} for L{ElementContent}."""
1842 return self.__value
1843 __value = None
1844 value = property(__getValue)
1845
1846 - def __init__ (self, value):
1847 self.__value = value
1848
1849 -class ElementContent (_Content):
1850 """Marking wrapper for element content.
1851
1852 The value should be translated into XML and made a child of its parent."""
1853
1855 """The L{pyxb.binding.content.ElementDeclaration} associated with the element content.
1856 This may be C{None} if the value is a wildcard."""
1857 return self.__elementDeclaration
1858 __elementDeclaration = None
1859
1860 elementDeclaration = property(__getElementDeclaration)
1861
1862 - def __init__ (self, value, element_declaration=None, instance=None, tag=None):
1863 """Create a wrapper associating a value with its element declaration.
1864
1865 Normally the element declaration is determined by consulting the
1866 content model when creating a binding instance. When manipulating the
1867 preferred content list, this may be inconvenient to obtain; in that case
1868 provide the C{instance} in which the content appears immediately,
1869 along with the C{tag} that is used for the Python attribute that holds
1870 the element.
1871
1872 @param value: the value of the element. Should be an instance of
1873 L{_TypeBinding_mixin}, but for simple types might be a Python native
1874 type.
1875
1876 @keyword element_declaration: The
1877 L{pyxb.binding.content.ElementDeclaration} associated with the element
1878 value. Should be C{None} if the element matches wildcard content.
1879
1880 @keyword instance: Alternative path to providing C{element_declaration}
1881 @keyword tag: Alternative path to providing C{element_declaration}
1882 """
1883
1884 import pyxb.binding.content
1885 super(ElementContent, self).__init__(value)
1886 if instance is not None:
1887 if not isinstance(instance, complexTypeDefinition):
1888 raise pyxb.UsageError('Unable to determine element declaration')
1889 element_declaration = instance._UseForTag(tag)
1890 assert (element_declaration is None) or isinstance(element_declaration, pyxb.binding.content.ElementDeclaration)
1891 self.__elementDeclaration = element_declaration
1892
1893 -class NonElementContent (_Content):
1894 """Marking wrapper for non-element content.
1895
1896 The value will be unicode text, and should be appended as character
1897 data."""
1898 - def __init__ (self, value):
1900
1901 -class complexTypeDefinition (_TypeBinding_mixin, utility._DeconflictSymbols_mixin, _DynamicCreate_mixin):
1902 """Base for any Python class that serves as the binding for an
1903 XMLSchema complexType.
1904
1905 Subclasses should define a class-level _AttributeMap variable which maps
1906 from the unicode tag of an attribute to the AttributeUse instance that
1907 defines it. Similarly, subclasses should define an _ElementMap variable.
1908 """
1909
1910 _CT_EMPTY = 'EMPTY'
1911 _CT_SIMPLE = 'SIMPLE'
1912 _CT_MIXED = 'MIXED'
1913 _CT_ELEMENT_ONLY = 'ELEMENT_ONLY'
1914
1915 _ContentTypeTag = None
1916
1917 _TypeDefinition = None
1918 """Subclass of simpleTypeDefinition that corresponds to the type content.
1919 Only valid if _ContentTypeTag is _CT_SIMPLE"""
1920
1921
1922
1923 _HasWildcardElement = False
1924
1925
1926 _ElementMap = { }
1927 """Map from expanded names to ElementDeclaration instances."""
1928
1929
1930
1931 __wildcardAttributeMap = None
1932
1934 """Obtain access to wildcard attributes.
1935
1936 The return value is C{None} if this type does not support wildcard
1937 attributes. If wildcard attributes are allowed, the return value is a
1938 map from QNames to the unicode string value of the corresponding
1939 attribute.
1940
1941 @todo: The map keys should be namespace extended names rather than
1942 QNames, as the in-scope namespace may not be readily available to the
1943 user.
1944 """
1945 return self.__wildcardAttributeMap
1946
1947
1948
1949 __wildcardElements = None
1950
1952 """Obtain access to wildcard elements.
1953
1954 The return value is C{None} if the content model for this type does not
1955 support wildcard elements. If wildcard elements are allowed, the
1956 return value is a list of values corresponding to conformant
1957 unrecognized elements, in the order in which they were encountered.
1958 If the containing binding was created from an XML document and enough
1959 information was present to determine the binding of the member
1960 element, the value is a binding instance. Otherwise, the value is the
1961 original DOM Element node.
1962 """
1963 return self.__wildcardElements
1964
1966 """Create a new instance of this binding.
1967
1968 Arguments are used as transition values along the content model.
1969 Keywords are passed to the constructor of any simple content, or used
1970 to initialize attribute and element values whose L{id
1971 <content.ElementDeclaration.id>} (not L{name <content.ElementDeclaration.name>})
1972 matches the keyword.
1973
1974 @keyword _dom_node: The node to use as the source of binding content.
1975 @type _dom_node: C{xml.dom.Element}
1976
1977 @keyword _location: An optional instance of
1978 L{pyxb.utils.utility.Location} showing the origin the binding. If
1979 C{None}, a value from C{_dom_node} is used if available.
1980
1981 @keyword _from_xml: See L{_TypeBinding_mixin.Factory}
1982
1983 @keyword _finalize_content_model: If C{True} the constructor invokes
1984 L{_TypeBinding_mixin._finalizeContentModel} prior to return. The
1985 value defaults to C{False} when content is assigned through keyword
1986 parameters (bypassing the content model) or neither a C{_dom_node} nor
1987 positional element parameters have been provided, and to C{True} in
1988 all other cases.
1989 """
1990
1991 fallback_namespace = kw.pop('_fallback_namespace', None)
1992 is_nil = False
1993 dom_node = kw.pop('_dom_node', None)
1994 location = kw.pop('_location', None)
1995 from_xml = kw.pop('_from_xml', dom_node is not None)
1996 do_finalize_content_model = kw.pop('_finalize_content_model', None)
1997 if dom_node is not None:
1998 if (location is None) and isinstance(dom_node, pyxb.utils.utility.Locatable_mixin):
1999 location = dom_node._location()
2000 if xml.dom.Node.DOCUMENT_NODE == dom_node.nodeType:
2001 dom_node = dom_node.documentElement
2002
2003 is_nil = XSI.nil.getAttribute(dom_node)
2004 if is_nil is not None:
2005 is_nil = kw['_nil'] = pyxb.binding.datatypes.boolean(is_nil)
2006 if location is not None:
2007 self._setLocation(location)
2008 if self._AttributeWildcard is not None:
2009 self.__wildcardAttributeMap = { }
2010 if self._HasWildcardElement:
2011 self.__wildcardElements = []
2012 if self._Abstract:
2013 raise pyxb.AbstractInstantiationError(type(self), location, dom_node)
2014 super(complexTypeDefinition, self).__init__(**kw)
2015 self.reset()
2016 self._setAttributesFromKeywordsAndDOM(kw, dom_node)
2017 did_set_kw_elt = False
2018 for fu in self._ElementMap.values():
2019 iv = kw.pop(fu.id(), None)
2020 if iv is not None:
2021 did_set_kw_elt = True
2022 fu.set(self, iv)
2023 if do_finalize_content_model is None:
2024 do_finalize_content_model = not did_set_kw_elt
2025 if kw and kw.pop('_strict_keywords', True):
2026 [ kw.pop(_fkw, None) for _fkw in self._PyXBFactoryKeywords ]
2027 if kw:
2028 raise pyxb.UnprocessedKeywordContentError(self, kw)
2029 if 0 < len(args):
2030 if did_set_kw_elt:
2031 raise pyxb.UsageError('Cannot mix keyword and positional args for element initialization')
2032 self.extend(args, _from_xml=from_xml, _location=location)
2033 elif self._CT_SIMPLE == self._ContentTypeTag:
2034 value = self._TypeDefinition.Factory(_require_value=not self._isNil(), _dom_node=dom_node, _location=location, _nil=self._isNil(), _apply_attributes=False, *args)
2035 if value._constructedWithValue():
2036 self.append(value)
2037 elif dom_node is not None:
2038 self.extend(dom_node.childNodes[:], fallback_namespace)
2039 else:
2040 do_finalize_content_model = False
2041 if do_finalize_content_model:
2042 self._finalizeContentModel()
2043
2044
2045 _ReservedSymbols = _TypeBinding_mixin._ReservedSymbols.union(set([ 'wildcardElements', 'wildcardAttributeMap',
2046 'xsdConstraintsOK', 'content', 'orderedContent', 'append', 'extend', 'value', 'reset' ]))
2047
2048
2049
2050 _Automaton = None
2051
2052 @classmethod
2054 """Method used by generated code to associate the element binding with a use in this type.
2055
2056 This is necessary because all complex type classes appear in the
2057 module prior to any of the element instances (which reference type
2058 classes), so the association must be formed after the element
2059 instances are available."""
2060 return cls._UseForTag(element.name())._setElementBinding(element)
2061
2062 @classmethod
2064 """Return the ElementDeclaration object corresponding to the element name.
2065
2066 @param tag: The L{ExpandedName} of an element in the class."""
2067 try:
2068 rv = cls._ElementMap[tag]
2069 except KeyError:
2070 if raise_if_fail:
2071 raise
2072 rv = None
2073 return rv
2074
2076 """Generate a list of children in the order in which they should be
2077 added to the parent when creating a DOM representation of this
2078 object.
2079
2080 @note: This is only used when L{pyxb.RequireValidWhenGenerating} has
2081 disabled validation. Consequently, it may not generate valid XML.
2082 """
2083 order = []
2084 for ed in self._ElementMap.values():
2085 value = ed.value(self)
2086 if value is None:
2087 continue
2088 if isinstance(value, list) and ed.isPlural():
2089 order.extend([ ElementContent(_v, ed) for _v in value ])
2090 continue
2091 order.append(ElementContent(value, ed))
2092 return order
2093
2095 """Provide the child elements and non-element content in an order
2096 consistent with the content model.
2097
2098 Returns a sequence of tuples representing a valid path through the
2099 content model where each transition corresponds to one of the member
2100 element instances within this instance. The tuple is a pair
2101 comprising the L{content.ElementDeclaration} instance and the value for the
2102 transition.
2103
2104 If the content of the instance does not validate against the content
2105 model, an exception is raised.
2106
2107 @return: C{None} or a list as described above.
2108 """
2109 if self._ContentTypeTag in (self._CT_EMPTY, self._CT_SIMPLE):
2110 return []
2111 self._resetAutomaton()
2112 return self.__automatonConfiguration.sequencedChildren()
2113
2115 """Return a map from L{content.ElementDeclaration} instances to a list of
2116 values associated with that use.
2117
2118 This is used as the set of symbols available for transitions when
2119 validating content against a model. Note that the original
2120 L{content.ElementUse} that may have validated the assignment of the
2121 symbol to the content is no longer available, which may result in a
2122 different order being generated by the content model. Preservation of
2123 the original order mitigates this risk.
2124
2125 The value C{None} is used to provide the wildcard members, if any.
2126
2127 If an element use has no associated values, it must not appear in the
2128 returned map.
2129
2130 @raise pyxb.SimpleTypeValueError: when unable tconverting element
2131 content the binding declaration type.
2132 """
2133 rv = { }
2134 for eu in self._ElementMap.values():
2135 value = eu.value(self)
2136 if value is None:
2137 continue
2138 converter = eu.elementBinding().compatibleValue
2139 if eu.isPlural():
2140 if 0 < len(value):
2141 rv[eu] = [ converter(_v) for _v in value ]
2142 else:
2143 rv[eu] = [ converter(value)]
2144 wce = self.__wildcardElements
2145 if (wce is not None) and (0 < len(wce)):
2146 rv[None] = wce[:]
2147 return rv
2148
2152
2170
2180
2198
2199
2200
2201
2202 __content = None
2203
2204 - def orderedContent (self):
2205 """Return the element and non-element content of the instance in order.
2206
2207 This must be a complex type with complex content. The return value is
2208 a list of the element and non-element content in a preferred order.
2209
2210 The returned list contains L{element<ElementContent>} and
2211 L{non-element<NonElementContent>} content in the order which it was
2212 added to the instance. This may have been through parsing a document,
2213 constructing an instance using positional arguments, invoking the
2214 L{append} or L{extend} methods, or assigning directly to an instance
2215 attribute associated with an element binding.
2216
2217 @note: Be aware that assigning directly to an element attribute does not
2218 remove any previous value for the element from the content list.
2219
2220 @note: Be aware that element values directly appended to an instance
2221 attribute with list type (viz., that corresponds to an element that
2222 allows more than one occurrence) will not appear in the ordered
2223 content list.
2224
2225 The order in the list may influence the generation of documents
2226 depending on L{pyxb.ValidationConfig} values that apply to an
2227 instance. Non-element content is emitted immediately prior to the
2228 following element in this list. Any trailing non-element content is
2229 emitted after the last element in the content. The list should
2230 include all element content. Element content in this list that is not
2231 present within an element member of the binding instance may result in
2232 an error, or may be ignored.
2233
2234 @note: The returned value is mutable, allowing the caller to change
2235 the order to be used.
2236
2237 @raise pyxb.NotComplexContentError: this is not a complex type with mixed or element-only content
2238 """
2239 if self._ContentTypeTag in (self._CT_EMPTY, self._CT_SIMPLE):
2240 raise pyxb.NotComplexContentError(self)
2241 return self.__content
2242
2243 @classmethod
2244 - def __WarnOnContent (cls):
2245 if cls.__NeedWarnOnContent:
2246 import traceback
2247 cls.__NeedWarnOnContent = False
2248 _log.warning('Deprecated complexTypeDefinition method "content" invoked\nPlease use "orderedContent"\n%s', ''.join(traceback.format_stack()[:-2]))
2249 pass
2250 __NeedWarnOnContent = True
2251
2252 - def content (self):
2253 """Legacy interface for ordered content.
2254
2255 This version does not accurately distinguish non-element content from
2256 element content that happens to have unicode type.
2257
2258 @deprecated: use L{orderedContent}."""
2259 self.__WarnOnContent()
2260 if self._ContentTypeTag in (self._CT_EMPTY, self._CT_SIMPLE):
2261 raise pyxb.NotComplexContentError(self)
2262 return [ _v.value for _v in self.__content ]
2263
2265 """Return the value of the element.
2266
2267 This must be a complex type with simple content. The returned value
2268 is expected to be an instance of some L{simpleTypeDefinition} class.
2269
2270 @raise pyxb.NotSimpleContentError: this is not a complex type with simple content
2271 """
2272 if self._CT_SIMPLE != self._ContentTypeTag:
2273 raise pyxb.NotSimpleContentError(self)
2274 return self.__content
2275
2276 - def _resetContent (self, reset_elements=False):
2277 if reset_elements:
2278 for eu in self._ElementMap.values():
2279 eu.reset(self)
2280 nv = None
2281 if self._ContentTypeTag in (self._CT_MIXED, self._CT_ELEMENT_ONLY):
2282 nv = []
2283 return self.__setContent(nv)
2284
2285 __automatonConfiguration = None
2293
2297
2299 """Reset the instance.
2300
2301 This resets all element and attribute fields, and discards any
2302 recorded content. It resets the content model automaton to its
2303 initial state.
2304
2305 @see: Manipulate the return value of L{orderedContent} if your intent is
2306 to influence the generation of documents from the binding instance
2307 without changing its (element) content.
2308 """
2309
2310 self._resetContent(reset_elements=True)
2311 for au in self._AttributeMap.values():
2312 au.reset(self)
2313 self._resetAutomaton()
2314 return self
2315
2316 @classmethod
2318 """Determine what the given name means as an element in this type.
2319
2320 Normally, C{element_name} identifies an element definition within this
2321 type. If so, the returned C{element_decl} identifies that definition,
2322 and the C{element_binding} is extracted from that use.
2323
2324 It may also be that the C{element_name} does not appear as an element
2325 definition, but that it identifies a global element. In that case,
2326 the returned C{element_binding} identifies the global element. If,
2327 further, that element is a member of a substitution group which does
2328 have an element definition in this class, then the returned
2329 C{element_decl} identifies that definition.
2330
2331 If a non-C{None} C{element_decl} is returned, there will be an
2332 associated C{element_binding}. However, it is possible to return a
2333 non-C{None} C{element_binding}, but C{None} as the C{element_decl}. In
2334 that case, the C{element_binding} can be used to create a binding
2335 instance, but the content model will have to treat it as a wildcard.
2336
2337 @param element_name: The name of the element in this type, either an
2338 expanded name or a local name if the element has an absent namespace.
2339
2340 @return: C{( element_binding, element_decl )}
2341 """
2342 element_decl = cls._ElementMap.get(element_name)
2343 element_binding = None
2344 if element_decl is None:
2345 try:
2346 element_binding = element_name.elementBinding()
2347 except pyxb.NamespaceError:
2348 pass
2349 if element_binding is not None:
2350 element_decl = element_binding.findSubstituendDecl(cls)
2351 else:
2352 element_binding = element_decl.elementBinding()
2353 return (element_binding, element_decl)
2354
2355 - def append (self, value, **kw):
2356 """Add the value to the instance.
2357
2358 The value should be a DOM node or other value that is or can be
2359 converted to a binding instance, or a string if the instance allows
2360 mixed content. The value must be permitted by the content model.
2361
2362 @raise pyxb.ContentValidationError: the value is not permitted at the current
2363 state of the content model.
2364 """
2365
2366
2367
2368 element_decl = kw.get('_element_decl', None)
2369 maybe_element = kw.get('_maybe_element', True)
2370 location = kw.get('_location', None)
2371 if self._isNil():
2372 raise pyxb.ContentInNilInstanceError(self, value, location)
2373 fallback_namespace = kw.get('_fallback_namespace', None)
2374 require_validation = kw.get('_require_validation', self._validationConfig.forBinding)
2375 from_xml = kw.get('_from_xml', False)
2376 element_binding = None
2377 if element_decl is not None:
2378 from pyxb.binding import content
2379 assert isinstance(element_decl, content.ElementDeclaration)
2380 element_binding = element_decl.elementBinding()
2381 assert element_binding is not None
2382
2383 if isinstance(value, xml.dom.Node):
2384 from_xml = True
2385 assert maybe_element
2386 assert element_binding is None
2387 node = value
2388 require_validation = pyxb.GlobalValidationConfig.forBinding
2389 if xml.dom.Node.COMMENT_NODE == node.nodeType:
2390
2391
2392 return self
2393 if node.nodeType in (xml.dom.Node.TEXT_NODE, xml.dom.Node.CDATA_SECTION_NODE):
2394 value = node.data
2395 maybe_element = False
2396 else:
2397
2398 assert xml.dom.Node.ELEMENT_NODE == node.nodeType
2399 expanded_name = pyxb.namespace.ExpandedName(node, fallback_namespace=fallback_namespace)
2400 (element_binding, element_decl) = self._ElementBindingDeclForName(expanded_name)
2401 if element_binding is not None:
2402
2403
2404 value = element_binding._createFromDOM(node, expanded_name, _fallback_namespace=fallback_namespace)
2405 else:
2406
2407
2408 try:
2409 value = element.CreateDOMBinding(node, None, _fallback_namespace=fallback_namespace)
2410 except:
2411 _log.warning('Unable to convert DOM node %s at %s to binding', expanded_name, getattr(node, 'location', '[UNAVAILABLE]'))
2412 if (not maybe_element) and isinstance(value, basestring) and (self._ContentTypeTag in (self._CT_EMPTY, self._CT_ELEMENT_ONLY)):
2413 if (0 == len(value.strip())) and not self._isNil():
2414 return self
2415 if maybe_element and (self.__automatonConfiguration is not None):
2416
2417 if not require_validation:
2418 if element_decl is not None:
2419 element_decl.setOrAppend(self, value)
2420 return self
2421 if self.__wildcardElements is not None:
2422 self._appendWildcardElement(value)
2423 return self
2424 raise pyxb.StructuralBadDocumentError(container=self, content=value)
2425
2426 num_cand = self.__automatonConfiguration.step(value, element_decl)
2427 if 1 <= num_cand:
2428
2429 return self
2430
2431
2432
2433 if (element_binding is not None) or isinstance(value, (xml.dom.Node, complexTypeDefinition, pyxb.BIND)):
2434 raise pyxb.UnrecognizedContentError(self, self.__automatonConfiguration, value, location)
2435
2436
2437
2438 if self._IsSimpleTypeContent():
2439 if self.__content is not None:
2440 raise pyxb.ExtraSimpleContentError(self, value)
2441 if not self._isNil():
2442 if not isinstance(value, self._TypeDefinition):
2443 value = self._TypeDefinition.Factory(value, _from_xml=from_xml)
2444 self.__setContent(value)
2445 if require_validation:
2446
2447
2448
2449 self.xsdConstraintsOK(location)
2450 return self
2451
2452
2453 if not self._IsMixed():
2454 raise pyxb.MixedContentError(self, value, location)
2455
2456
2457 self._addContent(NonElementContent(value))
2458 return self
2459
2463
2464 - def extend (self, value_list, _fallback_namespace=None, _from_xml=False, _location=None):
2465 """Invoke L{append} for each value in the list, in turn."""
2466 [ self.append(_v, _fallback_namespace=_fallback_namespace, _from_xml=_from_xml, _location=_location) for _v in value_list ]
2467 return self
2468
2469 - def __setContent (self, value):
2470 self.__content = value
2471 return self.__content
2472
2473 - def _addContent (self, wrapped_value):
2474
2475
2476
2477 assert not (self._ContentTypeTag in (self._CT_EMPTY, self._CT_SIMPLE))
2478 assert isinstance(wrapped_value, _Content)
2479 self.__content.append(wrapped_value)
2480 if isinstance(wrapped_value, ElementContent):
2481 value = wrapped_value.value
2482 ed = wrapped_value.elementDeclaration
2483 if isinstance(value, _TypeBinding_mixin) and (ed is not None) and (value._element() is None):
2484 assert isinstance(ed.elementBinding(), element)
2485 value._setElement(ed.elementBinding())
2486
2487 @classmethod
2490
2495
2496 - def _postDOMValidate (self):
2508
2516
2518 """Create a DOM element with the given tag holding the content of this instance."""
2519 element = parent
2520 self._setDOMFromAttributes(dom_support, element)
2521 if self._isNil():
2522 pass
2523 elif self._CT_EMPTY == self._ContentTypeTag:
2524 pass
2525 elif self._CT_SIMPLE == self._ContentTypeTag:
2526 assert self.value() is not None, '%s has no value' % (self,)
2527 dom_support.appendTextChild(self.value().xsdLiteral(), element)
2528 else:
2529 if pyxb.GlobalValidationConfig.forDocument:
2530 order = self._validatedChildren()
2531 else:
2532 order = self.__childrenForDOM()
2533 for content in order:
2534 assert content.value != self
2535 if isinstance(content, NonElementContent):
2536 dom_support.appendTextChild(content.value, element)
2537 continue
2538 if content.elementDeclaration is None:
2539 if isinstance(content.value, xml.dom.Node):
2540 dom_support.appendChild(content.value, element)
2541 else:
2542 content.value.toDOM(dom_support, parent)
2543 else:
2544 content.elementDeclaration.toDOM(dom_support, parent, content.value)
2545 mixed_content = self.orderedContent()
2546 for mc in mixed_content:
2547 pass
2548 return getattr(super(complexTypeDefinition, self), '_toDOM_csc', lambda *_args,**_kw: dom_support)(dom_support, parent)
2549
2550 @classmethod
2552 """CTDs with simple content are simple; other CTDs are not."""
2553 return cls._CT_SIMPLE == cls._ContentTypeTag
2554
2555 @classmethod
2556 - def _description (cls, name_only=False, user_documentation=True):
2582
2583
2584
2585
2586