@@ -331,6 +331,10 @@ def _get_schema_documents(self, namespace, fail_silently=False):
331331
332332
333333class SchemaDocument (object ):
334+ """A Schema Document consists of a set of schema components for a specific
335+ target namespace.
336+
337+ """
334338 def __init__ (self , namespace , location , base_url ):
335339 logger .debug ("Init schema document for %r" , location )
336340
@@ -340,6 +344,7 @@ def __init__(self, namespace, location, base_url):
340344 self ._target_namespace = namespace
341345 self ._is_internal = False
342346
347+ # Containers for specific types
343348 self ._attribute_groups = {}
344349 self ._attributes = {}
345350 self ._elements = {}
@@ -365,6 +370,12 @@ def is_empty(self):
365370 return not bool (self ._imports or self ._types or self ._elements )
366371
367372 def load (self , schema , node ):
373+ """Load the XML Schema passed in via the node attribute.
374+
375+ :type schema: zeep.xsd.schema.Schema
376+ :type node: etree._Element
377+
378+ """
368379 if node is None :
369380 return
370381
@@ -415,86 +426,110 @@ def _resolve_dict(val):
415426 _resolve_dict (self ._types )
416427
417428 def register_import (self , namespace , schema ):
429+ """Register an import for an other schema document.
430+
431+ :type namespace: str
432+ :type schema: zeep.xsd.schema.SchemaDocument
433+
434+ """
418435 schemas = self ._imports .setdefault (namespace , [])
419436 schemas .append (schema )
420437
421438 def is_imported (self , namespace ):
422439 return namespace in self ._imports
423440
424- def register_type (self , name , value ):
425- assert not isinstance (value , type )
426- assert value is not None
441+ def register_type (self , qname , value ):
442+ """Register a xsd.Type in this schema
427443
428- if isinstance (name , etree .QName ):
429- name = name .text
430- logger .debug ("register_type(%r, %r)" , name , value )
431- self ._types [name ] = value
444+ :type qname: str or etree.QName
445+ :type value: zeep.xsd.Type
432446
433- def register_element (self , name , value ):
434- if isinstance (name , etree .QName ):
435- name = name .text
436- logger .debug ("register_element(%r, %r)" , name , value )
437- self ._elements [name ] = value
447+ """
448+ self ._add_component (qname , value , self ._types , 'type' )
438449
439- def register_group (self , name , value ):
440- if isinstance (name , etree .QName ):
441- name = name .text
442- logger .debug ("register_group(%r, %r)" , name , value )
443- self ._groups [name ] = value
450+ def register_element (self , qname , value ):
451+ """Register a xsd.Element in this schema
444452
445- def register_attribute (self , name , value ):
446- if isinstance (name , etree .QName ):
447- name = name .text
448- logger .debug ("register_attribute(%r, %r)" , name , value )
449- self ._attributes [name ] = value
453+ :type qname: str or etree.QName
454+ :type value: zeep.xsd.Element
450455
451- def register_attribute_group (self , name , value ):
452- if isinstance (name , etree .QName ):
453- name = name .text
454- logger .debug ("register_attribute_group(%r, %r)" , name , value )
455- self ._attribute_groups [name ] = value
456+ """
457+ self ._add_component (qname , value , self ._elements , 'element' )
458+
459+ def register_group (self , qname , value ):
460+ """Register a xsd.Element in this schema
461+
462+ :type qname: str or etree.QName
463+ :type value: zeep.xsd.Element
464+
465+ """
466+ self ._add_component (qname , value , self ._groups , 'group' )
467+
468+ def register_attribute (self , qname , value ):
469+ """Register a xsd.Element in this schema
470+
471+ :type qname: str or etree.QName
472+ :type value: zeep.xsd.Attribute
473+
474+ """
475+ self ._add_component (qname , value , self ._attributes , 'attribute' )
476+
477+ def register_attribute_group (self , qname , value ):
478+ """Register a xsd.Element in this schema
479+
480+ :type qname: str or etree.QName
481+ :type value: zeep.xsd.Group
482+
483+ """
484+ self ._add_component (qname , value , self ._attribute_groups , 'attribute_group' )
456485
457486 def get_type (self , qname ):
458487 """Return a xsd.Type object from this schema
459488
460489 :rtype: zeep.xsd.ComplexType or zeep.xsd.AnySimpleType
461490
462491 """
463- return self ._get_instance (qname , self ._types , 'type' )
492+ return self ._get_component (qname , self ._types , 'type' )
464493
465494 def get_element (self , qname ):
466495 """Return a xsd.Element object from this schema
467496
468497 :rtype: zeep.xsd.Element
469498
470499 """
471- return self ._get_instance (qname , self ._elements , 'element' )
500+ return self ._get_component (qname , self ._elements , 'element' )
472501
473502 def get_group (self , qname ):
474503 """Return a xsd.Group object from this schema.
475504
476505 :rtype: zeep.xsd.Group
477506
478507 """
479- return self ._get_instance (qname , self ._groups , 'group' )
508+ return self ._get_component (qname , self ._groups , 'group' )
480509
481510 def get_attribute (self , qname ):
482511 """Return a xsd.Attribute object from this schema
483512
484513 :rtype: zeep.xsd.Attribute
485514
486515 """
487- return self ._get_instance (qname , self ._attributes , 'attribute' )
516+ return self ._get_component (qname , self ._attributes , 'attribute' )
488517
489518 def get_attribute_group (self , qname ):
490519 """Return a xsd.AttributeGroup object from this schema
491520
492521 :rtype: zeep.xsd.AttributeGroup
493522
494523 """
495- return self ._get_instance (qname , self ._attribute_groups , 'attributeGroup' )
524+ return self ._get_component (qname , self ._attribute_groups , 'attributeGroup' )
525+
526+ def _add_component (self , name , value , items , item_name ):
527+ if isinstance (name , etree .QName ):
528+ name = name .text
529+ logger .debug ("register_%s(%r, %r)" , item_name , name , value )
530+ items [name ] = value
496531
497- def _get_instance (self , qname , items , item_name ):
532+ def _get_component (self , qname , items , item_name ):
498533 try :
499534 return items [qname ]
500535 except KeyError :
0 commit comments