mirror of
https://github.com/getpelican/pelican.git
synced 2025-10-15 20:28:56 +02:00
Merge pull request #1828 from andreacorbellini/chr-to-unichr
Use unichr() instead of chr() with Python 2.
This commit is contained in:
commit
72ee73f886
2 changed files with 14 additions and 2 deletions
|
|
@ -190,6 +190,18 @@ class TestUtils(LoggedTestCase):
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
utils.truncate_html_words("cafetiére " * 100, 20),
|
utils.truncate_html_words("cafetiére " * 100, 20),
|
||||||
"cafetiére " * 20 + '...')
|
"cafetiére " * 20 + '...')
|
||||||
|
self.assertEqual(
|
||||||
|
utils.truncate_html_words("∫dx " * 100, 20),
|
||||||
|
"∫dx " * 20 + '...')
|
||||||
|
|
||||||
|
# Words with HTML character references inside and outside
|
||||||
|
# the ASCII range.
|
||||||
|
self.assertEqual(
|
||||||
|
utils.truncate_html_words("é " * 100, 20),
|
||||||
|
"é " * 20 + '...')
|
||||||
|
self.assertEqual(
|
||||||
|
utils.truncate_html_words("∫dx " * 100, 20),
|
||||||
|
"∫dx " * 20 + '...')
|
||||||
|
|
||||||
def test_process_translations(self):
|
def test_process_translations(self):
|
||||||
# create a bunch of articles
|
# create a bunch of articles
|
||||||
|
|
|
||||||
|
|
@ -512,14 +512,14 @@ class _HTMLWordTruncator(HTMLParser):
|
||||||
except KeyError:
|
except KeyError:
|
||||||
self.handle_ref('')
|
self.handle_ref('')
|
||||||
else:
|
else:
|
||||||
self.handle_ref(chr(codepoint))
|
self.handle_ref(six.unichr(codepoint))
|
||||||
|
|
||||||
def handle_charref(self, name):
|
def handle_charref(self, name):
|
||||||
if name.startswith('x'):
|
if name.startswith('x'):
|
||||||
codepoint = int(name[1:], 16)
|
codepoint = int(name[1:], 16)
|
||||||
else:
|
else:
|
||||||
codepoint = int(name)
|
codepoint = int(name)
|
||||||
self.handle_ref(chr(codepoint))
|
self.handle_ref(six.unichr(codepoint))
|
||||||
|
|
||||||
|
|
||||||
def truncate_html_words(s, num, end_text='...'):
|
def truncate_html_words(s, num, end_text='...'):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue