(self, body: str, mime: str)
| 57 | self.enabled = self.format_options['xml']['format'] |
| 58 | |
| 59 | def format_body(self, body: str, mime: str): |
| 60 | if 'xml' not in mime: |
| 61 | return body |
| 62 | |
| 63 | from xml.parsers.expat import ExpatError |
| 64 | from defusedxml.common import DefusedXmlException |
| 65 | |
| 66 | declaration = parse_declaration(body) |
| 67 | try: |
| 68 | parsed_body = parse_xml(body) |
| 69 | except ExpatError: |
| 70 | pass # Invalid XML, ignore. |
| 71 | except DefusedXmlException: |
| 72 | pass # Unsafe XML, ignore. |
| 73 | else: |
| 74 | body = pretty_xml(parsed_body, |
| 75 | encoding=parsed_body.encoding, |
| 76 | indent=self.format_options['xml']['indent'], |
| 77 | declaration=declaration) |
| 78 | |
| 79 | return body |
nothing calls this directly
no test coverage detected