Lines Matching +full:file +full:- +full:lines
5 lines, and joining lines with backslashes."""
14 """Provides a file-like object that takes care of all the things you
15 commonly want to do when processing a text file that has some
16 line-by-line syntax: strip comments (as long as "#" is your
17 comment character), skip blank lines, join adjacent lines by
24 spans multiple physical lines. Also provides 'unreadline()' for
25 implementing line-at-a-time lookahead.
29 TextFile (filename=None, file=None, **options)
31 It bombs (RuntimeError) if both 'filename' and 'file' are None;
32 'filename' should be a string, and 'file' a file object (or
35 can include it in warning messages. If 'file' is not supplied,
41 strip from "#" to end-of-line, as well as any whitespace
42 leading up to the "#" -- unless it is escaped by a backslash
49 skip lines that are empty *after* stripping comments and
51 then some lines may consist of solely whitespace: these will
54 if a backslash is the last non-newline character on a line
56 to it to form one "logical line"; if N consecutive lines end
57 with a backslash, then N+1 physical lines will be joined to
60 strip leading whitespace from lines that are joined to their
64 semantics of 'readline()' must differ from those of the builtin file
66 None for end-of-file: an empty string might just be a blank line (or
67 an all-whitespace line), if 'rstrip_ws' is true but 'skip_blanks' is
78 def __init__ (self, filename=None, file=None, **options): argument
80 (a string) and 'file' (a file-like object) must be supplied.
84 if filename is None and file is None:
86 "you must supply either or both of 'filename' and 'file'"
88 # set values for all options -- either from client option hash
102 if file is None:
106 self.file = file
107 self.current_line = 0 # assuming that file is at BOF!
109 # 'linebuf' is a stack of lines that will be emptied before we
110 # actually read from the file; it's only populated by an
116 """Open a new file named 'filename'. This overrides both the
117 'filename' and 'file' arguments to the constructor."""
120 self.file = open (self.filename, 'r')
125 """Close the current file and forget everything we know about it
127 file = self.file
128 self.file = None
131 file.close()
140 outmsg.append("lines %d-%d: " % tuple (line))
152 line in the current file. If the current logical line in the
153 file spans multiple physical lines, the warning refers to the
154 whole range, eg. "lines 3-5". If 'line' supplied, it overrides
156 range of physical lines, or an integer for a single physical
162 """Read and return a single logical line from the current file (or
163 from an internal buffer if lines have previously been "unread"
165 may involve reading multiple physical lines concatenated into a
168 line(s) just read. Returns None on end-of-file, since the empty
172 # If any "unread" lines waiting in 'linebuf', return the top
173 # one. (We don't actually buffer read-ahead data -- lines only
177 line = self.linebuf[-1]
178 del self.linebuf[-1]
185 line = self.file.readline()
192 # is not preceded by "\", then it starts a comment --
199 if pos == -1: # no "#" -- no comments
202 # It's definitely a comment -- either "#" is the first
204 elif pos == 0 or line[pos-1] != "\\":
206 # the job of a later step (rstrip_ws) to remove it --
211 eol = (line[-1] == '\n') and '\n' or ''
215 # *now*, before we try to join it to 'buildup_line' --
230 # oops: end of file
233 "end-of-file")
273 if line[-1] == '\\':
274 buildup_line = line[:-1]
277 if line[-2:] == '\\\n':
278 buildup_line = line[0:-2] + '\n'
288 """Read and return the list of all logical lines remaining in the
289 current file."""
291 lines = []
295 return lines
296 lines.append (line)
302 a parser with line-at-a-time lookahead."""