1.3.5. Item Variables¶
This module contains the basic run-time data model. Although the specification does contain elements to represent the values of variables set at runtime the XML schema sometimes relies too much on context for an efficient implementation. For example, a <value> element is always a value of a specific base type but the base type is rarely specified on the value element itself as it is normally implicit in the context. such as a variable declaration.
Although the expression model does contain an element that provides a more complete representation of single values (namely <baseValue>) we decide to make the distinction in this module with ValueElement representing the element and the abstract Value being used as the root of the runtime object model.
For example, to get the default value of a variable from a variable declaration you’ll use the GetDefaultValue() method and it will return a Value instance which could be of any cardinality or base type.
- class pyslet.qtiv2.variables.VariableDeclaration(parent)¶
Bases: pyslet.qtiv2.core.QTIElement
Item variables are declared by variable declarations... The purpose of the declaration is to associate an identifier with the variable and to identify the runtime type of the variable’s value:
<xsd:attributeGroup name="variableDeclaration.AttrGroup"> <xsd:attribute name="identifier" type="identifier.Type" use="required"/> <xsd:attribute name="cardinality" type="cardinality.Type" use="required"/> <xsd:attribute name="baseType" type="baseType.Type" use="optional"/> </xsd:attributeGroup> <xsd:group name="variableDeclaration.ContentGroup"> <xsd:sequence> <xsd:element ref="defaultValue" minOccurs="0" maxOccurs="1"/> </xsd:sequence> </xsd:group>
- class pyslet.qtiv2.variables.ValueElement(parent)¶
Bases: pyslet.qtiv2.core.QTIElement
A class that can represent a single value of any baseType in variable declarations and result reports:
<xsd:attributeGroup name="value.AttrGroup"> <xsd:attribute name="fieldIdentifier" type="identifier.Type" use="optional"/> <xsd:attribute name="baseType" type="baseType.Type" use="optional"/> </xsd:attributeGroup>
- class pyslet.qtiv2.variables.DefaultValue(parent)¶
Bases: pyslet.qtiv2.variables.DefinedValue
An optional default value for a variable. The point at which a variable is set to its default value varies depending on the type of item variable.
- class pyslet.qtiv2.variables.Cardinality¶
Bases: pyslet.xsdatatypes20041028.Enumeration
An expression or itemVariable can either be single-valued or multi-valued. A multi-valued expression (or variable) is called a container. A container contains a list of values, this list may be empty in which case it is treated as NULL. All the values in a multiple or ordered container are drawn from the same value set:
<xsd:simpleType name="cardinality.Type"> <xsd:restriction base="xsd:NMTOKEN"> <xsd:enumeration value="multiple"/> <xsd:enumeration value="ordered"/> <xsd:enumeration value="record"/> <xsd:enumeration value="single"/> </xsd:restriction> </xsd:simpleType>
Defines constants for the above carinalities. Usage example:
Cardinality.multiple
There is no default:
Cardinality.DEFAULT == None
For more methods see Enumeration
- class pyslet.qtiv2.variables.BaseType¶
Bases: pyslet.xsdatatypes20041028.Enumeration
A base-type is simply a description of a set of atomic values (atomic to this specification). Note that several of the baseTypes used to define the runtime data model have identical definitions to those of the basic data types used to define the values for attributes in the specification itself. The use of an enumeration to define the set of baseTypes used in the runtime model, as opposed to the use of classes with similar names, is designed to help distinguish between these two distinct levels of modelling:
<xsd:simpleType name="baseType.Type"> <xsd:restriction base="xsd:NMTOKEN"> <xsd:enumeration value="boolean"/> <xsd:enumeration value="directedPair"/> <xsd:enumeration value="duration"/> <xsd:enumeration value="file"/> <xsd:enumeration value="float"/> <xsd:enumeration value="identifier"/> <xsd:enumeration value="integer"/> <xsd:enumeration value="pair"/> <xsd:enumeration value="point"/> <xsd:enumeration value="string"/> <xsd:enumeration value="uri"/> </xsd:restriction> </xsd:simpleType>
Defines constants for the above base types. Usage example:
BaseType.float
There is no default:
BaseType.DEFAULT == None
For more methods see Enumeration
- class pyslet.qtiv2.variables.Mapping(parent)¶
Bases: pyslet.qtiv2.core.QTIElement
A special class used to create a mapping from a source set of any baseType (except file and duration) to a single float:
<xsd:attributeGroup name="mapping.AttrGroup"> <xsd:attribute name="lowerBound" type="float.Type" use="optional"/> <xsd:attribute name="upperBound" type="float.Type" use="optional"/> <xsd:attribute name="defaultValue" type="float.Type" use="required"/> </xsd:attributeGroup> <xsd:group name="mapping.ContentGroup"> <xsd:sequence> <xsd:element ref="mapEntry" minOccurs="1" maxOccurs="unbounded"/> </xsd:sequence> </xsd:group>
- ContentChanged()¶
Builds an internal dictionary of the values being mapped.
In order to fully specify the mapping we need to know the baseType of the source values. (The targets are always floats.) We do this based on our parent, orphan Mapping elements are treated as mappings from source strings.
- class pyslet.qtiv2.variables.MapEntry(parent)¶
Bases: pyslet.qtiv2.core.QTIElement
An entry in a Mapping
<xsd:attributeGroup name="mapEntry.AttrGroup"> <xsd:attribute name="mapKey" type="valueType.Type" use="required"/> <xsd:attribute name="mappedValue" type="float.Type" use="required"/> </xsd:attributeGroup>
- mapKey = None¶
The source value
- mappedValue = None¶
The mapped value
1.3.5.1. Response Variables¶
- class pyslet.qtiv2.variables.ResponseDeclaration(parent)¶
Bases: pyslet.qtiv2.variables.VariableDeclaration
Response variables are declared by response declarations and bound to interactions in the itemBody:
<xsd:group name="responseDeclaration.ContentGroup"> <xsd:sequence> <xsd:group ref="variableDeclaration.ContentGroup"/> <xsd:element ref="correctResponse" minOccurs="0" maxOccurs="1"/> <xsd:element ref="mapping" minOccurs="0" maxOccurs="1"/> <xsd:element ref="areaMapping" minOccurs="0" maxOccurs="1"/> </xsd:sequence> </xsd:group>
- GetCorrectValue()¶
Returns a Value instance representing either the correct response value or an appropriately typed NULL value if there is no correct value.
- GetStageDimensions()¶
For response variables with point type, returns a pair of integer values: width,height
In HTML, shapes (including those used in the AreaMapping) can use relative coordinates. To interpret relative coordinates we need to know the size of the stage used to interpret the point values. For a response variable that is typically the size of the image or object used in the interaction.
This method searches for the interaction associated with the response and obtains the width and height of the corresponding object.
[TODO: currently returns 100,100]
- class pyslet.qtiv2.variables.CorrectResponse(parent)¶
Bases: pyslet.qtiv2.variables.DefinedValue
A response declaration may assign an optional correctResponse. This value may indicate the only possible value of the response variable to be considered correct or merely just a correct value.
- class pyslet.qtiv2.variables.AreaMapping(parent)¶
Bases: pyslet.qtiv2.core.QTIElement
A special class used to create a mapping from a source set of point values to a target set of float values:
<xsd:attributeGroup name="areaMapping.AttrGroup"> <xsd:attribute name="lowerBound" type="float.Type" use="optional"/> <xsd:attribute name="upperBound" type="float.Type" use="optional"/> <xsd:attribute name="defaultValue" type="float.Type" use="required"/> </xsd:attributeGroup> <xsd:group name="areaMapping.ContentGroup"> <xsd:sequence> <xsd:element ref="areaMapEntry" minOccurs="1" maxOccurs="unbounded"/> </xsd:sequence> </xsd:group>
- MapValue(value, width, height)¶
Maps an instance of Value with point base type to an instance of Value with base type float.
- value is a Value of base type point
- width is the integer width of the object on which the area is defined
- height is the integer height of the object on which the area is defined
The width and height of the object are required because HTML allows relative values to be used when defining areas.
- class pyslet.qtiv2.variables.AreaMapEntry(parent)¶
Bases: pyslet.qtiv2.core.QTIElement, pyslet.qtiv2.core.ShapeElementMixin
An AreaMapping is defined by a set of areaMapEntries, each of which maps an area of the coordinate space onto a single float:
<xsd:attributeGroup name="areaMapEntry.AttrGroup"> <xsd:attribute name="shape" type="shape.Type" use="required"/> <xsd:attribute name="coords" type="coords.Type" use="required"/> <xsd:attribute name="mappedValue" type="float.Type" use="required"/> </xsd:attributeGroup>
- mappedValue = None¶
The mapped value
1.3.5.2. Outcome Variables¶
- class pyslet.qtiv2.variables.OutcomeDeclaration(parent)¶
Bases: pyslet.qtiv2.variables.VariableDeclaration
Outcome variables are declared by outcome declarations
<xsd:attributeGroup name="outcomeDeclaration.AttrGroup"> <xsd:attributeGroup ref="variableDeclaration.AttrGroup"/> <xsd:attribute name="view" use="optional"> <xsd:simpleType> <xsd:list itemType="view.Type"/> </xsd:simpleType> </xsd:attribute> <xsd:attribute name="interpretation" type="string.Type" use="optional"/> <xsd:attribute name="longInterpretation" type="uri.Type" use="optional"/> <xsd:attribute name="normalMaximum" type="float.Type" use="optional"/> <xsd:attribute name="normalMinimum" type="float.Type" use="optional"/> <xsd:attribute name="masteryValue" type="float.Type" use="optional"/> </xsd:attributeGroup> <xsd:group name="outcomeDeclaration.ContentGroup"> <xsd:sequence> <xsd:group ref="variableDeclaration.ContentGroup"/> <xsd:group ref="lookupTable.ElementGroup" minOccurs="0" maxOccurs="1"/> </xsd:sequence> </xsd:group>
- class pyslet.qtiv2.variables.LookupTable(parent)¶
Bases: pyslet.qtiv2.core.QTIElement
An abstract class associated with an outcomeDeclaration used to create a lookup table from a numeric source value to a single outcome value in the declared value set:
<xsd:attributeGroup name="lookupTable.AttrGroup"> <xsd:attribute name="defaultValue" type="valueType.Type" use="optional"/> </xsd:attributeGroup>
- class pyslet.qtiv2.variables.MatchTable(parent)¶
Bases: pyslet.qtiv2.variables.LookupTable
A matchTable transforms a source integer by finding the first matchTableEntry with an exact match to the source:
<xsd:group name="matchTable.ContentGroup"> <xsd:sequence> <xsd:element ref="matchTableEntry" minOccurs="1" maxOccurs="unbounded"/> </xsd:sequence> </xsd:group>
- ContentChanged()¶
Builds an internal dictionary of the values being mapped.
- class pyslet.qtiv2.variables.MatchTableEntry(parent)¶
Bases: pyslet.qtiv2.core.QTIElement
- sourceValue
- The source integer that must be matched exactly.
- targetValue
- The target value that is used to set the outcome when a match is found
<xsd:attributeGroup name="matchTableEntry.AttrGroup"> <xsd:attribute name="sourceValue" type="integer.Type" use="required"/> <xsd:attribute name="targetValue" type="valueType.Type" use="required"/> </xsd:attributeGroup>
- class pyslet.qtiv2.variables.InterpolationTable(parent)¶
Bases: pyslet.qtiv2.variables.LookupTable
An interpolationTable transforms a source float (or integer) by finding the first interpolationTableEntry with a sourceValue that is less than or equal to (subject to includeBoundary) the source value:
<xsd:group name="interpolationTable.ContentGroup"> <xsd:sequence> <xsd:element ref="interpolationTableEntry" minOccurs="1" maxOccurs="unbounded"/> </xsd:sequence> </xsd:group>
- ContentChanged()¶
Builds an internal table of the values being mapped.
- class pyslet.qtiv2.variables.InterpolationTableEntry(parent)¶
Bases: pyslet.qtiv2.core.QTIElement
- sourceValue
- The lower bound for the source value to match this entry.
- includeBoundary
- Determines if an exact match of sourceValue matches this entry. If true, the default, then an exact match of the value is considered a match of this entry.
- targetValue
- The target value that is used to set the outcome when a match is found
<xsd:attributeGroup name="interpolationTableEntry.AttrGroup"> <xsd:attribute name="sourceValue" type="float.Type" use="required"/> <xsd:attribute name="includeBoundary" type="boolean.Type" use="optional"/> <xsd:attribute name="targetValue" type="valueType.Type" use="required"/> </xsd:attributeGroup>
1.3.5.3. Template Variables¶
- class pyslet.qtiv2.variables.TemplateDeclaration(parent)¶
Bases: pyslet.qtiv2.variables.VariableDeclaration
Template declarations declare item variables that are to be used specifically for the purposes of cloning items
<xsd:attributeGroup name="templateDeclaration.AttrGroup"> <xsd:attributeGroup ref="variableDeclaration.AttrGroup"/> <xsd:attribute name="paramVariable" type="boolean.Type" use="optional"/> <xsd:attribute name="mathVariable" type="boolean.Type" use="optional"/> </xsd:attributeGroup>
1.3.5.4. Runtime Object Model¶
- class pyslet.qtiv2.variables.SessionState¶
Bases: object
Abstract class used as the base class for namespace-like objects used to track the state of an item or test session. Instances can be used as if they were dictionaries of Value.
- GetDeclaration(varName)¶
Returns the declaration associated with varName or None if the variable is one of the built-in variables. If varName is not a variable KeyError is raised. To test for the existence of a variable just use the object as you would a dictionary:
# state is a SessionState instance if 'RESPONSE' in state: print "RESPONSE declared!"
- IsResponse(varName)¶
Return True if varName is the name of a response variable.
- IsOutcome(varName)¶
Return True if varName is the name of an outcome variable.
- IsTemplate(varName)¶
Return True if varName is the name of a template variable.
- __getitem__(varName)¶
Returns the Value instance corresponding to varName or raises KeyError if there is no variable with that name.
- __setitem__(varName, value)¶
Sets the value of varName to the Value instance value.
The baseType and cardinality of value must match those expected for the variable.
This method does not actually update the dictionary with the value instance but instead, it copies the value of value into the Value instance already stored in the session. The side-effect of this implementation is that a previous look-up will be updated by a subsequent assignment:
# state is a SessionState instance state['RESPONSE']=IdentifierValue('Hello') r1=state['RESPONSE'] state['RESPONSE']=IdentifierValue('Bye') r2=state['RESPONSE'] r1==r2 # WARNING: r1 has been updated so still evaluates to True!
- __weakref__¶
list of weak references to the object (if defined)
- class pyslet.qtiv2.variables.ItemSessionState(item)¶
Bases: pyslet.qtiv2.variables.SessionState
Represents the state of an item session. item is the item from which the session should be created.
On construction, all declared variables (included built-in variables) are added to the session with NULL values, except the template variables which are set to their defaults.
In addition to the variables defined by the specification we add meta variables corresponding to response and outcome defaults, these have the same name as the variable but with ”.DEFAULT” appended. Similarly, we define names for the correct values of response variables using ”.CORRECT”. The values of these meta-variables are all initialised from the item definition on construction.
- SelectClone()¶
Item templates describe a range of possible items referred to as clones.
If the item used to create the session object is an item template then you must call SelectClone before beginning the candidate’s session with BeginSession().
The main purpose of this method is to run the template processing rules. These rules update the values of the template variables and may also alter correct responses and default outcome (or response) values.
- BeginSession()¶
Called at the start of an item session. According to the specification:
“The session starts when the associated item first becomes eligible for delivery to the candidate”The main purpose of this method is to set the outcome values to their defaults.
- BeginAttempt(htmlParent=None)¶
Called at the start of an attempt.
This method sets the default RESPONSE values and completionStatus if this is the first attempt and increments numAttempts accordingly.
- SaveSession(params, htmlParent=None)¶
Called when we wish to save unsubmitted values.
- SubmitSession(params, htmlParent=None)¶
Called when we wish to submit values (i.e., end an attempt).
- EndAttempt()¶
Called at the end of an attempt. Invokes response processing if present.
- IsResponse(varName)¶
Return True if varName is the name of a response variable.
We add handling of the built-in response variables numAttempts and duration.
- IsOutcome(varName)¶
Return True if varName is the name of an outcome variable.
We add handling of the built-in outcome variable completionStatus.
- class pyslet.qtiv2.variables.TestSessionState(form)¶
Bases: pyslet.qtiv2.variables.SessionState
Represents the state of a test session. The keys are the names of the variables including qualified names that can be used to look up the value of variables from the associated item session states. form is the test form from which the session should be created.
On construction, all declared variables (included built-in variables) are added to the session with NULL values.
- test = None¶
the tests.AssessmentTest that this session is an instance of
- t = None¶
the time of the last event
- salt = None¶
a random string of bytes used to add entropy to the session key
- key = None¶
A key representing this session in its current state, this key is initialised to a random value and changes as each event is received. The key must be supplied when triggering subsequent events. The key is designed to be unguessable and unique so a caller presenting the correct key when triggering an event can be securely assumed to be the owner of the existing session.
- prevKey = None¶
The key representing the previous state. This can be used to follow session state transitions back through a chain of states back to the beginning of the session (i.e., for auditing).
- keyMap = None¶
A mapping of keys previously used by this session. A caller presenting an expired key when triggering an event generates a SessionKeyExpired exception. This condition might indicate that a session response was not received (e.g., due to a connection failure) and that the session should be re-started with the previous response.
- GetCurrentTestPart()¶
Returns the current test part or None if the test is finished.
- GetCurrentQuestion()¶
Returns the current question or None if the test is finished.
- BeginSession(key, htmlParent=None)¶
Called at the start of a test session. Represents a ‘Start Test’ event.
The main purpose of this method is to set the outcome values to their defaults and to select the first question.
- GetNamespace(varName)¶
Takes a variable name varName and returns a tuple of namespace/varName.
The resulting namespace will be a dictionary or a dictionary-like object from which the value of the returned varName object can be looked up.
- IsResponse(varName)¶
Return True if varName is the name of a response variable. The test-level duration values are treated as built-in responses and return True.
- __len__()¶
Returns the total length of all namespaces combined.
- class pyslet.qtiv2.variables.Value¶
Bases: object
Represents a single value in the processing model.
This class is the heart of the QTI processing model. This is an abstract base class of a class hierarchy that represents the various types of value that may be encountered when processing.
- baseType = None¶
One of the BaseType constants or None if the baseType is unknown.
An unknown baseType acts like a wild-card. It means that the baseType is not determined and could potentially be any of the BaseType values. This distinction has implications for the way evaluation is done. A value with a baseType of None will not raise TypeErrors during evaluation if the cardinalities match the context. This allows expressions which contain types bound only at runtime to be evaluated for validity checking.
- value = None¶
The value of the variable. The following representations are used for values of single cardinality:
- NULL value
- Represented by None
- boolean
- One of the built-in Python values True and False
- directedPair
- A tuple of strings (<source identifier>, <destination identifier>)
- duration
- real number of seconds
- file
- a file like object (supporting seek)
- float
- real number
- identifier
- A text string
- integer
- A plain python integer (QTI does not support long integer values)
- pair
- A sorted tuple of strings (<identifier A>, <identifier B>). We sort the identifiers in a pair by python’s native string sorting to ensure that pair values are comparable.
- point
- A tuple of integers (<x-coordinate>, <y-coordinate>)
- string
- A python string
- uri
- An instance of URI
For containers, we use the following structures:
- ordered
- A list of one of the above value types.
- multiple:
- A dictionary with keys that are one of the above value types and values that indicate the frequency of that value in the container.
- record:
- A dictionary with keys that are the field identifiers and values that Value instances.
- SetValue(value)¶
Sets the value.
All single values can be set from a single text string corresponding to their XML schema defined lexical values (without character level escaping). If v is a single Value instance then the following always leaves v unchanged:
v.SetValue(unicode(v))
Value instances can also be set from values of the appropriate type as described in value. For base types that are represented with tuples we also accept and convert lists.
Containers values cannot be set from strings.
- ValueError(value)¶
Raises a ValueError with a debug-friendly message string.
- Cardinality()¶
Returns the cardinality of this value. One of the Cardinality constants.
By default we return None - indicating unknown cardinality. This can only be the case if the value is a NULL.
- IsNull()¶
Returns True is this value is NULL, as defined by the QTI specification.
- classmethod NewValue(cardinality, baseType=None)¶
Creates a new value instance with cardinality and baseType.
- classmethod CopyValue(value)¶
Creates a new value instance copying value.
- class pyslet.qtiv2.variables.SingleValue¶
Bases: pyslet.qtiv2.variables.Value
Represents all values with single cardinality.
- classmethod NewValue(baseType, value=None)¶
Creates a new instance of a single value with baseType and value
- class pyslet.qtiv2.variables.BooleanValue(value=None)¶
Bases: pyslet.qtiv2.variables.SingleValue
Represents single values of type BaseType.boolean.
- SetValue(value)¶
If value is a string it will be decoded according to the rules for representing boolean values. Booleans and integers can be used directly in the normal python way but other values will raise ValueError. To take advantage of a non-zero test you must explicitly force it to be a boolean. For example:
# x is a value of unknown type with non-zero test implemented v=BooleanValue() v.SetValue(True if x else False)
- class pyslet.qtiv2.variables.DirectedPairValue(value=None)¶
Bases: pyslet.qtiv2.variables.SingleValue
Represents single values of type BaseType.directedPair.
- SetValue(value, nameCheck=False)¶
See comment on Identifier.SetValue() for usage of nameCheck.
Note that if value is a string then nameCheck is ignored and identifier validation is always performed.
- class pyslet.qtiv2.variables.DurationValue(value=None)¶
Bases: pyslet.qtiv2.variables.FloatValue
Represents single value of type BaseType.duration.
- class pyslet.qtiv2.variables.FileValue¶
Bases: pyslet.qtiv2.variables.SingleValue
Represents single value of type BaseType.file.
- contentType = None¶
The content type of the file, a pyslet.rfc2616.HTTPMediaType instance.
- fileName = None¶
The file name to use for the file.
- SetValue(value, type='application/octet-stream', name='data.bin')¶
Sets a file value from a file like object or a string.
There are some important and subtle distinctions in this method.
If value is a Unicode text string then it is parsed according to the MIME-like format defined in the QTI specification. The values of type and name are only used as defaults if those values cannot be read from the value’s headers.
If value is a plain string then it is assumed to represent the file’s data directly, type and name are used to interpret the data. Other file type objects are set in the same way.
- class pyslet.qtiv2.variables.FloatValue(value=None)¶
Bases: pyslet.qtiv2.variables.SingleValue
Represents single value of type BaseType.float.
- SetValue(value)¶
This method will not convert integers to float values, you must do this explicitly if you want automatic conversion, for example
# x is a numeric value that may be float or integer v=FloatValue() v.SetValue(float(x))
- class pyslet.qtiv2.variables.IdentifierValue(value=None)¶
Bases: pyslet.qtiv2.variables.SingleValue
Represents single value of type BaseType.identifier.
- SetValue(value, nameCheck=True)¶
In general, to speed up computation we do not check the validity of identifiers unless parsing the value from a string representation (such as a value read from an XML input document).
As values of baseType identifier are represented natively as strings we cannot tell if this method is being called with an existing, name-checked value or a new value being parsed from an external source. To speed up computation you can suppress the name check in the first case by setting nameCheck to False (the default is True).
- class pyslet.qtiv2.variables.IntegerValue(value=None)¶
Bases: pyslet.qtiv2.variables.SingleValue
Represents single value of type BaseType.integer.
- SetValue(value)¶
Note that integers and floats are distinct types in QTI: we do not accept floats where we would expect integers or vice versa. However, integers are accepted from long or plain integer values provided they are within the ranges specified in the QTI specification: -2147483648...2147483647.
- class pyslet.qtiv2.variables.PairValue(value=None)¶
Bases: pyslet.qtiv2.variables.DirectedPairValue
Represents single values of type BaseType.pair.
- SetValue(value, nameCheck=True)¶
Overrides DirectedPair’s implementation to force a predictable ordering on the identifiers.
- class pyslet.qtiv2.variables.PointValue(value=None)¶
Bases: pyslet.qtiv2.variables.SingleValue
Represents single value of type BaseType.point.
- class pyslet.qtiv2.variables.StringValue(value=None)¶
Bases: pyslet.qtiv2.variables.SingleValue
Represents single value of type BaseType.string.
- class pyslet.qtiv2.variables.URIValue(value=None)¶
Bases: pyslet.qtiv2.variables.SingleValue
Represents single value of type BaseType.uri.
- SetValue(value)¶
Sets a uri value from a string or another URI instance.
- class pyslet.qtiv2.variables.Container(baseType=None)¶
Bases: pyslet.qtiv2.variables.Value
An abstract class for all container types.
By default containers are empty (and are treated as NULL values). You can force the type of an empty container by passing a baseType constant to the constructor. This will cause the container to generate TypeError if used in a context where the specified baseType is not allowed.
- GetValues()¶
Returns an iterable of the container’s values.
- classmethod NewValue(cardinality, baseType=None)¶
Creates a new container with cardinality and baseType.
- class pyslet.qtiv2.variables.OrderedContainer(baseType=None)¶
Bases: pyslet.qtiv2.variables.Container
Represents containers with ordered Cardinality.
- SetValue(value, baseType=None)¶
Sets the value of this container from a list, tuple or other iterable. The list must contain valid representations of baseType, items may be None indicating a NULL value in the list. In accordance with the specification’s multiple operator NULL values are ignored.
If the input list of values empty, or contains only NULL values then the resulting container is empty.
If baseType is None the base type specified when the container was constructed is assumed.
- GetValues()¶
Returns an iterable of values in the ordered container.
- class pyslet.qtiv2.variables.MultipleContainer(baseType=None)¶
Bases: pyslet.qtiv2.variables.Container
Represents containers with multiple Cardinality.
- SetValue(value, baseType=None)¶
Sets the value of this container from a list, tuple or other iterable. The list must contain valid representations of baseType, items may be None indicating a NULL value in the list. In accordance with the specification’s multiple operator NULL values are ignored.
If the input list of values is empty, or contains only NULL values then the resulting container is empty.
If baseType is None the base type specified when the container was constructed is assumed.
- GetValues()¶
Returns an iterable of values in the ordered container.
- class pyslet.qtiv2.variables.RecordContainer¶
Bases: pyslet.qtiv2.variables.Container
Represents containers with record Cardinality.
- SetValue(value)¶
Sets the value of this container from an existing dictionary in which the keys are the field identifiers and the values are Value instances. You cannot parse containers from strings.
Records are always treated as having a wild-card base type.
If the input value contains any keys which map to None or to a NULL value then these fields are omitted from the resulting value.
- __getitem__(fieldIdentifier)¶
Returns the Value instance corresponding to fieldIdentifier or raises KeyError if there is no field with that name.
- __setitem__(fieldIdentifier, value)¶
Sets the value in the named field to value.
We add some special behaviour here. If value is None or is a NULL value then we remove the field with the give name. In other words:
r=RecordContainer() r['pi']=FloatValue(3.14) r['pi']=FloatValue() # a NULL value print r['pi'] # raises KeyError