This class is used to parse the six-letter species code (e.g.,
"FALPER" for Falco
peregrinus) used in MAWS sets. It is similar to
Section 34, “class Spec4Field: Four-letter species
code”, so comments are shown here
mainly for the differences. See the specification.
# - - - - - c l a s s S p e c 6 F i e l d - - - - -
class Spec6Field(FieldItem):
'''Represents a 6-letter species field.
Exports, other than those inherited:
Spec6Field.scanField(encounter, scan, fieldName): # Static
[ (encounter is a BaseEncounter object) and
(scan is a Scan object) and
(fieldName is a field name in self.OUT_FIELD_LIST) ->
if scan starts with a valid 6-letter species code in
the context of encounter ->
scan := scan advanced past that field
encounter.(fieldName) := a Species object representing
that field
else ->
scan := scan advanced no further than end of line
Log() +:= error message(s)
raise SyntaxError ]
Spec6Field.flatten(): [ as in base class ]
'''
This method scans a 6-letter MAWS species code.
# - - - S p e c 6 F i e l d . s c a n F i e l d - - -
@staticmethod
def scanField(encounter, scan, fieldName):
'''Scan a 6-letter species code.
'''
#-- 1 --
# [ if the line in scan has at least SPEC6_L characters ->
# scan := scan advanced SPEC6_L
# rawCode := those characters, uppercased
# else ->
# Log() +:= error message
# raise SyntaxError ]
try:
rawCode = scan.move(SPEC6_L).upper()
except IndexError:
scan.syntax("Expecting a %d-character species code." %
SPEC6_L)
Next we check the code for validity. IBP has
specifically requested that invalid codes be preserved in
the record, so we issue a warning instead of an error.
See Section 13.2, “BaseSpeciesSet.lookupSpec6()”.
#-- 2 --
# [ if rawCode is not a 4-letter code defined in
# encounter.compiler.speciesSet ->
# Log() +:= warning message
# else -> I ]
try:
species = encounter.compiler.speciesSet.lookupSpec6 (
rawCode)
except KeyError:
scan.warning("Species code '%s' is undefined." %
rawCode)
#-- 3 --
setattr(encounter, SPEC6_ATTR,
Spec6Field(encounter, rawCode))