Next / Previous / Contents / Shipman's homepage

11.16. BirdId.scanAbbrFlat()

This scans a “flat file” bird code, consisting of a bird code right-padded with spaces to length ABBR_L.

abbr.py
# - - -   B i r d I d . s c a n A b b r F l a t   - - -

    def scanAbbrFlat ( txny, scan ):
        """Scan a bird code from a flat file record.
        """

        #-- 1 --
        # [ if scan starts with a bird code valid in txny ->
        #     scan  :=  scan advanced past that code
        #     abbr  :=  that code
        #   else ->
        #     scan  :=   scan advanced valid-looking parts, if any
        #     scan  +:=  error message
        #     raise ValueError ]
        abbr = BirdId.scanAbbr ( txny, scan )

        #-- 2 --
        # [ if (len(abbr) == ABBR_L) ->
        #     return abbr
        #   else ->
        #     pad  :=  a string of (ABBR_L - len(abbr)) spaces ]
        if  len(abbr) == ABBR_L:
            return abbr
        else:
            pad = " " * (ABBR_L - len(abbr))

        #-- 3 --
        # [ if scan starts with pad ->
        #     return abbr
        #   else ->
        #     scan  +:=  error message
        #     raise ValueError ]
        matcher = scan.tabMatch ( pad )
        if  matcher is None:
            message = ( "Expecting a pad of %d spaces after "
                          "a bird code." % len(pad) )
            scan.error ( message )
            raise ValueError, message
        else:
            return abbr

    scanAbbrFlat = staticmethod ( scanAbbrFlat)