Package pyxsd :: Module schemaBase :: Class SchemaBase
[hide private]
[frames] | no frames]

Class SchemaBase

source code

object --+
         |
        SchemaBase

Serves as the base class for all schema type classes created. The pythonic instance tree is built from this class. This class also contains the means to do non-fatal parser error checking. A little bit of the work this class does is also done in pyXSD. The schema and xml file do not line up perfectly. The top level element in the schema and the schema tag both contain information relevent to the top-level tag in the XML. For this reason, the tree building/checking must be started in the same location the method makeInstanceFromTag is called in this class.

Instance Methods [hide private]
  __init__(self)
Creates the instances that are in the tree.
  getAttributesFromTag(self, elementTag)
Adds attributes to the _attribs_ dictionary in the instance.
  descAttributes(self)
Returns a dictionary of the descriptor attributes.
  descAttributeNames(self)
Returns a list that has all of the names of attribute descriptors.
  checkAttributes(self, usedAttrs, elementTag)
Checks to see that required attributes are used in the xml, and does other such checks on the attributes.

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__


Class Methods [hide private]
  makeInstanceFromTag(cls, elementTag)
A classmethod.
  addAttributesTo(cls, instance, elementTag)
A classmethod.
  addElementsTo(cls, instance, elementTag)
A classmethod.
  addValueTo(cls, instance, elementTag)
Checks to see if the tag has a value, and assigns it to the element instance if it does.
  checkElementOrderInChoice(cls, elemDescriptor, subElements)
A classmethod.
  checkElementOrderInSequence(cls, descriptors, subElements)
A classmethodChecks the element order in sequence fields to make sure that the order specified in the schema is preserved in the xml.
  consume(cls, dname, subElements)
A classmethod.
  primitiveValueFor(cls, subElCls, subElement)
A classmethod.
  addBaseDescriptors(cls)
Adds attribute descriptors from classes that are bases to the current class.

Static Methods [hide private]
  dumpCls(cls)
For debugging purposes only.

Properties [hide private]

Inherited from object: __class__


Method Details [hide private]

__init__(self)
(Constructor)

source code 

Creates the instances that are in the tree. These objects are initialized from within SchemaBase.

No parameters

Overrides: object.__init__

makeInstanceFromTag(cls, elementTag)
Class Method

source code 

A classmethod. It takes in a schema type class and its corresponding xml element. It then instanciates the class. It adds a name from the name in the xml element, and then it hands the instance and the element to other methods to add attributes, elements, and values to this instance. It adds these according to the schema classes, and not the element. A non-fatal (when possible) error is raised when the xml element does not correspond to the schema class.

Parameters:

  • cls- The schema type class to use. NOTE: since this function is a classmethod, cls is the first argument, not the instance of the class.
  • elementTag- The xml element that correspond to cls

addAttributesTo(cls, instance, elementTag)
Class Method

source code 

A classmethod. Called by makeInstanceFromTag(). Adds attributes according to the schema by calling getAttributesFromTag(). The attributes are then checked.

parameters:

  • cls- The schema type class to use. NOTE: since this function is a classmethod, cls is the first argument, not the instance of the class.
  • instance - The instance of cls that is having attributes added to it.
  • elementTag- The xml element that correspond to cls

getAttributesFromTag(self, elementTag)

source code 

Adds attributes to the _attribs_ dictionary in the instance. Only attributes in the type classes are added. All of the attribute values are validated against descriptors in the Attribute class in ElementRepresentatives. The only exception to this proceedure is for namespace and schemaLocation tags, as the program currently does not have any mechanism to actually check these.

Parameters:

  • elementTag: the xml element that the instance represents

addElementsTo(cls, instance, elementTag)
Class Method

source code 

A classmethod. Checks order on the child elements, with different functions for sequences and choices. Iterates through all the elements specified in the class of the schema, and matches these elements with the elements from the xml. Redirects elements that are primitive types (integer, double, string, and so on) to another function. Calls makeInstanceFromTag() on all the children.

