(s, quotes=('"', "'", '"""', "'''"))
| 27 | nonglobal_ops = frozenset(('STORE_DEREF', 'DELETE_DEREF')) |
| 28 | |
| 29 | def escape_string(s, quotes=('"', "'", '"""', "'''")): |
| 30 | quote = None |
| 31 | for q in quotes: |
| 32 | if s.find(q) == -1: |
| 33 | quote = q |
| 34 | break |
| 35 | pass |
| 36 | if quote is None: |
| 37 | quote = '"""' |
| 38 | s = s.replace('"""', '\\"""') |
| 39 | |
| 40 | for (orig, replace) in (('\t', '\\t'), |
| 41 | ('\n', '\\n'), |
| 42 | ('\r', '\\r')): |
| 43 | s = s.replace(orig, replace) |
| 44 | return "%s%s%s" % (quote, s, quote) |
| 45 | |
| 46 | # FIXME: this and find_globals could be parameterized with one of the |
| 47 | # above global ops |
no outgoing calls
no test coverage detected