(self, multiline)
| 3509 | return ''.join(self.code_buffer) |
| 3510 | |
| 3511 | def read_code(self, multiline): |
| 3512 | code_line, comment = '', '' |
| 3513 | while True: |
| 3514 | m = self.re_tok.search(self.source[self.offset:]) |
| 3515 | if not m: |
| 3516 | code_line += self.source[self.offset:] |
| 3517 | self.offset = len(self.source) |
| 3518 | self.write_code(code_line.strip(), comment) |
| 3519 | return |
| 3520 | code_line += self.source[self.offset:self.offset+m.start()] |
| 3521 | self.offset += m.end() |
| 3522 | _str, _com, _po, _pc, _blk1, _blk2, _end, _cend, _nl = m.groups() |
| 3523 | if (code_line or self.paren_depth > 0) and (_blk1 or _blk2): # a if b else c |
| 3524 | code_line += _blk1 or _blk2 |
| 3525 | continue |
| 3526 | if _str: # Python string |
| 3527 | code_line += _str |
| 3528 | elif _com: # Python comment (up to EOL) |
| 3529 | comment = _com |
| 3530 | if multiline and _com.strip().endswith(self._tokens[1]): |
| 3531 | multiline = False # Allow end-of-block in comments |
| 3532 | elif _po: # open parenthesis |
| 3533 | self.paren_depth += 1 |
| 3534 | code_line += _po |
| 3535 | elif _pc: # close parenthesis |
| 3536 | if self.paren_depth > 0: |
| 3537 | # we could check for matching parentheses here, but it's |
| 3538 | # easier to leave that to python - just check counts |
| 3539 | self.paren_depth -= 1 |
| 3540 | code_line += _pc |
| 3541 | elif _blk1: # Start-block keyword (if/for/while/def/try/...) |
| 3542 | code_line, self.indent_mod = _blk1, -1 |
| 3543 | self.indent += 1 |
| 3544 | elif _blk2: # Continue-block keyword (else/elif/except/...) |
| 3545 | code_line, self.indent_mod = _blk2, -1 |
| 3546 | elif _end: # The non-standard 'end'-keyword (ends a block) |
| 3547 | self.indent -= 1 |
| 3548 | elif _cend: # The end-code-block template token (usually '%>') |
| 3549 | if multiline: multiline = False |
| 3550 | else: code_line += _cend |
| 3551 | else: # \n |
| 3552 | self.write_code(code_line.strip(), comment) |
| 3553 | self.lineno += 1 |
| 3554 | code_line, comment, self.indent_mod = '', '', 0 |
| 3555 | if not multiline: |
| 3556 | break |
| 3557 | |
| 3558 | def flush_text(self): |
| 3559 | text = ''.join(self.text_buffer) |
no test coverage detected