1.3.10. Core Types and Utilities¶
This module contains a number core classes used to support the standard.
1.3.10.1. Constants¶
- pyslet.qtiv2.core.IMSQTI_NAMESPACE = 'http://www.imsglobal.org/xsd/imsqti_v2p1'¶
The namespace used to recognise elements in XML documents.
- pyslet.qtiv2.core.IMSQTI_SCHEMALOCATION = 'http://www.imsglobal.org/xsd/imsqti_v2p1.xsd'¶
The location of the QTI 2.1 schema file on the IMS website.
- pyslet.qtiv2.core.IMSQTI_ITEM_RESOURCETYPE = 'imsqti_item_xmlv2p1'¶
The resource type to use for the QTI 2.1 items when added to content packages.
1.3.10.2. XML Basics¶
- class pyslet.qtiv2.core.QTIElement(parent, name=None)¶
Bases: pyslet.xmlnames20091208.XMLNSElement
Basic element to represent all QTI elements
- AddToCPResource(cp, resource, beenThere)¶
We need to add any files with URL’s in the local file system to the content package.
beenThere is a dictionary we use for mapping URLs to File objects so that we don’t keep adding the same linked resource multiple times.
This implementation is a little more horrid, we avoid circular module references by playing dumb about our children. HTML doesn’t actually know anything about QTI even though QTI wants to define children for some XHTML elements so we pass the call only to “CP-Aware” elements.
- class pyslet.qtiv2.core.QTIDocument(**args)¶
Bases: pyslet.xmlnames20091208.XMLNSDocument
Used to represent all documents representing information from the QTI v2 specification.
- AddToContentPackage(cp, metadata, dName=None)¶
Copies this QTI document into a content package and returns the resource ID used.
An optional directory name can be specified in which to put the resource files.
1.3.10.3. Exceptions¶
- class pyslet.qtiv2.core.QTIError¶
Bases: exceptions.Exception
Abstract class used for all QTI v2 exceptions.
- class pyslet.qtiv2.core.DeclarationError¶
Bases: pyslet.qtiv2.core.QTIError
Error raised when a variable declaration is invalid.
- class pyslet.qtiv2.core.ProcessingError¶
Bases: pyslet.qtiv2.core.QTIError
Error raised when an invalid processing element is encountered.
- class pyslet.qtiv2.core.SelectionError¶
Bases: pyslet.qtiv2.core.QTIError
Error raised when there is a problem with creating test forms.
1.3.10.4. Basic Data Types¶
Basic data types in QTI v2 are a mixture of custom types and basic types defined externally, for example, by XMLSchema.
The external types used are:
- boolean
- Represented by python’s boolean values True and False. See DecodeBoolean() and EncodeBoolean()
- coords
- Defined as part of support for HTML. See Coords
- date
- Although QTI draws on the definitions in XML schema it restricts values to those from the nontimezoned timeline. This restriction is effectively implemented in the basic Date class.
- datetime:
- See DecodeDateTime() and EncodeDateTime()
- duration:
- Earlier versions of QTI drew on the ISO8601 representation of duration but QTI v2 simplifies this with a basic representation in seconds bound to XML Schema’s double type which we, in turn, represent with python’s float. See DecodeDouble() and EncodeDouble()
- float:
- implemented by python’s float. Note that this is defined as having “machine-level double precision” and the python specification goes on to warn that “You are at the mercy of the underlying machine architecture”. See DecodeDouble() and EncodeDouble()
- identifier:
represented by python’s (unicode) string. The type is effectively just the NCName from the XML namespace specification. See pyslet.xmlnames20091208.IsValidNCName().
- pyslet.qtiv2.core.ValidateIdentifier(value, prefix='_')¶
Decodes an identifier from a string:
<xsd:simpleType name="identifier.Type"> <xsd:restriction base="xsd:NCName"/> </xsd:simpleType>
This function takes a string that is supposed to match the production for NCName in XML and forces it to comply by replacing illegal characters with ‘_’, except the ‘:’ which is replaced with a hyphen for compatibility with previous versions of the QTI migraiton script. If name starts with a valid name character but not a valid name start character, it is prefixed with ‘_’ too, but the prefix string used can be overridden.
- integer:
- XML schema’s integer, implemented by python’s integer. See DecodeInteger() and EncodeInteger()
- language:
- Currently implemented as a simple python string.
- length:
- Defined as part of support for HTML. See LengthType
- mimeType:
- Currently implemented as a simple python string
- string:
- XML schema string becomes python’s unicode string
- string256:
- Length restriction not yet implemented, see string above.
- styleclass:
- Inherited from HTML, implemented with a simple (unicode) string.
- uri:
- In some instances this is implemented as a simple (unicode) string, for example, in cases where a URI is being used as global identifier. In contexts where the URI will need to be interpreted it is implemented with instances of pyslet.rfc2396.URI.
QTI-specific types:
- class pyslet.qtiv2.core.Orientation¶
Bases: pyslet.xsdatatypes20041028.Enumeration
Orientation attribute values provide a hint to rendering systems that an element has an inherent vertical or horizontal interpretation:
<xsd:simpleType name="orientation.Type"> <xsd:restriction base="xsd:NMTOKEN"> <xsd:enumeration value="horizontal"/> <xsd:enumeration value="vertical"/> </xsd:restriction> </xsd:simpleType>
Defines constants for the above orientations. Usage example:
Orientation.horizontal
Note that:
Orientation.DEFAULT == None
For more methods see Enumeration
- class pyslet.qtiv2.core.Shape¶
Bases: pyslet.xsdatatypes20041028.Enumeration
A value of a shape is always accompanied by coordinates and an associated image which provides a context for interpreting them:
<xsd:simpleType name="shape.Type"> <xsd:restriction base="xsd:NMTOKEN"> <xsd:enumeration value="circle"/> <xsd:enumeration value="default"/> <xsd:enumeration value="ellipse"/> <xsd:enumeration value="poly"/> <xsd:enumeration value="rect"/> </xsd:restriction> </xsd:simpleType>
Defines constants for the above types of Shape. Usage example:
Shape.circle
Note that:
Shape.DEFAULT == Shape.default
For more methods see Enumeration
- class pyslet.qtiv2.core.ShowHide¶
Bases: pyslet.xsdatatypes20041028.Enumeration
Used to control content visibility with variables
<xsd:simpleType name="showHide.Type"> <xsd:restriction base="xsd:NMTOKEN"> <xsd:enumeration value="hide"/> <xsd:enumeration value="show"/> </xsd:restriction> </xsd:simpleType>
Note that ShowHide.DEFAULT == ShowHide.show
- class pyslet.qtiv2.core.View¶
Bases: pyslet.xsdatatypes20041028.Enumeration
Used to represent roles when restricting view:
<xsd:simpleType name="view.Type"> <xsd:restriction base="xsd:NMTOKEN"> <xsd:enumeration value="author"/> <xsd:enumeration value="candidate"/> <xsd:enumeration value="proctor"/> <xsd:enumeration value="scorer"/> <xsd:enumeration value="testConstructor"/> <xsd:enumeration value="tutor"/> </xsd:restriction> </xsd:simpleType>
Defines constants for the above views. Usage example:
View.candidate
There is no default view. Views are represented in XML as space-separated lists of values. Typical usage:
view=View.DecodeValueDict("tutor scorer") # returns... { View.tutor:'tutor', View.scorer:'scorer' } View.EncodeValueDict(view) # returns... "scorer tutor"
For more methods see Enumeration
The QTI specification lists valueType as a basic data type. In pyslet this is implemented as a core part of the processing model. See pyslet.qtiv2.variables.Value for details.