Next / Previous / Contents / Shipman's homepage

77.2. Maws2007Encounter.scanBody(): Scan encounter line body and tail sections

The MAWS 2007 protocol uses a four-character net field instead of the standard two-character field. Because the net field is scanned in BaseEncounter.scanBody(), we need to override that method with a variant here that uses Section 68, “class Net4Field: Four-character net code”. In every other respect it is identical to the parent method.

baseclasses.py
# - - -   M a w s 2 0 0 7 E n c o u n t e r . s c a n B o d y   - - -

    def scanBody(self, scan):
        '''Scan encounter record body and tail.

          [ scan is a Scan object ->
              if scan contains a valid encounter body and tail in
              the context of self ->
                scan  :=  scan advanced to end of line
                self  :=  self with all fields from that line added
              else ->
                Log()  +:=  error message(s)
                raise SyntaxError ]
        '''

        #-- 1 --
        # [ if the line in scan starts with a sequence of valid
        #   fields as described by self.BODY_FIELD_LIST ->
        #     scan  :=  scan advanced past those fields
        #     self  :=  self with values of those fields stored by
        #               the attribute names in self.BODY_FIELD_LIST
        #   else ->
        #     scan   :=   scan advanced no further than end of line
        #     Log()  +:=  error message(s)
        #     raise SyntaxError ]
        scanFieldItems(self, self.BODY_FIELD_LIST, scan)

        #-- 2 --
        # [ if (self.compiler is a multi-station set) and
        #   (line in scan starts with a valid station code in
        #   the context of self.compiler) ->
        #     scan  :=  scan advanced past that field
        #     self.(STATION_ATTR)  :=  a StationCodeField containing
        #                              that field
        #   else if (self.compiler is a multi-station set) and
        #   (line in scan does not start with a valid station code in
        #   the context of self.compiler) ->
        #     scan   :=   scan advanced no further than end of line
        #     Log()  +:=  error message(s)
        #     raise SyntaxError
        #   else ->
        #     self.(STATION_ATTR)  :=  a StationCodeField containing
        #         self.compiler.station.staCode ]
        if  self.compiler.location is not None:
            #-- 2.1 --
            # [ if line in scan starts with a valid station code in
            #   the context of self.compiler ->
            #     scan  :=  scan advanced past that field
            #     self.(STATION_ATTR)  :=  a Station object representing
            #         that field
            #   else ->
            #     scan   :=   scan advanced no further than end of line
            #     Log()  +:=  error message(s)
            #     raise SyntaxError ]
            StationCodeField.scanField(self, scan, STATION_ATTR)
        else:
            setattr(self, STATION_ATTR,
                    StationCodeField(self,
                                     self.compiler.station.staCode))

Here is the only part of this method that differs from the parent method. See Section 68.1, “Net4Field.scanField().

baseclasses.py
        #-- 3 --
        # [ if scan starts with a valid 4-character net field ->
        #     scan  :=  scan advanced past that field
        #     self.(NET_ATTR)  :=  that field
        #   else ->
        #     scan   :=   scan advanced no further than end of line
        #     Log()  +:=  error message(s)
        #     raise SyntaxError ]
        Net4Field.scanField(self, scan, NET_ATTR)

The rest is the same as the parent method.

baseclasses.py
        #-- 4 --
        # [ if scan starts with an alignment check character ->
        #     scan  :=  scan advanced past that character
        #   else ->
        #     Log()  +:=  error message(s)
        #     raise SyntaxError ]
        m = scan.tabMatch(ALIGNMENT_CHAR)
        if  m is None:
            scan.syntax("Expecting the alignment character, '%s'." %
                         ALIGNMENT_CHAR)
        #-- 5 --
        # [ if the line in scan starts with a valid tail section ->
        #     scan  :=  scan advanced to end of line
        #     self  :=  self with values from the tail stored using
        #               attribute names from self.OUT_FIELD_LIST
        #   else ->
        #     scan   :=   scan advanced no further than end of line
        #     Log()  +:=  error message(s)
        #     raise SyntaxError ]
        self.scanTail(scan)