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