Next / Previous / Contents / Shipman's homepage

8. class BaseStationSet: Base class for station authority objects

This abstract class describes the standard interface for looking up location and station codes.
# - - - - -   c l a s s   B a s e S t a t i o n S e t   - - - - -

class BaseStationSet:
    '''Abstract class for location and station authority file objects.

          [ fileName is a string ->
              if fileName names a readable, valid flat file
              made from a station authority .dbf file ->
                return a new BaseStationSet object representing
                that file
              else -> raise IOError ]
          [ locCode is a string ->
              if locCode matches a location code in self (case
              insensitive) ->
               return the corresponding Location object
              else -> raise KeyError ]
          [ staNo is a string ->
              if staNo matches a station code in self ->
                return the corresponding Station object
              else -> raise KeyError ]

The only reason we use an abstract class is that there are multiple different station authority files. The Location and Station objects are, so far, the same for MAPS and MAWS. See Section 9, “class Location: Represents a group of stations” and Section 10, “class Station: Represents one station”.

The data structures we need to look up location codes and station numbers can live in the base class because they aren't dependent on the input file format. Here they are:
          [ a dictionary whose keys are the uppercased location
            codes in self, and each corresponding value is the
            Location object that has that code ]
          [ a dictionary whose keys are the station numbers in
            self, and each corresponding value is the Station
            object that has that station number ]

8.1. BaseStationSet.locationLookup()

Finds a location code, or raises KeyError.
# - - -   B a s e S t a t i o n S e t . l o c a t i o n L o o k u p   - - -

    def locationLookup(self, locCode):
        '''Look up a location code.
        return self.locCodeMap[locCode.upper()]