summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorGreg Ward <gward@python.net>2000-09-16 18:06:31 (GMT)
committerGreg Ward <gward@python.net>2000-09-16 18:06:31 (GMT)
commitf11296bdea61a526713027b6337977941aa48fa7 (patch)
tree6ece153ff3c01a39fccfbb0976bc4ce46e635a00 /Lib
parent60cd2864fe1e473f0bfc46b439b33b7864e40f0f (diff)
downloadcpython-f11296bdea61a526713027b6337977941aa48fa7.zip
cpython-f11296bdea61a526713027b6337977941aa48fa7.tar.gz
cpython-f11296bdea61a526713027b6337977941aa48fa7.tar.bz2
[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).
Diffstat (limited to 'Lib')
-rw-r--r--Lib/distutils/text_file.py26
1 files changed, 17 insertions, 9 deletions
diff --git a/Lib/distutils/text_file.py b/Lib/distutils/text_file.py
index f22b3e9..b731762 100644
--- a/Lib/distutils/text_file.py
+++ b/Lib/distutils/text_file.py
@@ -134,6 +134,22 @@ class TextFile:
self.current_line = None
+ def gen_error (self, msg, line=None):
+ outmsg = []
+ if line is None:
+ line = self.current_line
+ outmsg.append(self.filename + ", ")
+ if type (line) in (ListType, TupleType):
+ outmsg.append("lines %d-%d: " % tuple (line))
+ else:
+ outmsg.append("line %d: " % line)
+ outmsg.append(str(msg))
+ return string.join(outmsg, "")
+
+
+ def error (self, msg, line=None):
+ raise ValueError, "error: " + self.gen_error(msg, line)
+
def warn (self, msg, line=None):
"""Print (to stderr) a warning message tied to the current logical
line in the current file. If the current logical line in the
@@ -142,15 +158,7 @@ class TextFile:
the current line number; it may be a list or tuple to indicate a
range of physical lines, or an integer for a single physical
line."""
-
- if line is None:
- line = self.current_line
- sys.stderr.write (self.filename + ", ")
- if type (line) in (ListType, TupleType):
- sys.stderr.write ("lines %d-%d: " % tuple (line))
- else:
- sys.stderr.write ("line %d: " % line)
- sys.stderr.write (str (msg) + "\n")
+ sys.stderr.write("warning: " + self.gen_error(msg, line) + "\n")
def readline (self):