The status code is a single-character field on input, but it is expanded to a three-digit version on output. See the specification for this field.
# - - - - - c l a s s S t a t u s F i e l d - - - - -
class StatusField(FieldItem):
'''Represents a bird's release status.
Exports, beyond those inherited:
.status: [ the BBL three-digit status as a string ]
'''
The class attribute STATUS_MAP is a dictionary
whose keys are the valid status codes as input, and each
corresponding value is the output status code.
# - - - S t a t u s F i e l d . s c a n F i e l d - - -
STATUS_MAP = {
"0": "000",
"3": "300",
"1": "301",
"2": "325",
"5": "500",
"6": "501",
"7": "700",
"8": "318",
"9": "518" }
@staticmethod
def scanField(encounter, scan, fieldName):
'''Scan a release-status field.
'''
#-- 1 --
# [ if the line in scan has at least one character ->
# scan := scan advanced 1
# code := next character from scan, uppercased
# else ->
# Log() +:= error message
# raise SyntaxError ]
try:
code = scan.move(1).upper()
except IndexError:
scan.syntax("Expecting a 1-character status code.")
#-- 2 --
# [ if code is a key in self.STATUS_MAP ->
# status := the corresponding value
# else ->
# Log() +:= error message
# raise SyntaxError ]
try:
status = StatusField.STATUS_MAP [ code ]
except KeyError:
scan.syntax("Status code '%s' is not valid." % code)
#-- 3 --
# [ encounter.(fieldName) := a new StatusField item with
# value (status) ]
setattr(encounter, fieldName,
StatusField(encounter, status))