Next / Previous / Contents / Shipman's homepage

32.4. BandNoField.scanField()

Required as part of the FieldItem interface, this method attempts to pass a full-length band number from a Scan object. The BAND_NO_PAT class attribute is a precompiled regular expression that matches a band number: nine characters, any combination of digits, spaces, question marks, or letters (because for example a hummer band might look like " T34075").

baseclasses.py
# - - -   B a n d N o F i e l d . s c a n F i e l d   - - -   Static

    BAND_NO_PAT = re.compile(r'[0-9a-zA-Z? ]{9}')

    @staticmethod
    def scanField(encounter, scan, fieldName):
        '''Parse a full band number.
        '''
        
        #-- 1 --
        # [ if scan starts with self.BAND_NO_PAT ->
        #     scan  :=  scan advanced past that match
        #     s     :=  matching characters, uppercased
        #   else ->
        #     scan   :=   scan advanced no further than end of line
        #     Log()  +:=  error message
        #     raise SyntaxError ]
        m = scan.tabReMatch(BandNoField.BAND_NO_PAT)
        if  m is None:
            scan.syntax("Expecting a %d-digit band number." %
                          L_BAND_NO)
        else:
            s = m.group().upper()
            
        #-- 2 --
        # [ encounter.(fieldName)  :=  a new BandNoField object
        #                              with value s ]
        setattr(encounter, fieldName,
                BandNoField(encounter, s))