Next / Previous / Contents / Shipman's homepage

67. class Net2Field: Two-character net code

This class represents a two-character net field. See the specification.

Because the capacity of the actual field is four, and because some banders may use three- or four-character net fields, other classes for this field may be created for those cases.

baseclasses.py
# - - - - -   c l a s s   N e t 2 F i e l d   - - - - -

class Net2Field(FieldItem):
    '''Represents a two-character net field.

      Exports: as inherited.
    '''

67.1. Net2Field.scanField()

Scans a two-character net field.

baseclasses.py
# - - -   N e t 2 F i e l d . s c a n F i e l d   - - -

    @staticmethod
    def scanField(encounter, scan, fieldName):
        '''Scan a two-character net field.
        '''
        #-- 1 --
        # [ if the line in scan contains at least NET2_L characters ->
        #     scan  :=  scan advanced NET2_L
        #     text  :=  next NET2_L characters from scan, uppercased
        #   else ->
        #     Log()  +:=  error message
        #     raise SyntaxError ]
        try:
            text = scan.move(NET2_L).upper()
        except IndexError:
            scan.syntax("Expecting a %d-character net field." %
                        NET2_L)

        #-- 2 --
        setattr(encounter, NET_ATTR,
                Net2Field(encounter, text))