Skip to content

Commit f11296b

Browse files
committed
[change from 2000/08/11, propagating now to distutils copy]
Factored the guts of 'warn()' out to 'gen_error()', and added the 'error()' method (trivial thanks to the refactoring).
1 parent 60cd286 commit f11296b

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

Lib/distutils/text_file.py

+17-9
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,22 @@ def close (self):
134134
self.current_line = None
135135

136136

137+
def gen_error (self, msg, line=None):
138+
outmsg = []
139+
if line is None:
140+
line = self.current_line
141+
outmsg.append(self.filename + ", ")
142+
if type (line) in (ListType, TupleType):
143+
outmsg.append("lines %d-%d: " % tuple (line))
144+
else:
145+
outmsg.append("line %d: " % line)
146+
outmsg.append(str(msg))
147+
return string.join(outmsg, "")
148+
149+
150+
def error (self, msg, line=None):
151+
raise ValueError, "error: " + self.gen_error(msg, line)
152+
137153
def warn (self, msg, line=None):
138154
"""Print (to stderr) a warning message tied to the current logical
139155
line in the current file. If the current logical line in the
@@ -142,15 +158,7 @@ def warn (self, msg, line=None):
142158
the current line number; it may be a list or tuple to indicate a
143159
range of physical lines, or an integer for a single physical
144160
line."""
145-
146-
if line is None:
147-
line = self.current_line
148-
sys.stderr.write (self.filename + ", ")
149-
if type (line) in (ListType, TupleType):
150-
sys.stderr.write ("lines %d-%d: " % tuple (line))
151-
else:
152-
sys.stderr.write ("line %d: " % line)
153-
sys.stderr.write (str (msg) + "\n")
161+
sys.stderr.write("warning: " + self.gen_error(msg, line) + "\n")
154162

155163

156164
def readline (self):

0 commit comments

Comments
 (0)