Next / Previous / Contents / Shipman's homepage

20.3. InputFile.__readFile(): Slice up the input lines

listext2
# - - -    I n p u t F i l e . _ _ r e a d F i l e

    def __readFile(self, inFile):
        '''Read all input and break long lines.

          [ inFile is a readable file ->
              self.__blockList  +:=  OutBlock instances representing
                  the lines from inFile with tabs expanded, with each
                  line represented as a FirstBlock
                  followed by zero or more OverflowBlock
                  instances ]
        '''

We read the lines by iterating over them with a for statement, which breaks them on newline characters. The author's testing established that no special mode is necessary when reading the lines: this method will read a string containing every one of the 256 ASCII characters and they arrive intact. (Here is a test file named all-ascii containing all 256 ASCII characters.)

Each line is handled by Section 20.4, “InputFile.__readLine(): Process one input line”.

listext2
        #-- 1
        for rawLine in inFile:
            #-- 1 body
            # [ self.__blockList  +:=  OutBlock instances representing
            #       rawLine with tabs expanded, with each line
            #       represented as a FirstBlock
            #       followed by zero or more OverflowBlock
            #       instances ]
            self.__readLine(rawLine)