# - - - W r p F i e l d . _ c h e c k
@staticmethod
def _check(encounter, scan, rawCode, fieldName):
'''Validate a WRP code.
[ (encounter is a BaseEncounter instance) and
(scan is a logscan.Scan instance) and
(rawCode is a str of length WRP_L) and
(fieldName is a valid Python name) ->
if rawCode is a valid WRP code ->
encounter.(fieldName) := rawCode
else ->
Log() +:= error message
raise SyntaxError ]
'''
A completely blank field is valid. Otherwise, the first
character must be in WRP_CYCLE; the second
must be in WRP_QUAL; and the third must be
in WRP_PLUM. For these definitions, see
Section 5.2, “Constants related to encounter records”.
#-- 1
# [ if (rawCode != ' ') and
# (rawCode is not a valid WRP code) ->
# Log() +:= error message
# raise SyntaxError
# else -> I ]
if rawCode.strip() != '':
cycle, qual, plum = rawCode
if cycle not in WRP_CYCLE:
scan.syntax("WRP code '{0}': first character must be "
"one of '{1}'".format(cycle, WRP_CYCLE))
if qual not in WRP_QUAL:
scan.syntax("WRP code '{0}': second character must be "
"one of '{1}'".format(qual, WRP_QUAL))
if plum not in WRP_PLUM:
scan.syntax("WRP code '{0}': third character must be "
"one of '{1}'".format(plum, WRP_PLUM))
#-- 2
# [ encounter.(fieldName) := rawCode ]
setattr(encounter, fieldName, rawCode)