##// END OF EJS Templates
Some cleanup of Pycolorize....
Matthias Bussonnier -
Show More
@@ -185,8 +185,11 b' class Parser(Colorable):'
185 185
186 186 super(Parser, self).__init__(parent=parent)
187 187
188 self.color_table = color_table and color_table or ANSICodeColors
188 self.color_table = color_table if color_table else ANSICodeColors
189 189 self.out = out
190 self.pos = None
191 self.lines = None
192 self.raw = None
190 193 if not style:
191 194 self.style = self.default_style
192 195 else:
@@ -232,7 +235,6 b' class Parser(Colorable):'
232 235 self.out.write(raw)
233 236 if string_output:
234 237 return raw,error
235 else:
236 238 return None,error
237 239
238 240 # local shorthands
@@ -247,9 +249,10 b' class Parser(Colorable):'
247 249 pos = 0
248 250 raw_find = self.raw.find
249 251 lines_append = self.lines.append
250 while 1:
252 while True:
251 253 pos = raw_find('\n', pos) + 1
252 if not pos: break
254 if not pos:
255 break
253 256 lines_append(pos)
254 257 lines_append(len(self.raw))
255 258
@@ -277,11 +280,11 b' class Parser(Colorable):'
277 280 return (output, error)
278 281 return (None, error)
279 282
280 def _inner_call_(self, toktype, toktext, start_pos, end_pos, line):
283
284 def _inner_call_(self, toktype, toktext, start_pos):
281 285 """like call but write to a temporary buffer"""
282 286 buff = StringIO()
283 (srow,scol) = start_pos
284 (erow,ecol) = end_pos
287 srow, scol = start_pos
285 288 colors = self.colors
286 289 owrite = buff.write
287 290
@@ -310,8 +313,6 b' class Parser(Colorable):'
310 313 toktype = _KEYWORD
311 314 color = colors.get(toktype, colors[_TEXT])
312 315
313 #print '<%s>' % toktext, # dbg
314
315 316 # Triple quoted strings must be handled carefully so that backtracking
316 317 # in pagers works correctly. We need color terminators on _each_ line.
317 318 if linesep in toktext:
@@ -327,5 +328,4 b' class Parser(Colorable):'
327 328 def __call__(self, toktype, toktext, start_pos, end_pos, line):
328 329 """ Token handler, with syntax highlighting."""
329 330 self.out.write(
330 self._inner_call_(toktype, toktext, start_pos, end_pos, line))
331
331 self._inner_call_(toktype, toktext, start_pos))
General Comments 0
You need to be logged in to leave comments. Login now