Add compatibility code for Python 2.7
- Typo in codepoints.py for compat chr() - Add a fake lru_cache decorator for Python 2.7
This commit is contained in:
parent
422380f06e
commit
d0cad5b52b
|
@ -494,7 +494,7 @@ def get_unicodedata_categories():
|
|||
minor_category = 'Cc'
|
||||
start_cp, next_cp = 0, 1
|
||||
for cp in range(maxunicode + 1):
|
||||
if category(chr(cp)) != minor_category:
|
||||
if category(unicode_chr(cp)) != minor_category:
|
||||
if cp > next_cp:
|
||||
categories[minor_category].append((start_cp, cp))
|
||||
categories[minor_category[0]].append(categories[minor_category][-1])
|
||||
|
@ -502,7 +502,7 @@ def get_unicodedata_categories():
|
|||
categories[minor_category].append(start_cp)
|
||||
categories[minor_category[0]].append(start_cp)
|
||||
|
||||
minor_category = category(chr(cp))
|
||||
minor_category = category(unicode_chr(cp))
|
||||
start_cp, next_cp = cp, cp + 1
|
||||
else:
|
||||
if next_cp == maxunicode + 1:
|
||||
|
|
|
@ -21,6 +21,7 @@ try:
|
|||
from urllib.error import URLError
|
||||
from io import StringIO, BytesIO
|
||||
from collections.abc import Iterable, MutableSet, Sequence, MutableSequence, Mapping, MutableMapping
|
||||
from functools import lru_cache
|
||||
except ImportError:
|
||||
# Python 2.7 imports
|
||||
from urllib import pathname2url
|
||||
|
@ -29,6 +30,18 @@ except ImportError:
|
|||
from StringIO import StringIO # the io.StringIO accepts only unicode type
|
||||
from io import BytesIO
|
||||
from collections import Iterable, MutableSet, Sequence, MutableSequence, Mapping, MutableMapping
|
||||
from functools import wraps
|
||||
|
||||
def lru_cache(maxsize=128, typed=False):
|
||||
"""
|
||||
A fake lru_cache decorator function for Python 2.7 compatibility until support ends.
|
||||
"""
|
||||
def lru_cache_decorator(f):
|
||||
@wraps(f)
|
||||
def wrapper(*args, **kwargs):
|
||||
return f(*args, **kwargs)
|
||||
return wrapper
|
||||
return lru_cache_decorator
|
||||
|
||||
|
||||
PY3 = sys.version_info[0] == 3
|
||||
|
|
Loading…
Reference in New Issue