Normalize an Expression object's parts, collapsing multiple adjacent text blocks and removing empty text blocks. Generates a sequence of parts.
(expr)
| 20 | |
| 21 | |
| 22 | def _normexpr(expr): |
| 23 | """Normalize an Expression object's parts, collapsing multiple |
| 24 | adjacent text blocks and removing empty text blocks. Generates a |
| 25 | sequence of parts. |
| 26 | """ |
| 27 | textbuf = [] |
| 28 | for part in expr.parts: |
| 29 | if isinstance(part, str): |
| 30 | textbuf.append(part) |
| 31 | else: |
| 32 | if textbuf: |
| 33 | text = "".join(textbuf) |
| 34 | if text: |
| 35 | yield text |
| 36 | textbuf = [] |
| 37 | yield part |
| 38 | if textbuf: |
| 39 | text = "".join(textbuf) |
| 40 | if text: |
| 41 | yield text |
| 42 | |
| 43 | |
| 44 | def _normparse(text): |
no test coverage detected