Python htmlentitydefs.codepoint2name() Examples
The following are 14
code examples of htmlentitydefs.codepoint2name().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
htmlentitydefs
, or try the search function
.
Example #1
Source File: test_codeccallbacks.py From ironpython2 with Apache License 2.0 | 6 votes |
def test_xmlcharnamereplace(self): # This time use a named character entity for unencodable # characters, if one is available. def xmlcharnamereplace(exc): if not isinstance(exc, UnicodeEncodeError): raise TypeError("don't know how to handle %r" % exc) l = [] for c in exc.object[exc.start:exc.end]: try: l.append(u"&%s;" % htmlentitydefs.codepoint2name[ord(c)]) except KeyError: l.append(u"&#%d;" % ord(c)) return (u"".join(l), exc.end) codecs.register_error( "test.xmlcharnamereplace", xmlcharnamereplace) sin = u"\xab\u211c\xbb = \u2329\u1234\u20ac\u232a" sout = "«ℜ» = ⟨ሴ€⟩" self.assertEqual(sin.encode("ascii", "test.xmlcharnamereplace"), sout) sout = "\xabℜ\xbb = ⟨ሴ€⟩" self.assertEqual(sin.encode("latin-1", "test.xmlcharnamereplace"), sout) sout = "\xabℜ\xbb = ⟨ሴ\xa4⟩" self.assertEqual(sin.encode("iso-8859-15", "test.xmlcharnamereplace"), sout)
Example #2
Source File: test_codeccallbacks.py From BinderFilter with MIT License | 6 votes |
def test_xmlcharnamereplace(self): # This time use a named character entity for unencodable # characters, if one is available. def xmlcharnamereplace(exc): if not isinstance(exc, UnicodeEncodeError): raise TypeError("don't know how to handle %r" % exc) l = [] for c in exc.object[exc.start:exc.end]: try: l.append(u"&%s;" % htmlentitydefs.codepoint2name[ord(c)]) except KeyError: l.append(u"&#%d;" % ord(c)) return (u"".join(l), exc.end) codecs.register_error( "test.xmlcharnamereplace", xmlcharnamereplace) sin = u"\xab\u211c\xbb = \u2329\u1234\u20ac\u232a" sout = "«ℜ» = ⟨ሴ€⟩" self.assertEqual(sin.encode("ascii", "test.xmlcharnamereplace"), sout) sout = "\xabℜ\xbb = ⟨ሴ€⟩" self.assertEqual(sin.encode("latin-1", "test.xmlcharnamereplace"), sout) sout = "\xabℜ\xbb = ⟨ሴ\xa4⟩" self.assertEqual(sin.encode("iso-8859-15", "test.xmlcharnamereplace"), sout)
Example #3
Source File: test_codeccallbacks.py From oss-ftp with MIT License | 6 votes |
def test_xmlcharnamereplace(self): # This time use a named character entity for unencodable # characters, if one is available. def xmlcharnamereplace(exc): if not isinstance(exc, UnicodeEncodeError): raise TypeError("don't know how to handle %r" % exc) l = [] for c in exc.object[exc.start:exc.end]: try: l.append(u"&%s;" % htmlentitydefs.codepoint2name[ord(c)]) except KeyError: l.append(u"&#%d;" % ord(c)) return (u"".join(l), exc.end) codecs.register_error( "test.xmlcharnamereplace", xmlcharnamereplace) sin = u"\xab\u211c\xbb = \u2329\u1234\u20ac\u232a" sout = "«ℜ» = ⟨ሴ€⟩" self.assertEqual(sin.encode("ascii", "test.xmlcharnamereplace"), sout) sout = "\xabℜ\xbb = ⟨ሴ€⟩" self.assertEqual(sin.encode("latin-1", "test.xmlcharnamereplace"), sout) sout = "\xabℜ\xbb = ⟨ሴ\xa4⟩" self.assertEqual(sin.encode("iso-8859-15", "test.xmlcharnamereplace"), sout)
Example #4
Source File: test_codeccallbacks.py From gcblue with BSD 3-Clause "New" or "Revised" License | 6 votes |
def test_xmlcharnamereplace(self): # This time use a named character entity for unencodable # characters, if one is available. def xmlcharnamereplace(exc): if not isinstance(exc, UnicodeEncodeError): raise TypeError("don't know how to handle %r" % exc) l = [] for c in exc.object[exc.start:exc.end]: try: l.append(u"&%s;" % htmlentitydefs.codepoint2name[ord(c)]) except KeyError: l.append(u"&#%d;" % ord(c)) return (u"".join(l), exc.end) codecs.register_error( "test.xmlcharnamereplace", xmlcharnamereplace) sin = u"\xab\u211c\xbb = \u2329\u1234\u20ac\u232a" sout = "«ℜ» = ⟨ሴ€⟩" self.assertEqual(sin.encode("ascii", "test.xmlcharnamereplace"), sout) sout = "\xabℜ\xbb = ⟨ሴ€⟩" self.assertEqual(sin.encode("latin-1", "test.xmlcharnamereplace"), sout) sout = "\xabℜ\xbb = ⟨ሴ\xa4⟩" self.assertEqual(sin.encode("iso-8859-15", "test.xmlcharnamereplace"), sout)
Example #5
Source File: test_codeccallbacks.py From medicare-demo with Apache License 2.0 | 6 votes |
def test_xmlcharnamereplace(self): # This time use a named character entity for unencodable # characters, if one is available. def xmlcharnamereplace(exc): if not isinstance(exc, UnicodeEncodeError): raise TypeError("don't know how to handle %r" % exc) l = [] for c in exc.object[exc.start:exc.end]: try: l.append(u"&%s;" % htmlentitydefs.codepoint2name[ord(c)]) except KeyError: l.append(u"&#%d;" % ord(c)) return (u"".join(l), exc.end) codecs.register_error( "test.xmlcharnamereplace", xmlcharnamereplace) sin = u"\xab\u211c\xbb = \u2329\u1234\u20ac\u232a" sout = "«ℜ» = ⟨ሴ€⟩" self.assertEqual(sin.encode("ascii", "test.xmlcharnamereplace"), sout) sout = "\xabℜ\xbb = ⟨ሴ€⟩" self.assertEqual(sin.encode("latin-1", "test.xmlcharnamereplace"), sout) sout = "\xabℜ\xbb = ⟨ሴ\xa4⟩" self.assertEqual(sin.encode("iso-8859-15", "test.xmlcharnamereplace"), sout)
Example #6
Source File: test_codeccallbacks.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 6 votes |
def test_xmlcharnamereplace(self): # This time use a named character entity for unencodable # characters, if one is available. def xmlcharnamereplace(exc): if not isinstance(exc, UnicodeEncodeError): raise TypeError("don't know how to handle %r" % exc) l = [] for c in exc.object[exc.start:exc.end]: try: l.append(u"&%s;" % htmlentitydefs.codepoint2name[ord(c)]) except KeyError: l.append(u"&#%d;" % ord(c)) return (u"".join(l), exc.end) codecs.register_error( "test.xmlcharnamereplace", xmlcharnamereplace) sin = u"\xab\u211c\xbb = \u2329\u1234\u20ac\u232a" sout = "«ℜ» = ⟨ሴ€⟩" self.assertEqual(sin.encode("ascii", "test.xmlcharnamereplace"), sout) sout = "\xabℜ\xbb = ⟨ሴ€⟩" self.assertEqual(sin.encode("latin-1", "test.xmlcharnamereplace"), sout) sout = "\xabℜ\xbb = ⟨ሴ\xa4⟩" self.assertEqual(sin.encode("iso-8859-15", "test.xmlcharnamereplace"), sout)
Example #7
Source File: test_codeccallbacks.py From CTFCrackTools with GNU General Public License v3.0 | 6 votes |
def test_xmlcharnamereplace(self): # This time use a named character entity for unencodable # characters, if one is available. def xmlcharnamereplace(exc): if not isinstance(exc, UnicodeEncodeError): raise TypeError("don't know how to handle %r" % exc) l = [] for c in exc.object[exc.start:exc.end]: try: l.append(u"&%s;" % htmlentitydefs.codepoint2name[ord(c)]) except KeyError: l.append(u"&#%d;" % ord(c)) return (u"".join(l), exc.end) codecs.register_error( "test.xmlcharnamereplace", xmlcharnamereplace) sin = u"\xab\u211c\xbb = \u2329\u1234\u20ac\u232a" sout = "«ℜ» = ⟨ሴ€⟩" self.assertEqual(sin.encode("ascii", "test.xmlcharnamereplace"), sout) sout = "\xabℜ\xbb = ⟨ሴ€⟩" self.assertEqual(sin.encode("latin-1", "test.xmlcharnamereplace"), sout) sout = "\xabℜ\xbb = ⟨ሴ\xa4⟩" self.assertEqual(sin.encode("iso-8859-15", "test.xmlcharnamereplace"), sout)
Example #8
Source File: multibytecodec_support.py From ironpython2 with Apache License 2.0 | 5 votes |
def test_customreplace_encode(self): if self.has_iso10646: self.skipTest('encoding contains full ISO 10646 map') from htmlentitydefs import codepoint2name def xmlcharnamereplace(exc): if not isinstance(exc, UnicodeEncodeError): raise TypeError("don't know how to handle %r" % exc) l = [] for c in exc.object[exc.start:exc.end]: if ord(c) in codepoint2name: l.append(u"&%s;" % codepoint2name[ord(c)]) else: l.append(u"&#%d;" % ord(c)) return (u"".join(l), exc.end) codecs.register_error("test.xmlcharnamereplace", xmlcharnamereplace) if self.xmlcharnametest: sin, sout = self.xmlcharnametest else: sin = u"\xab\u211c\xbb = \u2329\u1234\u232a" sout = "«ℜ» = ⟨ሴ⟩" self.assertEqual(self.encode(sin, "test.xmlcharnamereplace")[0], sout)
Example #9
Source File: test_multibytecodec_support.py From BinderFilter with MIT License | 5 votes |
def test_customreplace_encode(self): if self.has_iso10646: return from htmlentitydefs import codepoint2name def xmlcharnamereplace(exc): if not isinstance(exc, UnicodeEncodeError): raise TypeError("don't know how to handle %r" % exc) l = [] for c in exc.object[exc.start:exc.end]: if ord(c) in codepoint2name: l.append(u"&%s;" % codepoint2name[ord(c)]) else: l.append(u"&#%d;" % ord(c)) return (u"".join(l), exc.end) codecs.register_error("test.xmlcharnamereplace", xmlcharnamereplace) if self.xmlcharnametest: sin, sout = self.xmlcharnametest else: sin = u"\xab\u211c\xbb = \u2329\u1234\u232a" sout = "«ℜ» = ⟨ሴ⟩" self.assertEqual(self.encode(sin, "test.xmlcharnamereplace")[0], sout)
Example #10
Source File: test_multibytecodec_support.py From oss-ftp with MIT License | 5 votes |
def test_customreplace_encode(self): if self.has_iso10646: self.skipTest('encoding contains full ISO 10646 map') from htmlentitydefs import codepoint2name def xmlcharnamereplace(exc): if not isinstance(exc, UnicodeEncodeError): raise TypeError("don't know how to handle %r" % exc) l = [] for c in exc.object[exc.start:exc.end]: if ord(c) in codepoint2name: l.append(u"&%s;" % codepoint2name[ord(c)]) else: l.append(u"&#%d;" % ord(c)) return (u"".join(l), exc.end) codecs.register_error("test.xmlcharnamereplace", xmlcharnamereplace) if self.xmlcharnametest: sin, sout = self.xmlcharnametest else: sin = u"\xab\u211c\xbb = \u2329\u1234\u232a" sout = "«ℜ» = ⟨ሴ⟩" self.assertEqual(self.encode(sin, "test.xmlcharnamereplace")[0], sout)
Example #11
Source File: test_multibytecodec_support.py From gcblue with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_customreplace_encode(self): if self.has_iso10646: self.skipTest('encoding contains full ISO 10646 map') from htmlentitydefs import codepoint2name def xmlcharnamereplace(exc): if not isinstance(exc, UnicodeEncodeError): raise TypeError("don't know how to handle %r" % exc) l = [] for c in exc.object[exc.start:exc.end]: if ord(c) in codepoint2name: l.append(u"&%s;" % codepoint2name[ord(c)]) else: l.append(u"&#%d;" % ord(c)) return (u"".join(l), exc.end) codecs.register_error("test.xmlcharnamereplace", xmlcharnamereplace) if self.xmlcharnametest: sin, sout = self.xmlcharnametest else: sin = u"\xab\u211c\xbb = \u2329\u1234\u232a" sout = "«ℜ» = ⟨ሴ⟩" self.assertEqual(self.encode(sin, "test.xmlcharnamereplace")[0], sout)
Example #12
Source File: test_multibytecodec_support.py From medicare-demo with Apache License 2.0 | 5 votes |
def test_customreplace_encode(self): if self.has_iso10646: return from htmlentitydefs import codepoint2name def xmlcharnamereplace(exc): if not isinstance(exc, UnicodeEncodeError): raise TypeError("don't know how to handle %r" % exc) l = [] for c in exc.object[exc.start:exc.end]: if ord(c) in codepoint2name: l.append(u"&%s;" % codepoint2name[ord(c)]) else: l.append(u"&#%d;" % ord(c)) return (u"".join(l), exc.end) codecs.register_error("test.xmlcharnamereplace", xmlcharnamereplace) if self.xmlcharnametest: sin, sout = self.xmlcharnametest else: sin = u"\xab\u211c\xbb = \u2329\u1234\u232a" sout = "«ℜ» = ⟨ሴ⟩" self.assertEqual(self.encode(sin, "test.xmlcharnamereplace")[0], sout)
Example #13
Source File: test_multibytecodec_support.py From CTFCrackTools-V2 with GNU General Public License v3.0 | 5 votes |
def test_customreplace_encode(self): if self.has_iso10646: return from htmlentitydefs import codepoint2name def xmlcharnamereplace(exc): if not isinstance(exc, UnicodeEncodeError): raise TypeError("don't know how to handle %r" % exc) l = [] for c in exc.object[exc.start:exc.end]: if ord(c) in codepoint2name: l.append(u"&%s;" % codepoint2name[ord(c)]) else: l.append(u"&#%d;" % ord(c)) return (u"".join(l), exc.end) codecs.register_error("test.xmlcharnamereplace", xmlcharnamereplace) if self.xmlcharnametest: sin, sout = self.xmlcharnametest else: sin = u"\xab\u211c\xbb = \u2329\u1234\u232a" sout = "«ℜ» = ⟨ሴ⟩" self.assertEqual(self.encode(sin, "test.xmlcharnamereplace")[0], sout)
Example #14
Source File: test_multibytecodec_support.py From CTFCrackTools with GNU General Public License v3.0 | 5 votes |
def test_customreplace_encode(self): if self.has_iso10646: return from htmlentitydefs import codepoint2name def xmlcharnamereplace(exc): if not isinstance(exc, UnicodeEncodeError): raise TypeError("don't know how to handle %r" % exc) l = [] for c in exc.object[exc.start:exc.end]: if ord(c) in codepoint2name: l.append(u"&%s;" % codepoint2name[ord(c)]) else: l.append(u"&#%d;" % ord(c)) return (u"".join(l), exc.end) codecs.register_error("test.xmlcharnamereplace", xmlcharnamereplace) if self.xmlcharnametest: sin, sout = self.xmlcharnametest else: sin = u"\xab\u211c\xbb = \u2329\u1234\u232a" sout = "«ℜ» = ⟨ሴ⟩" self.assertEqual(self.encode(sin, "test.xmlcharnamereplace")[0], sout)