This method looks at self.fileName to see if it
starts with a station code.
# - - - B a s e C o m p i l e r . c h e c k F o r S t a t i o n
def checkForStation(self):
'''See if self.fileName starts with a valid station code.
[ if (self.fileName starts with STA_NO_PAT) and
(the matching part is a station code defined in
self.stationSet) ->
self.station := the Station from self.stationSet
with that station code
return self.fileName past the matching part
else if (self.fileName starts with STA_NO_PAT) and
(the matching part is not a station code defined in
self.stationSet) ->
Log() +:= error message(s)
raise ValueError
else -> return None ]
'''
We use the precompiled regular expression STA_NO_PAT to see if the start of self.fileName looks like a station code.
#-- 1 --
# [ if self.fileName starts with STA_NO_PAT ->
# staNo := the part that matches
# rest := the part after the match
# else ->
# return None ]
m = STA_NO_PAT.match(self.fileName)
if m is None:
return None
else:
staNo = m.group()
rest = self.fileName[m.end():]
Next we look up staNo in the stations
authority object. See Section 8.2, “BaseStationSet.stationNoLookup()”.
#-- 2 --
# [ if staNo is a station code defined in
# self.stationSet ->
# self.station := the Station object with that code
# else ->
# Log() +:= error message
# raise ValueError ]
try:
self.station = self.stationSet.stationNoLookup(staNo)
except KeyError:
message = "No such station code: '%s'" % staNo
Log().error(message)
raise ValueError, message
#-- 3 --
return rest