diff options
author | Georg Brandl <georg@python.org> | 2014-10-15 08:19:55 +0200 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2014-10-15 08:19:55 +0200 |
commit | 305f4af94739222fdaaeb06a81de9927d7fd2964 (patch) | |
tree | 029a0e5a569a27fb751cc1c34c449c9db4684b83 | |
parent | 02d812930d90c3e20a056796d182bf1ce80d24cd (diff) | |
download | pygments-305f4af94739222fdaaeb06a81de9927d7fd2964.tar.gz |
unistring: fix generated Cs category on Py2.
-rw-r--r-- | pygments/unistring.py | 6 | ||||
-rw-r--r-- | tests/test_unistring.py | 11 |
2 files changed, 7 insertions, 10 deletions
diff --git a/pygments/unistring.py b/pygments/unistring.py index 183f088f..2e4eaed6 100644 --- a/pygments/unistring.py +++ b/pygments/unistring.py @@ -21,7 +21,7 @@ Cn = u'\u0378-\u0379\u037f-\u0383\u038b\u038d\u03a2\u0528-\u0530\u0557-\u0558\u0 Co = u'\ue000-\uf8ff\U000f0000-\U000ffffd\U00100000-\U0010fffd' try: - Cs = eval(r"'\ud800-\udbff\\\udc00\udc01-\udfff'") + Cs = eval(r"u'\ud800-\udbff\\\udc00\udc01-\udfff'") except UnicodeDecodeError: Cs = '' # Jython can't handle isolated surrogates @@ -155,9 +155,9 @@ if __name__ == '__main__': # Jython can't handle isolated surrogates f.write("""\ try: - Cs = eval(r"%s") + Cs = eval(r"u%s") except UnicodeDecodeError: - Cs = '' # Jython can't handle isolated surrogates\n\n""" % repr(val).lstrip('u')) + Cs = '' # Jython can't handle isolated surrogates\n\n""" % ascii(val)) else: f.write('%s = u%a\n\n' % (cat, val)) f.write('cats = %r\n\n' % sorted(categories)) diff --git a/tests/test_unistring.py b/tests/test_unistring.py index a8791e0c..217b2bbf 100644 --- a/tests/test_unistring.py +++ b/tests/test_unistring.py @@ -14,11 +14,12 @@ import random from pygments import unistring as uni from pygments.util import unichr + class UnistringTest(unittest.TestCase): def test_cats_exist_and_compilable(self): for cat in uni.cats: s = getattr(uni, cat) - if s == '': # Probably Cs on Jython + if s == '': # Probably Cs on Jython continue print("%s %r" % (cat, s)) re.compile('[%s]' % s) @@ -27,7 +28,7 @@ class UnistringTest(unittest.TestCase): matching_cats = [] for cat in uni.cats: s = getattr(uni, cat) - if s == '': # Probably Cs on Jython + if s == '': # Probably Cs on Jython continue if re.compile('[%s]' % s).match(c): matching_cats.append(cat) @@ -40,12 +41,8 @@ class UnistringTest(unittest.TestCase): o = random.randint(0, 65535) c = unichr(o) if o > 0xd800 and o <= 0xdfff and not uni.Cs: - continue # Bah, Jython. + continue # Bah, Jython. print(hex(o)) cats = self._cats_that_match(c) self.assertEqual(len(cats), 1, "%d (%s): %s" % (o, c, cats)) - - - - |