1.2.1. Core Types and Utilities

This module contains a number core classes used to support the standard.

1.2.1.1. Enumerations

Where the DTD defines enumerated attribute values we define special enumeration classes. These follow a common pattern in which the values are represented by constant members of the class. The classes are not designed to be instantiated but they do define class methods for decoding and encoding from and to text strings.

class pyslet.qtiv1.core.Action

Bases: pyslet.xsdatatypes20041028.Enumeration

Action enumeration (for pyslet.qtiv1.common.SetVar:

(Set | Add | Subtract | Multiply | Divide )  'Set'

Defines constants for the above action types. Usage example:

Action.Add

Note that:

Action.DEFAULT == Action.Set

For more methods see Enumeration

class pyslet.qtiv1.core.Area

Bases: pyslet.xsdatatypes20041028.Enumeration

Area enumeration:

(Ellipse | Rectangle | Bounded )  'Ellipse'

Defines constants for the above area types. Usage example:

Area.Rectangle

Note that:

Area.DEFAULT == Area.Ellipse

For more methods see Enumeration

pyslet.qtiv1.core.MigrateV2AreaCoords(area, value, log)

Returns a tuple of (shape,coords object) representing the area.

  • area is one of the Area constants.

  • value is the string containing the content of the element to which

    the area applies.

This conversion is generous because the separators have never been well defined and in some cases content uses a mixture of space and ‘,’.

Note also that the definition of rarea was updated in the 1.2.1 errata and that affects this algorithm. The clarification on the definition of ellipse from radii to diameters might mean that some content ends up with hotspots that are too small but this is safer than hotspots that are too large.

Example:

import pyslet.qtiv1.core as qticore1
import pyslet.qtiv2.core as qticore2
import pyslet.html40_1991224 as html
log=[]
shape,coords=qticore1.MigrateV2AreaCoords(qticore1.Area.Ellipse,"10,10,2,2",log)
# returns (qticore2.Shape.circle, html.Coords([10, 10, 1]) )

Note that Ellipse was deprecated in QTI version 2:

import pyslet.qtiv1.core as qticore1
import pyslet.html40_1991224 as html
log=[]
shape,coords=qticore1.MigrateV2AreaCoords(qticore1.Area.Ellipse,"10,10,2,4",log)
print log
# outputs the following...

['Warning: ellipse shape is deprecated in version 2']
class pyslet.qtiv1.core.FeedbackStyle

Bases: pyslet.xsdatatypes20041028.Enumeration

feedbackstyle enumeration:

(Complete | Incremental | Multilevel | Proprietary )  'Complete'

Defines constants for the above feedback style. Usage example:

FeedbackStyle.Decimal

Note that:

FeedbackStyle.DEFAULT == FeedbackStyle.Complete

For more methods see Enumeration

class pyslet.qtiv1.core.FeedbackType

Bases: pyslet.xsdatatypes20041028.Enumeration

feedbacktype enumeration:

(Response | Solution | Hint )  'Response'

Defines constants for the above types of feedback. Usage example:

FeedbackType.Decimal

Note that:

FeedbackType.DEFAULT == FeedbackType.Response

For more methods see Enumeration

class pyslet.qtiv1.core.FIBType

Bases: pyslet.xsdatatypes20041028.Enumeration

Fill-in-the-blank type enumeration:

(String | Integer | Decimal | Scientific )  'String'

Defines constants for the above fill-in-the-blank types. Usage example:

FIBType.Decimal

Note that:

FIBType.DEFAULT == FIBType.String

For more methods see Enumeration

class pyslet.qtiv1.core.MDOperator

Bases: pyslet.xsdatatypes20041028.Enumeration

Metadata operator enumeration for pyslet.qtiv1.sao.SelectionMetadata:

(EQ | NEQ | LT | LTE | GT | GTE )

Defines constants for the above operators. Usage example:

MDOperator.EQ

Lower-case aliases of the constants are provided for compatibility.

For more methods see Enumeration

class pyslet.qtiv1.core.NumType

Bases: pyslet.xsdatatypes20041028.Enumeration

numtype enumeration:

(Integer | Decimal | Scientific )  'Integer'

Defines constants for the above numeric types. Usage example:

NumType.Scientific

Note that:

NumType.DEFAULT == NumType.Integer

For more methods see Enumeration

class pyslet.qtiv1.core.Orientation

Bases: pyslet.xsdatatypes20041028.Enumeration

Orientation enumeration:

(Horizontal | Vertical )  'Horizontal'

Defines constants for the above orientation types. Usage example:

Orientation.Horizontal

Note that:

Orientation.DEFAULT == Orientation.Horizontal

For more methods see Enumeration

pyslet.qtiv1.core.MigrateV2Orientation(orientation)

Maps a v1 orientation onto the corresponding v2 constant.

Raises KeyError if orientation is not one of the Orientation constants.

class pyslet.qtiv1.core.PromptType

Bases: pyslet.xsdatatypes20041028.Enumeration

Prompt type enumeration:

(Box | Dashline | Asterisk | Underline )

Defines constants for the above prompt types. Usage example:

PromptType.Dashline

For more methods see Enumeration

class pyslet.qtiv1.core.RCardinality

Bases: pyslet.xsdatatypes20041028.Enumeration

rcardinality enumeration:

(Single | Multiple | Ordered )  'Single'

Defines constants for the above cardinality types. Usage example:

RCardinality.Multiple

Note that:

RCardinality.DEFAULT == RCardinality.Single

For more methods see Enumeration

pyslet.qtiv1.core.MigrateV2Cardinality(rCardinality)

Maps a v1 cardinality onto the corresponding v2 constant.

Raises KeyError if rCardinality is not one of the RCardinality constants.

pyslet.qtiv1.core.TestOperator = <class pyslet.qtiv1.core.MDOperator at 0x7f81efc8e188>

A simple alias of MDOperator defined for pyslet.qtiv1.outcomes.VariableTest

class pyslet.qtiv1.core.VarType

Bases: pyslet.xsdatatypes20041028.Enumeration

vartype enumeration:

(Integer | String | Decimal | Scientific | Boolean | Enumerated | Set )  'Integer'

Defines constants for the above view types. Usage example:

VarType.String

Note that:

VarType.DEFAULT == VarType.Integer

For more methods see Enumeration

pyslet.qtiv1.core.MigrateV2VarType(vartype, log)

Returns the v2 BaseType representing the v1 vartype.

Note that we reduce both Decimal and Scientific to the float types. In version 2 the BaseType values were chosen to map onto the typical types available in most programming languages. The representation of the number in decimal or exponent form is considered to be part of the interaction or the presentation rather than part of the underlying processing model. Although there clearly are use cases where retaining this distinction would have been an advantage the quality of implementation was likely to be poor and use cases that require a distinction are now implemented in more cumbersome, but probably more interoperable ways.

Note also that the poorly defined Set type in version 1 maps to an identifier in version 2 on the assumption that the cardinality will be upgraded as necessary.

Raises KeyError if vartype is not one of the VarType constants.

class pyslet.qtiv1.core.View

Bases: pyslet.xsdatatypes20041028.Enumeration

View enumeration:

(All | Administrator | AdminAuthority | Assessor | Author | Candidate |
InvigilatorProctor | Psychometrician | Scorer | Tutor )  'All'

Defines constants for the above view types. Usage example:

View.Candidate

Note that:

View.DEFAULT == View.All

In addition to the constants defined in the specification we add two aliases which are in common use:

(Invigilator | Proctor)

For more methods see Enumeration

pyslet.qtiv1.core.MigrateV2View(view, log)

Returns a list of v2 view values representing the v1 view.

The use of a list as the return type enables mapping of the special value ‘All’, which has no direct equivalent in version 2 other than providing all the defined views.

Raises KeyError if view is not one of the View constants.

This function will log warnings when migrating the following v1 values: Administrator, AdminAuthority, Assessor and Psychometrician

1.2.1.2. Utility Functions

pyslet.qtiv1.core.MakeValidName(name)

This function takes a string that is supposed to match the production for Name in XML and forces it to comply by replacing illegal characters with ‘_’. If name starts with a valid name character but not a valid name start character, it is prefixed with ‘_’ too.

pyslet.qtiv1.core.ParseYesNo(src)

Returns a True/False parsed from a “Yes” / “No” string.

This function is generous in what it accepts, it will accept mixed case and strips surrounding space. It returns True if the resulting string matches “yes” and False otherwise.

Reverses the transformation defined by FormatYesNo().

pyslet.qtiv1.core.FormatYesNo(value)

Returns “Yes” if value is True, “No” otherwise.

Reverses the transformation defined by ParseYesNo().

1.2.1.3. Constants

pyslet.qtiv1.core.QTI_SOURCE = 'QTIv1'

str(object=’‘) -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

1.2.1.4. Exceptions

class pyslet.qtiv1.core.QTIError

Bases: exceptions.Exception

All errors raised by this module are derived from QTIError.

class pyslet.qtiv1.core.QTIUnimplementedError

Bases: pyslet.qtiv1.core.QTIError

A feature of QTI v1 that is not yet implemented by this module.

1.2.1.5. Abstract Elements

class pyslet.qtiv1.core.QTIElement(parent, name=None)

Bases: pyslet.xml20081126.structures.Element

Base class for all elements defined by the QTI specification

DeclareMetadata(label, entry, definition=None)

Declares a piece of metadata to be associated with the element.

Most QTIElements will be contained by some type of metadata container that collects metadata in a format suitable for easy lookup and export to other metadata formats. The default implementation simply passes the call to the parent element or, if there is no parent, the declaration is ignored.

For more information see MetadataContainer.

class pyslet.qtiv1.core.ObjectMixin

Mix-in class for elements that can be inside ObjectBank:

(section | item)+
class pyslet.qtiv1.core.SectionItemMixin

Mix-in class for objects that can be in section objects:

(itemref | item | sectionref | section)*
class pyslet.qtiv1.core.SectionMixin

Bases: pyslet.qtiv1.core.SectionItemMixin

Mix-in class for objects that can be in assessment objects:

(sectionref | section)+