Next / Previous / Contents / Shipman's homepage

11. class MapsStationSet: Station set object

This class represents the station codes authority file. For the format of this file, see the specification.

It is a derived class: for the base class, see Section 8, “class BaseStationSet: Base class for station authority objects”.

baseclasses.py
# - - - - -   c l a s s   M a p s S t a t i o n S e t   - - - - -

class MapsStationSet(BaseStationSet):
    '''Represents the MAPS station codes authority file.

      Exports:
        AUTHORITY_FILE:   [ name of the MAPS stations authority file ]
        MapsStationSet():
          [ if AUTHORITY_FILE names a readable, valid flat file
            made from a station authority .dbf file ->
                return a new BaseStationSet object representing
                that file
              else -> raise IOError ]
        .readLine(scan):
          [ scan is a Scan object ->
              if the line in scan is not a valid station line ->
                scan  :=  scan advanced not beyond end of line
                raise IOError
              else if the line in scan contains a location code
              not in self.locCodeMap ->
                scan  :=  scan advanced to end of line
                self.locCodeMap  +:=  a new entry whose key is
                    that location code, uppercase, and whose
                    value is a new Location containing the
                    station from that line
              else if the line in scan contains a location code
              that is in self.locCodeMap ->
                scan  :=  scan advanced to end of line
                corresponding value  +:=  the station from
                    that line ]

    '''

This constant defines the name of the authority file.

baseclasses.py
    AUTHORITY_FILE = "stations.txt"

These constants define the lengths of the fields in the authority file; the “_L” suffix connotes a field length. They are given in the same order as the occurrence of the fields.

baseclasses.py
#--
# Field lengths in the authority file.
#--
    REGION_L     = 1        # Region code
    STA_NO_L     = 5        # Station number
    LOC_CODE_L   = 4        # Location code
    STA_NAME_L   = 30       # Station name
    STA_CODE_L   = 4        # Station code (alphabetic)
    STATE_L      = 2        # State code

This class has a class variable FIELD_LIST that defines the format of the authority file. The scanFieldList() utility function handles scanning of a sequence of fixed-size fields; see Section 6, “scanFieldList(): A utility routine for flat-file scanning”.

baseclasses.py
    FIELD_LIST = [
       ("region",         REGION_L),
       ("station number", STA_NO_L),
       ("location code",  LOC_CODE_L),
       ("station name",   STA_NAME_L),
       ("station code",   STA_CODE_L),
       ("state code",     STATE_L) ]

11.1. MapsStationSet.__init__()

The constructor supplies the name of the authority file to the parent constructor; see Section 8.3, “BaseStationSet.__init__(): Constructor”.

baseclasses.py
# - - -   M a p s S t a t i o n S e t . _ _ i n i t _ _   - - -

    def __init__(self):
        '''Constructor for MapsStationSet.
        '''
        BaseStationSet.__init__(self, self.AUTHORITY_FILE)