diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2020-08-16 00:29:24 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2020-08-16 07:15:18 -0400 |
commit | fb7ab81a3d080422687bad71f9ae9d36eeefbee2 (patch) | |
tree | d87a9f6fdf32ab64334e1eb8a695949a88a3b043 /setuptools/package_index.py | |
parent | 4eb5b32f8d8bb1e20907028a516346e2b1901391 (diff) | |
download | python-setuptools-git-fb7ab81a3d080422687bad71f9ae9d36eeefbee2.tar.gz |
Remove Python 2 compatibility
Diffstat (limited to 'setuptools/package_index.py')
-rw-r--r-- | setuptools/package_index.py | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/setuptools/package_index.py b/setuptools/package_index.py index 1702c7c6..3979b131 100644 --- a/setuptools/package_index.py +++ b/setuptools/package_index.py @@ -2,17 +2,21 @@ import sys import os import re +import io import shutil import socket import base64 import hashlib import itertools import warnings +import configparser +import html +import http.client +import urllib.parse +import urllib.request +import urllib.error from functools import wraps -from setuptools.extern import six -from setuptools.extern.six.moves import urllib, http_client, configparser, map - import setuptools from pkg_resources import ( CHECKOUT_DIST, Distribution, BINARY_DIST, normalize_path, SOURCE_DIST, @@ -23,12 +27,8 @@ from setuptools import ssl_support 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 -__metaclass__ = type - EGG_FRAGMENT = re.compile(r'^egg=([-A-Za-z0-9_.+!]+)$') HREF = re.compile(r"""href\s*=\s*['"]?([^'"> ]+)""", re.I) PYPI_MD5 = re.compile( @@ -191,7 +191,7 @@ def unique_everseen(iterable, key=None): seen = set() seen_add = seen.add if key is None: - for element in six.moves.filterfalse(seen.__contains__, iterable): + for element in itertools.filterfalse(seen.__contains__, iterable): seen_add(element) yield element else: @@ -740,7 +740,7 @@ class PackageIndex(Environment): size = -1 if "content-length" in headers: # Some servers return multiple Content-Length headers :( - sizes = get_all_headers(headers, 'Content-Length') + sizes = headers.get_all('Content-Length') size = max(map(int, sizes)) self.reporthook(url, filename, blocknum, bs, size) with open(filename, 'wb') as tfp: @@ -767,7 +767,7 @@ class PackageIndex(Environment): return local_open(url) try: return open_with_auth(url, self.opener) - except (ValueError, http_client.InvalidURL) as v: + except (ValueError, http.client.InvalidURL) as v: msg = ' '.join([str(arg) for arg in v.args]) if warning: self.warn(warning, msg) @@ -781,7 +781,7 @@ class PackageIndex(Environment): else: raise DistutilsError("Download error for %s: %s" % (url, v.reason)) from v - except http_client.BadStatusLine as v: + except http.client.BadStatusLine as v: if warning: self.warn(warning, v.line) else: @@ -790,7 +790,7 @@ class PackageIndex(Environment): 'down, %s' % (url, v.line) ) from v - except (http_client.HTTPException, socket.error) as v: + except (http.client.HTTPException, socket.error) as v: if warning: self.warn(warning, v) else: @@ -940,7 +940,7 @@ entity_sub = re.compile(r'&(#(\d+|x[\da-fA-F]+)|[\w.:-]+);?').sub def decode_entity(match): what = match.group(0) - return unescape(what) + return html.unescape(what) def htmldecode(text): @@ -972,8 +972,7 @@ def socket_timeout(timeout=15): def _encode_auth(auth): """ - A function compatible with Python 2.3-3.3 that will encode - auth from a URL suitable for an HTTP header. + Encode auth from a URL suitable for an HTTP header. >>> str(_encode_auth('username%3Apassword')) 'dXNlcm5hbWU6cGFzc3dvcmQ=' @@ -1056,7 +1055,7 @@ def open_with_auth(url, opener=urllib.request.urlopen): # Double scheme does not raise on macOS as revealed by a # failing test. We would expect "nonnumeric port". Refs #20. if netloc.endswith(':'): - raise http_client.InvalidURL("nonnumeric port: ''") + raise http.client.InvalidURL("nonnumeric port: ''") if scheme in ('http', 'https'): auth, address = _splituser(netloc) @@ -1136,5 +1135,5 @@ def local_open(url): status, message, body = 404, "Path not found", "Not found" headers = {'content-type': 'text/html'} - body_stream = six.StringIO(body) + body_stream = io.StringIO(body) return urllib.error.HTTPError(url, status, message, headers, body_stream) |