This field represents the approximate capture time, as
HHMM with the units digit of the minutes
dropped. For its format, see the specification.
# - - - - - c l a s s H H M F i e l d - - - - -
class HHMField(FieldItem):
'''Represents a ten-minute slice of time.
Exports, other than those inherited:
HHMField(encounter, hhm):
[ hhm is a time with the minutes units digit dropped, as
a string ->
return a new HHMField representing that time ]
.encounter: [ as passed to constructor, read-only ]
.hhm: [ as passed to constructor, read-only ]
'''
Scans a time field. The field may be left blank, in which
case we take no action, so that the BaseEncounter object's time attribute remains None. The class attribute HHM_PAT is
a compiled regular expression that matches a valid time field.
# - - - H H M F i e l d . s c a n F i e l d - - -
HHM_PAT = re.compile (
r'[012]' # First digit of hour
r'[0-9]' # Second digit of hour
r'[0-5]') # First digit of minutes
@staticmethod
def scanField(encounter, scan, fieldName):
'''Scan a time field in HHM format.
'''
#-- 1 --
# [ if the line in scan starts with BLANK_HHM ->
# scan := scan advanced past that pattern
# return
# else -> I ]
rawHHM = scan.tabMatch(BLANK_HHM)
if rawHHM is not None:
return
As we test the field for validity, we don't need to
test that the H part is valid. The regular
expression handles that—it can be only a single digit
from 0 through 6 inclusive.
#-- 2 --
# [ if the line in scan starts with a pattern that matches
# self.HHM_PAT ->
# scan := scan advanced past that pattern
# rawHHM := the matching pattern
# else ->
# Log() +:= error message
# raise SyntaxError ]
m = scan.tabReMatch(HHMField.HHM_PAT)
if m is None:
scan.syntax("Time is not valid.")
else:
rawHHM = m.group()
hh = rawHHM[:2]
if not(0 <= int(hh) <= 23):
scan.syntax("Hour '%s' is not valid." % hh)
#-- 3 --
# [ encounter.(fieldName) := a new HHMField object with
# value rawHHM ]
setattr(encounter, fieldName,
HHMField(encounter, rawHHM))