@@ -134,6 +134,22 @@ def close (self):
134
134
self .current_line = None
135
135
136
136
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
+
137
153
def warn (self , msg , line = None ):
138
154
"""Print (to stderr) a warning message tied to the current logical
139
155
line in the current file. If the current logical line in the
@@ -142,15 +158,7 @@ def warn (self, msg, line=None):
142
158
the current line number; it may be a list or tuple to indicate a
143
159
range of physical lines, or an integer for a single physical
144
160
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 " )
154
162
155
163
156
164
def readline (self ):
0 commit comments