(self)
| 81 | ) |
| 82 | |
| 83 | def test_customreplace_encode(self): |
| 84 | if self.has_iso10646: |
| 85 | self.skipTest('encoding contains full ISO 10646 map') |
| 86 | |
| 87 | from html.entities import codepoint2name |
| 88 | |
| 89 | def xmlcharnamereplace(exc): |
| 90 | if not isinstance(exc, UnicodeEncodeError): |
| 91 | raise TypeError("don't know how to handle %r" % exc) |
| 92 | l = [] |
| 93 | for c in exc.object[exc.start:exc.end]: |
| 94 | if ord(c) in codepoint2name: |
| 95 | l.append("&%s;" % codepoint2name[ord(c)]) |
| 96 | else: |
| 97 | l.append("&#%d;" % ord(c)) |
| 98 | return ("".join(l), exc.end) |
| 99 | |
| 100 | codecs.register_error("test.xmlcharnamereplace", xmlcharnamereplace) |
| 101 | |
| 102 | if self.xmlcharnametest: |
| 103 | sin, sout = self.xmlcharnametest |
| 104 | else: |
| 105 | sin = "\xab\u211c\xbb = \u2329\u1234\u232a" |
| 106 | sout = b"«ℜ» = ⟨ሴ⟩" |
| 107 | self.assertEqual(self.encode(sin, |
| 108 | "test.xmlcharnamereplace")[0], sout) |
| 109 | |
| 110 | def test_callback_returns_bytes(self): |
| 111 | def myreplace(exc): |
nothing calls this directly
no test coverage detected