3.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 get_default_value() 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,pyslet.py2.SortableMixinItem 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>
-
get_default_value()¶ Returns a
Valueinstance representing either the default value or an appropriately typed NULL value if there is no default defined.
-
GetDefaultValue(*args, **kwargs)¶ Deprecated equivalent to
get_default_value()
-
-
class
pyslet.qtiv2.variables.ValueElement(parent)¶ Bases:
pyslet.qtiv2.core.QTIElementA 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.DefinedValueAn 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.xml.xsdatatypes.EnumerationAn 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.xml.xsdatatypes.EnumerationNoCaseA 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.QTIElementA 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>
-
content_changed()¶ 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.
-
map_value(value)¶ Maps an instance of
Valuewith the same base type as the mapping to an instance ofValuewith base type float.
-
MapValue(*args, **kwargs)¶ Deprecated equivalent to
map_value()
-
-
class
pyslet.qtiv2.variables.MapEntry(parent)¶ Bases:
pyslet.qtiv2.core.QTIElementAn 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
-
3.3.5.1. Response Variables¶
-
class
pyslet.qtiv2.variables.ResponseDeclaration(parent)¶ Bases:
pyslet.qtiv2.variables.VariableDeclarationResponse 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>
-
get_correct_value()¶ Returns a
Valueinstance representing either the correct response value or an appropriately typed NULL value if there is no correct value.
-
get_stage_dimensions()¶ 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.DefinedValueA 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.QTIElementA 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>
-
map_value(value, width, height)¶ Maps a point onto a float.
Returns an instance of
Valuewith base type float.- value is a
Valueof 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.
- value is a
-
MapValue(*args, **kwargs)¶ Deprecated equivalent to
map_value()
-
-
class
pyslet.qtiv2.variables.AreaMapEntry(parent)¶ Bases:
pyslet.qtiv2.core.QTIElement,pyslet.qtiv2.core.ShapeElementMixinAn
AreaMappingis 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
-
3.3.5.2. Outcome Variables¶
-
class
pyslet.qtiv2.variables.OutcomeDeclaration(parent)¶ Bases:
pyslet.qtiv2.variables.VariableDeclarationOutcome 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.QTIElementAn 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.LookupTableA 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>
-
content_changed()¶ 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.LookupTableAn 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>
-
content_changed()¶ 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>
3.3.5.3. Template Variables¶
-
class
pyslet.qtiv2.variables.TemplateDeclaration(parent)¶ Bases:
pyslet.qtiv2.variables.VariableDeclarationTemplate 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>
3.3.5.4. Runtime Object Model¶
-
class
pyslet.qtiv2.variables.SessionState¶ Bases:
pyslet.pep8.MigratedClassAbstract 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.-
get_declaration(var_name)¶ Returns the declaration associated with var_name or None if the variable is one of the built-in variables. If var_name 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!")
-
is_response(var_name)¶ Return True if var_name is the name of a response variable.
-
is_outcome(var_name)¶ Return True if var_name is the name of an outcome variable.
-
is_template(var_name)¶ Return True if var_name is the name of a template variable.
-
__getitem__(var_name)¶ Returns the
Valueinstance corresponding to var_name or raises KeyError if there is no variable with that name.
-
__setitem__(var_name, value)¶ Sets the value of var_name to the
Valueinstance 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
Valueinstance 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!
-
GetDeclaration(*args, **kwargs)¶ Deprecated equivalent to
get_declaration()
-
IsOutcome(*args, **kwargs)¶ Deprecated equivalent to
is_outcome()
-
IsResponse(*args, **kwargs)¶ Deprecated equivalent to
is_response()
-
IsTemplate(*args, **kwargs)¶ Deprecated equivalent to
is_template()
-
-
class
pyslet.qtiv2.variables.ItemSessionState(item)¶ Bases:
pyslet.qtiv2.variables.SessionStateRepresents 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.
-
select_clone()¶ 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 select_clone before beginning the candidate’s session with
begin_session().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.
-
begin_session()¶ 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.
-
begin_attempt(html_parent=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.
-
save_session(params, html_parent=None)¶ Called when we wish to save unsubmitted values.
-
submit_session(params, html_parent=None)¶ Called when we wish to submit values (i.e., end an attempt).
-
end_attempt()¶ Called at the end of an attempt. Invokes response processing if present.
-
is_response(var_name)¶ Return True if var_name is the name of a response variable.
We add handling of the built-in response variables numAttempts and duration.
-
is_outcome(var_name)¶ Return True if var_name 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.SessionStateRepresents 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.AssessmentTestthat this session is an
-
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
SessionKeyExpiredexception. 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.
-
get_current_test_part()¶ Returns the current test part or None if the test is finished.
-
get_current_question()¶ Returns the current question or None if the test is finished.
-
begin_session(key, html_parent=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.
-
get_namespace(var_name)¶ Returns a tuple of namespace/var_name from variable name
The resulting namespace will be a dictionary or a dictionary-like object from which the value of the returned var_name object can be looked up.
-
is_response(var_name)¶ Return True if var_name 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:
pyslet.pep8.MigratedClass,pyslet.py2.BoolMixinRepresents 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
BaseTypeconstants 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
BaseTypevalues. 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.
-
set_value(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.set_value(unicode(v)) # str() in Python 3
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.
-
value_error(value)¶ Raises a ValueError with a debug-friendly message string.
-
cardinality()¶ Returns the cardinality of this value. One of the
Cardinalityconstants.By default we return None - indicating unknown cardinality. This can only be the case if the value is a NULL.
-
is_null()¶ Returns True is this value is NULL, as defined by the QTI specification.
-
classmethod
new_value(cardinality, base_type=None)¶ Creates a new value instance with cardinality and base_type.
-
classmethod
copy_value(value)¶ Creates a new value instance copying value.
-
Cardinality(*args, **kwargs)¶ Deprecated equivalent to
cardinality()
-
classmethod
CopyValue(*args, **kwargs)¶ Deprecated equivalent to
copy_value()
-
classmethod
NewValue(*args, **kwargs)¶ Deprecated equivalent to
new_value()
-
ValueError(*args, **kwargs)¶ Deprecated equivalent to
value_error()
-
-
class
pyslet.qtiv2.variables.SingleValue¶ Bases:
pyslet.qtiv2.variables.ValueRepresents all values with single cardinality.
-
classmethod
new_value(base_type, value=None)¶ Creates a new instance of a single value with base_type and value
-
classmethod
-
class
pyslet.qtiv2.variables.BooleanValue(value=None)¶ Bases:
pyslet.qtiv2.variables.SingleValueRepresents single values of type
BaseType.boolean.-
set_value(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.set_value(True if x else False)
-
-
class
pyslet.qtiv2.variables.DirectedPairValue(value=None)¶ Bases:
pyslet.qtiv2.variables.SingleValueRepresents single values of type
BaseType.directedPair.-
set_value(value, name_check=False)¶ See
Identifier.SetValue()for usage of name_check.Note that if value is a string then name_check is ignored and identifier validation is always performed.
-
-
class
pyslet.qtiv2.variables.DurationValue(value=None)¶ Bases:
pyslet.qtiv2.variables.FloatValueRepresents single value of type
BaseType.duration.
-
class
pyslet.qtiv2.variables.FileValue¶ Bases:
pyslet.qtiv2.variables.SingleValueRepresents single value of type
BaseType.file.-
contentType= None¶ The content type of the file, a
pyslet.http.params.MediaTypeinstance.
-
file_name= None¶ The file name to use for the file.
-
set_value(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.SingleValueRepresents single value of type
BaseType.float.-
set_value(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.set_value(float(x))
-
-
class
pyslet.qtiv2.variables.IdentifierValue(value=None)¶ Bases:
pyslet.qtiv2.variables.SingleValueRepresents single value of type
BaseType.identifier.-
set_value(value, name_check=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 name_check to False (the default is True).
-
-
class
pyslet.qtiv2.variables.IntegerValue(value=None)¶ Bases:
pyslet.qtiv2.variables.SingleValueRepresents single value of type
BaseType.integer.-
set_value(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.DirectedPairValueRepresents single values of type
BaseType.pair.-
set_value(value, name_check=True)¶ Overrides DirectedPair’s implementation to force a predictable ordering on the identifiers.
-
-
class
pyslet.qtiv2.variables.PointValue(value=None)¶ Bases:
pyslet.qtiv2.variables.SingleValueRepresents single value of type
BaseType.point.
-
class
pyslet.qtiv2.variables.StringValue(value=None)¶ Bases:
pyslet.qtiv2.variables.SingleValueRepresents single value of type
BaseType.string.
-
class
pyslet.qtiv2.variables.URIValue(value=None)¶ Bases:
pyslet.qtiv2.variables.SingleValueRepresents single value of type
BaseType.uri.-
set_value(value)¶ Sets a uri value from a string or another URI instance.
-
-
class
pyslet.qtiv2.variables.Container(base_type=None)¶ Bases:
pyslet.qtiv2.variables.ValueAn 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.
-
get_values()¶ Returns an iterable of the container’s values.
-
classmethod
new_value(cardinality, base_type=None)¶ Creates a new container with cardinality and base_type.
-
-
class
pyslet.qtiv2.variables.OrderedContainer(base_type=None)¶ Bases:
pyslet.qtiv2.variables.ContainerRepresents containers with ordered
Cardinality.-
set_value(value, base_type=None)¶ Sets the value of this container from a list, tuple or other iterable. The list must contain valid representations of base_type, 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 base_type is None the base type specified when the container was constructed is assumed.
-
get_values()¶ Returns an iterable of values in the ordered container.
-
-
class
pyslet.qtiv2.variables.MultipleContainer(base_type=None)¶ Bases:
pyslet.qtiv2.variables.ContainerRepresents containers with multiple
Cardinality.-
set_value(value, base_type=None)¶ Sets the value of this container from a list, tuple or other iterable. The list must contain valid representations of base_type, 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 base_type is None the base type specified when the container was constructed is assumed.
-
get_values()¶ Returns an iterable of values in the ordered container.
-
-
class
pyslet.qtiv2.variables.RecordContainer¶ Bases:
pyslet.qtiv2.variables.ContainerRepresents containers with record
Cardinality.-
set_value(value)¶ Sets the value of this container from an existing dictionary in which the keys are the field identifiers and the values are
Valueinstances. 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__(field_identifier)¶ Returns the
Valueinstance corresponding to field_identifier or raises KeyError if there is no field with that name.
-
__setitem__(field_identifier, 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 r['pi'] # raises KeyError
-