3.3.10. Core Types and Utilities¶
This module contains a number core classes used to support the standard.
3.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.
3.3.10.2. XML Basics¶
-
class
pyslet.qtiv2.core.
QTIElement
(parent, name=None)¶ Bases:
pyslet.xml.namespace.NSElement
Basic element to represent all QTI elements
-
add_to_cpresource
(cp, resource, been_there)¶ We need to add any files with URL’s in the local file system to the content package.
been_there 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.
-
3.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.
3.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
boolean_from_str()
andboolean_to_str()
- 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()
andEncodeDateTime()
- 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
double_from_str()
anddouble_to_str()
- 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
double_from_str()
anddouble_to_str()
- identifier:
represented by python’s (unicode) string. The type is effectively just the NCName from the XML namespace specification. See
pyslet.xml.namespace.IsValidNCName()
.-
pyslet.qtiv2.core.
ValidateIdentifier
(*args, **kwargs)¶ Deprecated equivalent to
validate_identifier()
-
- integer:
- XML schema’s integer, implemented by python’s integer. See
DecodeInteger()
andinteger_to_str()
- 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.xml.xsdatatypes.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.xml.xsdatatypes.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.xml.xsdatatypes.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.xml.xsdatatypes.EnumerationNoCase
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.