Parameters:

  • cls- The schema type class to use. NOTE: since this function is a classmethod, cls is the first argument, not the instance of the class.
  • instance - The instance of cls that is having elements added to it.
  • elementTag- The xml element that correspond to cls

addValueTo(cls, instance, elementTag)
Class Method

source code 

Checks to see if the tag has a value, and assigns it to the element instance if it does. Uses the ElementTree function .text to retrieve this information from the tag.

Parameters:

  • cls- The schema type class to use. NOTE: since this function is a classmethod, cls is the first argument, not the instance of the class.
  • instance - The instance of cls that is having values added to it.
  • elementTag- The xml element that correspond to cls

checkElementOrderInChoice(cls, elemDescriptor, subElements)
Class Method

source code 

A classmethod. Checks to see that elements in a choice field, which is specified in the schema, follow the rules of such a field. Gets minOccurs and maxOccurs from the choice element in the schema, and checks the number of elements from there.

Parameters:

  • cls- The schema type class in use. NOTE: since this function is a classmethod, cls is the first argument, not the instance of the class.
  • subElements- All of the children of an element that is being processed in addElementsTo().

checkElementOrderInSequence(cls, descriptors, subElements)
Class Method

source code 

A classmethodChecks the element order in sequence fields to make sure that the order specified in the schema is preserved in the xml. Raises non-fatal errors when a problem is found. Checks minOccurs and maxOccurs on each element as well.

Parameters:

  • cls- The schema type class in use. NOTE: since this function is a classmethod, cls is the first argument, not the instance of the class.
  • descriptors- a list of schema-specified elements that define parameters for an element. Called descriptors because the program takes advantage of descriptors in python to help check the data. These descriptors are in the Element class in elementRepresentatives.
  • subElements- All of the children of an element that is being processed in addElementsTo(). Correspond to elements in descriptors

consume(cls, dname, subElements)
Class Method

source code 

A classmethod. Used to check the number of times an element type in the schema is used with the xml elements. Used by checkElementOrderInSequence().

Parameters:

  • cls- The schema type class in use. NOTE: since this function is a classmethod, cls is the first argument, not the instance of the class.
  • dname- The name of the descriptor that is currently being checked.
  • subElements- the list of subElements being checked.

primitiveValueFor(cls, subElCls, subElement)
Class Method

source code 

A classmethod. Used to check and assign primitive values to an instance. called by addElementsTo(). NOTE: this class may not work correctly for all elements with primitive data types. If you find an error in this method or any other error in the program, please submit this error and the appropiate correction on the pyXSD website.

Parameters:

  • cls- The schema type class in use. NOTE: since this function is a classmethod, cls is the first argument, not the instance of the class.
  • subElCls- the schema type class that corresponds to the subElement that is being processed.
  • subElement- The subElement that has a primitive data type.

addBaseDescriptors(cls)
Class Method

source code 

Adds attribute descriptors from classes that are bases to the current class. Does this recursively down the list of bases. Everything returned as a dictionary. A classmethod.

Parameters:

  • cls- The schema type class in use. NOTE: since this function is a classmethod, cls is the first argument, not the instance of the class.

descAttributes(self)

source code 

Returns a dictionary of the descriptor attributes. These attributes are from the schema and use descriptors, which are specified in the Attribute class in elementReprsentatives, that help check element attribute values. Uses lazy evulation by storing the descriptor attributes in a variable called '_descAttrs_', which it returns if this variable is specified.

No parameters.

descAttributeNames(self)

source code 
Returns a list that has all of the names of attribute descriptors. Calls descAttributes(), and returns a list of the keys from that dictionary.

checkAttributes(self, usedAttrs, elementTag)

source code 

Checks to see that required attributes are used in the xml, and does other such checks on the attributes. Note: the attribute descriptors check the values in element attributes.

Parameters:

  • usedAttrs- a list containing the names of attributes that were put into the instance.
  • elementTag- The ElementTree tag for the instance that is being checked.

dumpCls(cls)
Static Method

source code 

For debugging purposes only. Prints out the contents of a class. A staticmethod.

parameters:

  • cls- The class to dump the contents of. NOTE: this is the only arguement, since it is a staticmethod.