(line)
| 6 | EVENT_COUNT = 5 |
| 7 | |
| 8 | def encode_stream(line): |
| 9 | for c in line: |
| 10 | if c == '\n': |
| 11 | yield '\\n' |
| 12 | elif c == '"': |
| 13 | yield '\\"' |
| 14 | elif c == '\t': |
| 15 | yield '\\t' |
| 16 | elif ord(c) < 0x20: |
| 17 | yield '\\x' + hex(ord(c)) |
| 18 | else: |
| 19 | yield c |
| 20 | |
| 21 | def encode(line): |
| 22 | return ''.join(encode_stream(line)) |