summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason R. Coombs <jaraco@jaraco.com>2018-03-17 11:53:22 -0400
committerJason R. Coombs <jaraco@jaraco.com>2018-03-17 12:16:10 -0400
commit6fba91c17b264beec674bb25019e3888fe5ba305 (patch)
tree2bb0ef3b043a509d74fb0c8a8a006dd1f78291db
parente141c08edc47834b04eb0fd7c1510ee04b682921 (diff)
downloadpython-setuptools-git-6fba91c17b264beec674bb25019e3888fe5ba305.tar.gz
Rely on stdlib to decode entities.
-rwxr-xr-xsetuptools/package_index.py17
-rw-r--r--setuptools/py33compat.py9
2 files changed, 11 insertions, 15 deletions
diff --git a/setuptools/package_index.py b/setuptools/package_index.py
index 64a11c9b..914b5e61 100755
--- a/setuptools/package_index.py
+++ b/setuptools/package_index.py
@@ -23,6 +23,7 @@ from distutils import log
from distutils.errors import DistutilsError
from fnmatch import translate
from setuptools.py27compat import get_all_headers
+from setuptools.py33compat import unescape
from setuptools.wheel import Wheel
EGG_FRAGMENT = re.compile(r'^egg=([-A-Za-z0-9_.+!]+)$')
@@ -931,23 +932,9 @@ class PackageIndex(Environment):
entity_sub = re.compile(r'&(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?').sub
-def uchr(c):
- if not isinstance(c, int):
- return c
- if c > 255:
- return six.unichr(c)
- return chr(c)
-
-
def decode_entity(match):
what = match.group(1)
- if what.startswith('#x'):
- what = int(what[2:], 16)
- elif what.startswith('#'):
- what = int(what[1:])
- else:
- what = six.moves.html_entities.name2codepoint.get(what, match.group(0))
- return uchr(what)
+ return unescape(what)
def htmldecode(text):
diff --git a/setuptools/py33compat.py b/setuptools/py33compat.py
index af64d5d1..2a73ebb3 100644
--- a/setuptools/py33compat.py
+++ b/setuptools/py33compat.py
@@ -2,7 +2,13 @@ import dis
import array
import collections
+try:
+ import html
+except ImportError:
+ html = None
+
from setuptools.extern import six
+from setuptools.extern.six.moves import html_parser
OpArg = collections.namedtuple('OpArg', 'opcode arg')
@@ -43,3 +49,6 @@ class Bytecode_compat(object):
Bytecode = getattr(dis, 'Bytecode', Bytecode_compat)
+
+
+unescape = getattr(html, 'unescape', html_parser.HTMLParser().unescape)