Next / Previous / Contents / Shipman's homepage

60. class WingField: Wing length

Represents a wing length field. The value is optional, and single-column ditto is not supported. For the input format, see the specification.

baseclasses.py
# - - - - -   c l a s s   W i n g F i e l d   - - - - -

class WingField(FieldItem):
    '''Represents a wing length in millimeters.

      Exports, other than those inherited:
        .wing:   [ wing length in millimeters ]
    '''

60.1. WingField.scanField(): Scan a wing length field

We gather in the field to variable rawField first; if all those characters are blank, we do nothing, so that the containing encounter field will have a value of None, and be flattened as a string of spaces.

baseclasses.py
# - - -   W i n g F i e l d . s c a n F i e l d   - - -

    @staticmethod
    def scanField(encounter, scan, fieldName):
        '''Scan a wing-length field.
        '''

        #-- 1 --
        # [ if the line in scan starts with WING_L characters ->
        #     scan  :=  scan advanced by WING_L
        #     rawText  :=  next WING_L characters from scan
        #   else ->
        #     Log()  +:=  error message
        #     raise SyntaxError ]
        try:
            rawText = scan.move(WING_L)
        except IndexError:
            scan.syntax("Expecting a %d-digit wing field." % WING_L)

        #-- 2 --
        # [ if rawText is all blank ->
        #     return
        #   else if rawText is a valid integer ->
        #     encounter.(fieldName)  :=  that integer
        #   else ->
        #     Log()  +:=  error message
        #     raise SyntaxError ]
        if  len(rawText.strip()) == 0:
            return
        else:
            try:
                wing = int(rawText)
            except ValueError:
                scan.syntax("Wing field '%s' is not a proper "
                    "integer." % rawText)

        #-- 3 --
        # [ encounter.(fieldName)  :=  wing ]
        setattr(encounter, fieldName,
                WingField(encounter, wing))