(text, encoding)
| 78 | _raise_serialization_error(text) |
| 79 | |
| 80 | def _escape_cdata(text, encoding): |
| 81 | # escape character data |
| 82 | try: |
| 83 | # it's worth avoiding do-nothing calls for strings that are |
| 84 | # shorter than 500 character, or so. assume that's, by far, |
| 85 | # the most common case in most applications. |
| 86 | if "&" in text: |
| 87 | text = text.replace("&", "&") |
| 88 | if "<" in text: |
| 89 | text = text.replace("<", "<") |
| 90 | if ">" in text: |
| 91 | text = text.replace(">", ">") |
| 92 | return text.encode(encoding, "xmlcharrefreplace") |
| 93 | except (TypeError, AttributeError): |
| 94 | _raise_serialization_error(text) |
| 95 | |
| 96 | |
| 97 | def _escape_attrib(text, encoding): |
no test coverage detected