like call but write to a temporary buffer
(self, toktype, toktext, start_pos)
| 282 | |
| 283 | |
| 284 | def _inner_call_(self, toktype, toktext, start_pos): |
| 285 | """like call but write to a temporary buffer""" |
| 286 | buff = StringIO() |
| 287 | srow, scol = start_pos |
| 288 | colors = self.colors |
| 289 | owrite = buff.write |
| 290 | |
| 291 | # line separator, so this works across platforms |
| 292 | linesep = os.linesep |
| 293 | |
| 294 | # calculate new positions |
| 295 | oldpos = self.pos |
| 296 | newpos = self.lines[srow] + scol |
| 297 | self.pos = newpos + len(toktext) |
| 298 | |
| 299 | # send the original whitespace, if needed |
| 300 | if newpos > oldpos: |
| 301 | owrite(self.raw[oldpos:newpos]) |
| 302 | |
| 303 | # skip indenting tokens |
| 304 | if toktype in [token.INDENT, token.DEDENT]: |
| 305 | self.pos = newpos |
| 306 | buff.seek(0) |
| 307 | return buff.read() |
| 308 | |
| 309 | # map token type to a color group |
| 310 | if token.LPAR <= toktype <= token.OP: |
| 311 | toktype = token.OP |
| 312 | elif toktype == token.NAME and keyword.iskeyword(toktext): |
| 313 | toktype = _KEYWORD |
| 314 | color = colors.get(toktype, colors[_TEXT]) |
| 315 | |
| 316 | # Triple quoted strings must be handled carefully so that backtracking |
| 317 | # in pagers works correctly. We need color terminators on _each_ line. |
| 318 | if linesep in toktext: |
| 319 | toktext = toktext.replace(linesep, '%s%s%s' % |
| 320 | (colors.normal,linesep,color)) |
| 321 | |
| 322 | # send text |
| 323 | owrite('%s%s%s' % (color,toktext,colors.normal)) |
| 324 | buff.seek(0) |
| 325 | return buff.read() |
| 326 | |
| 327 | |
| 328 | def __call__(self, toktype, toktext, start_pos, end_pos, line): |