encoding: make HFS+ ignore code Python 3 compatible
unichr() doesn't exist in Python 3. chr() is the equivalent there.
Unfortunately, we can't use chr() outright because Python 2 only
accepts values smaller than 256.
Also, Python 3 returns an int when accessing a character of a
bytes type (s[x]). So, we have to ord() the values in the assert
statement.
--- a/mercurial/encoding.py Fri Mar 11 10:28:58 2016 +0000
+++ b/mercurial/encoding.py Fri Mar 11 21:23:34 2016 -0800
@@ -10,12 +10,16 @@
import array
import locale
import os
+import sys
import unicodedata
from . import (
error,
)
+if sys.version_info[0] >= 3:
+ unichr = chr
+
# These unicode characters are ignored by HFS+ (Apple Technote 1150,
# "Unicode Subtleties"), so we need to ignore them in some places for
# sanity.
@@ -23,7 +27,10 @@
"200c 200d 200e 200f 202a 202b 202c 202d 202e "
"206a 206b 206c 206d 206e 206f feff".split()]
# verify the next function will work
-assert set([i[0] for i in _ignore]) == set(["\xe2", "\xef"])
+if sys.version_info[0] >= 3:
+ assert set(i[0] for i in _ignore) == set([ord(b'\xe2'), ord(b'\xef')])
+else:
+ assert set(i[0] for i in _ignore) == set(["\xe2", "\xef"])
def hfsignoreclean(s):
"""Remove codepoints ignored by HFS+ from s.