diff --git a/docs/conf.py b/docs/conf.py index 80622e7..a6723b3 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -11,9 +11,9 @@ # All configuration values have a default value; values that are commented out # serve to show the default value. -import sys # If your extensions are in another directory, add it here. +#import sys #sys.path.append('some/directory') # General configuration diff --git a/paste/auth/auth_tkt.py b/paste/auth/auth_tkt.py index 96d4007..4237fed 100644 --- a/paste/auth/auth_tkt.py +++ b/paste/auth/auth_tkt.py @@ -36,7 +36,6 @@ makes it possible to use the same authentication process with non-Python code run under Apache. """ -import six import time as time_mod try: import hashlib @@ -202,15 +201,17 @@ def calculate_digest(ip, timestamp, secret, userid, tokens, user_data, digest = digest_algo(digest0 + secret).hexdigest() return maybe_encode(digest) +def int2byte(i): + return bytes((i,)) def encode_ip_timestamp(ip, timestamp): - ip_chars = b''.join(map(six.int2byte, map(int, ip.split('.')))) + ip_chars = b''.join(map(int2byte, map(int, ip.split('.')))) t = int(timestamp) ts = ((t & 0xff000000) >> 24, (t & 0xff0000) >> 16, (t & 0xff00) >> 8, t & 0xff) - ts_chars = b''.join(map(six.int2byte, ts)) + ts_chars = b''.join(map(int2byte, ts)) return (ip_chars + ts_chars) diff --git a/paste/auth/basic.py b/paste/auth/basic.py index 3055d52..c61d26c 100644 --- a/paste/auth/basic.py +++ b/paste/auth/basic.py @@ -23,8 +23,6 @@ """ from base64 import b64decode -import six - from paste.httpexceptions import HTTPUnauthorized from paste.httpheaders import ( AUTHORIZATION, @@ -53,7 +51,7 @@ def authenticate(self, environ): (authmeth, auth) = authorization.split(' ', 1) if 'basic' != authmeth.lower(): return self.build_authentication() - auth = six.ensure_text(b64decode(six.ensure_binary(auth.strip()))) + auth = b64decode(auth.strip().encode('ascii')).decode('ascii') username, password = auth.split(':', 1) if self.authfunc(environ, username, password): return username diff --git a/paste/auth/cas.py b/paste/auth/cas.py index 489ee65..bd731e4 100644 --- a/paste/auth/cas.py +++ b/paste/auth/cas.py @@ -19,6 +19,7 @@ authentication methods to be used concurrently. """ from urllib.parse import urlencode +from urllib.request import urlopen from paste.request import construct_url from paste.httpexceptions import HTTPSeeOther, HTTPForbidden @@ -94,6 +95,6 @@ def cas_application(environ, start_response): authority = "https://secure.its.yale.edu/cas/servlet/" from paste.wsgilib import dump_environ from paste.httpserver import serve - from paste.httpexceptions import * + from paste.httpexceptions import HTTPExceptionHandler serve(HTTPExceptionHandler( AuthCASHandler(dump_environ, authority))) diff --git a/paste/auth/cookie.py b/paste/auth/cookie.py index 74ba8af..79b10a5 100644 --- a/paste/auth/cookie.py +++ b/paste/auth/cookie.py @@ -41,7 +41,8 @@ """ -import hmac, base64, random, six, time, warnings +import hmac, base64, random, time, warnings +from functools import reduce try: from hashlib import sha1 except ImportError: @@ -62,7 +63,7 @@ def make_time(value): _decode = [(v, k) for (k, v) in _encode] _decode.reverse() def encode(s, sublist = _encode): - return six.moves.reduce((lambda a, b: a.replace(b[0], b[1])), sublist, str(s)) + return reduce((lambda a, b: a.replace(b[0], b[1])), sublist, str(s)) decode = lambda s: encode(s, _decode) class CookieTooLarge(RuntimeError): diff --git a/paste/cgiapp.py b/paste/cgiapp.py index 255ef2c..04d318e 100644 --- a/paste/cgiapp.py +++ b/paste/cgiapp.py @@ -12,12 +12,17 @@ import select except ImportError: select = None -import six from paste.util import converters __all__ = ['CGIError', 'CGIApplication'] +def ensure_text(s, encoding='utf-8', errors='strict'): + if type(s) is str: + return s + else: + return s.decode(encoding, errors) + class CGIError(Exception): """ Raised when the CGI script can't be found or doesn't @@ -40,7 +45,7 @@ def __init__(self, include_os_environ=True, query_string=None): if global_conf: - raise NotImplemented( + raise NotImplementedError( "global_conf is no longer supported for CGIApplication " "(use make_cgi_application); please pass None instead") self.script_filename = script @@ -158,7 +163,7 @@ def write(self, data): else: self.headers.append((name, value)) -class StdinReader(object): +class StdinReader: def __init__(self, stdin, content_length): self.stdin = stdin @@ -252,7 +257,7 @@ def proc_communicate(proc, stdin=None, stdout=None, stderr=None): read_set.remove(proc.stderr) if trans_nl: data = proc._translate_newlines(data) - stderr.write(six.ensure_text(data)) + stderr.write(ensure_text(data)) try: proc.wait() diff --git a/paste/evalexception/middleware.py b/paste/evalexception/middleware.py index 95d3af7..9e11eaa 100644 --- a/paste/evalexception/middleware.py +++ b/paste/evalexception/middleware.py @@ -45,6 +45,9 @@ limit = 200 +def cmp(a, b): + return (a > b) - (a < b) + def html_quote(v): """ Escape HTML characters, plus translate None to '' diff --git a/paste/exceptions/collector.py b/paste/exceptions/collector.py index 8490001..9a5e42a 100644 --- a/paste/exceptions/collector.py +++ b/paste/exceptions/collector.py @@ -382,7 +382,7 @@ def safeStr(self, obj): return str(obj) except UnicodeEncodeError: try: - return unicode(obj).encode(FALLBACK_ENCODING, 'replace') + return str(obj).encode(FALLBACK_ENCODING, 'replace') except UnicodeEncodeError: # This is when something is really messed up, but this can # happen when the __str__ of an object has to handle unicode diff --git a/paste/exceptions/serial_number_generator.py b/paste/exceptions/serial_number_generator.py index c2fcc9a..e69e5da 100644 --- a/paste/exceptions/serial_number_generator.py +++ b/paste/exceptions/serial_number_generator.py @@ -13,7 +13,8 @@ except ImportError: from md5 import md5 -import six +import operator +byte2int = operator.itemgetter(0) good_characters = "23456789abcdefghjkmnpqrtuvwxyz" @@ -71,7 +72,7 @@ def hash_identifier(s, length, pad=True, hasher=md5, prefix='', modulo = base ** length number = 0 for c in list(bin_hash): - number = (number * 256 + six.byte2int([c])) % modulo + number = (number * 256 + byte2int([c])) % modulo ident = make_identifier(number) if pad: ident = good_characters[0]*(length-len(ident)) + ident diff --git a/paste/fileapp.py b/paste/fileapp.py index e18281a..9bde843 100644 --- a/paste/fileapp.py +++ b/paste/fileapp.py @@ -10,8 +10,29 @@ """ import os, time, mimetypes, zipfile, tarfile -from paste.httpexceptions import * -from paste.httpheaders import * +from paste.httpexceptions import ( + HTTPBadRequest, + HTTPForbidden, + HTTPMethodNotAllowed, + HTTPNotFound, + HTTPRequestRangeNotSatisfiable, +) +from paste.httpheaders import ( + get_header, + list_headers, + ACCEPT_RANGES, + CACHE_CONTROL, + CONTENT_DISPOSITION, + CONTENT_LENGTH, + CONTENT_RANGE, + CONTENT_TYPE, + ETAG, + EXPIRES, + IF_MODIFIED_SINCE, + IF_NONE_MATCH, + LAST_MODIFIED, + RANGE, +) CACHE_SIZE = 4096 BLOCK_SIZE = 4096 * 16 diff --git a/paste/fixture.py b/paste/fixture.py index 87fa15c..ab613a2 100644 --- a/paste/fixture.py +++ b/paste/fixture.py @@ -22,13 +22,24 @@ import subprocess from urllib.parse import urlencode from urllib import parse as urlparse -from six.moves.http_cookies import BaseCookie -import six +from http.cookies import BaseCookie from paste import wsgilib from paste import lint from paste.response import HeaderDict +def ensure_binary(s): + if isinstance(s, bytes): + return s + else: + return s.encode('utf-8') + +def ensure_str(s, encoding='utf-8', errors='strict'): + if type(s) is str: + return s + else: + return s.decode(encoding, errors) + def tempnam_no_warning(*args): """ An os.tempnam with the warning turned off, because sometimes @@ -333,18 +344,18 @@ def encode_multipart(self, params, files): lines = [] for key, value in params: lines.append(b'--'+boundary) - line = b'Content-Disposition: form-data; name="%s"' % six.ensure_binary(key) + line = b'Content-Disposition: form-data; name="%s"' % ensure_binary(key) lines.append(line) lines.append(b'') - line = six.ensure_binary(value) + line = ensure_binary(value) lines.append(line) for file_info in files: key, filename, value = self._get_file_info(file_info) lines.append(b'--'+boundary) line = (b'Content-Disposition: form-data; name="%s"; filename="%s"' - % (six.ensure_binary(key), six.ensure_binary(filename))) + % (ensure_binary(key), ensure_binary(filename))) lines.append(line) - fcontent = mimetypes.guess_type(six.ensure_str(filename, 'ascii', 'ignore'))[0] + fcontent = mimetypes.guess_type(ensure_str(filename, 'ascii', 'ignore'))[0] line = (b'Content-Type: %s' % (fcontent.encode('ascii') if fcontent else b'application/octet-stream')) lines.append(line) diff --git a/paste/httpserver.py b/paste/httpserver.py index 50dc3c6..f8539ec 100755 --- a/paste/httpserver.py +++ b/paste/httpserver.py @@ -25,10 +25,10 @@ import time import os from itertools import count -from six.moves import _thread -from six.moves import queue -from six.moves.BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer -from six.moves.socketserver import ThreadingMixIn +import _thread +import queue +from http.server import BaseHTTPRequestHandler, HTTPServer +from socketserver import ThreadingMixIn from urllib.parse import unquote, urlsplit from paste.util import converters import logging diff --git a/paste/proxy.py b/paste/proxy.py index 0ca7ff7..513a0e4 100644 --- a/paste/proxy.py +++ b/paste/proxy.py @@ -29,7 +29,7 @@ """ -from six.moves import http_client as httplib +import http.client as httplib from urllib import parse as urlparse from urllib.parse import quote diff --git a/paste/translogger.py b/paste/translogger.py index 3a898dd..33825b0 100644 --- a/paste/translogger.py +++ b/paste/translogger.py @@ -6,7 +6,7 @@ import logging import time -from six.moves.urllib.parse import quote +from urllib.parse import quote class TransLogger: """ diff --git a/paste/util/quoting.py b/paste/util/quoting.py index 72369e1..186949f 100644 --- a/paste/util/quoting.py +++ b/paste/util/quoting.py @@ -1,13 +1,10 @@ # (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org) # Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php +import html +import html.entities import re -from six.moves import html_entities from urllib.parse import quote, unquote -import six - -import html - __all__ = ['html_quote', 'html_unquote', 'url_quote', 'url_unquote', 'strip_html'] @@ -30,10 +27,10 @@ def html_quote(v, encoding=None): return html.escape(str(v), 1) _unquote_re = re.compile(r'&([a-zA-Z]+);') -def _entity_subber(match, name2c=html_entities.name2codepoint): +def _entity_subber(match, name2c=html.entities.name2codepoint): code = name2c.get(match.group(1)) if code: - return six.unichr(code) + return chr(code) else: return match.group(0) diff --git a/paste/util/template.py b/paste/util/template.py index eec35f1..25459fd 100644 --- a/paste/util/template.py +++ b/paste/util/template.py @@ -31,7 +31,6 @@ def foo(bar): """ import re -import six import sys from html import escape from urllib.parse import quote @@ -44,6 +43,17 @@ def foo(bar): in_re = re.compile(r'\s+in\s+') var_re = re.compile(r'^[a-z_][a-z0-9_]*$', re.I) +def reraise(tp, value, tb=None): + try: + if value is None: + value = tp() + if value.__traceback__ is not tb: + raise value.with_traceback(tb) + raise value + finally: + value = None + tb = None + class TemplateError(Exception): """Exception raised while parsing a template """ @@ -208,7 +218,7 @@ def _eval(self, code, ns, pos): else: arg0 = str(e) e.args = (self._add_line_info(arg0, pos),) - six.reraise(exc_info[0], e, exc_info[2]) + reraise(exc_info[0], e, exc_info[2]) def _exec(self, code, ns, pos): __traceback_hide__ = True @@ -218,7 +228,7 @@ def _exec(self, code, ns, pos): exc_info = sys.exc_info() e = exc_info[1] e.args = (self._add_line_info(e.args[0], pos),) - six.reraise(exc_info[0], e, exc_info[2]) + reraise(exc_info[0], e, exc_info[2]) def _repr(self, value, pos): __traceback_hide__ = True @@ -230,7 +240,7 @@ def _repr(self, value, pos): exc_info = sys.exc_info() e = exc_info[1] e.args = (self._add_line_info(e.args[0], pos),) - six.reraise(exc_info[0], e, exc_info[2]) + reraise(exc_info[0], e, exc_info[2]) else: if self._unicode and isinstance(value, bytes): if not self.decode_encoding: diff --git a/paste/util/threadedprint.py b/paste/util/threadedprint.py index 7635f75..4161cce 100644 --- a/paste/util/threadedprint.py +++ b/paste/util/threadedprint.py @@ -90,7 +90,7 @@ def __init__(self, default=None, factory=None, paramwriter=None, self._catchers = {} def write(self, v, currentThread=threading.current_thread): - name = current_thread().name + name = currentThread().name catchers = self._catchers if not catchers.has_key(name): self._defaultfunc(name, v) diff --git a/setup.py b/setup.py index f3851be..addf126 100644 --- a/setup.py +++ b/setup.py @@ -56,7 +56,6 @@ zip_safe=False, install_requires=[ 'setuptools', # pkg_resources - 'six>=1.4.0', ], extras_require={ 'subprocess': [], diff --git a/tests/test_auth/test_auth_cookie.py b/tests/test_auth/test_auth_cookie.py index 19deb4d..ba4b1a0 100644 --- a/tests/test_auth/test_auth_cookie.py +++ b/tests/test_auth/test_auth_cookie.py @@ -5,7 +5,6 @@ from paste.auth import cookie from paste.wsgilib import raw_interactive, dump_environ from paste.response import header_value -from paste.httpexceptions import * def build(application,setenv, *args, **kwargs): def setter(environ, start_response): diff --git a/tests/test_auth/test_auth_digest.py b/tests/test_auth/test_auth_digest.py index 2a4c4aa..17b839b 100644 --- a/tests/test_auth/test_auth_digest.py +++ b/tests/test_auth/test_auth_digest.py @@ -2,9 +2,9 @@ # This module is part of the Python Paste Project and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php -from paste.auth.digest import * +from paste.auth.digest import digest_password, AuthDigestHandler from paste.wsgilib import raw_interactive -from paste.httpexceptions import * +from paste.httpexceptions import HTTPExceptionHandler from paste.httpheaders import AUTHORIZATION, WWW_AUTHENTICATE, REMOTE_USER import os diff --git a/tests/test_cgiapp.py b/tests/test_cgiapp.py index ea04b4c..d173aa2 100644 --- a/tests/test_cgiapp.py +++ b/tests/test_cgiapp.py @@ -4,7 +4,7 @@ import pytest from paste.cgiapp import CGIApplication, CGIError -from paste.fixture import * +from paste.fixture import TestApp data_dir = os.path.join(os.path.dirname(__file__), 'cgiapp_data') diff --git a/tests/test_cgitb_catcher.py b/tests/test_cgitb_catcher.py index 5247aa0..0a4c99c 100644 --- a/tests/test_cgitb_catcher.py +++ b/tests/test_cgitb_catcher.py @@ -1,4 +1,4 @@ -from paste.fixture import * +from paste.fixture import TestApp from paste.cgitb_catcher import CgitbMiddleware from paste import lint from .test_exceptions.test_error_middleware import clear_middleware diff --git a/tests/test_errordocument.py b/tests/test_errordocument.py index efeae61..65a06b4 100644 --- a/tests/test_errordocument.py +++ b/tests/test_errordocument.py @@ -1,5 +1,5 @@ from paste.errordocument import forward -from paste.fixture import * +from paste.fixture import TestApp from paste.recursive import RecursiveMiddleware def simple_app(environ, start_response): diff --git a/tests/test_exceptions/test_error_middleware.py b/tests/test_exceptions/test_error_middleware.py index 91fbc46..0750593 100644 --- a/tests/test_exceptions/test_error_middleware.py +++ b/tests/test_exceptions/test_error_middleware.py @@ -1,4 +1,4 @@ -from paste.fixture import * +from paste.fixture import TestApp from paste.exceptions.errormiddleware import ErrorMiddleware from paste import lint from paste.util.quoting import strip_html diff --git a/tests/test_exceptions/test_reporter.py b/tests/test_exceptions/test_reporter.py index a40666e..5a06589 100644 --- a/tests/test_exceptions/test_reporter.py +++ b/tests/test_exceptions/test_reporter.py @@ -1,6 +1,6 @@ import sys import os -from paste.exceptions.reporter import * +from paste.exceptions.reporter import LogReporter from paste.exceptions import collector def setup_file(fn, content=None): diff --git a/tests/test_fileapp.py b/tests/test_fileapp.py index d209bb9..e2ada64 100644 --- a/tests/test_fileapp.py +++ b/tests/test_fileapp.py @@ -8,8 +8,8 @@ from email.utils import parsedate_tz, mktime_tz from paste import fileapp -from paste.fileapp import * -from paste.fixture import * +from paste.fileapp import DataApp +from paste.fixture import TestApp # NOTE(haypo): don't use string.letters because the order of lower and upper # case letters changes when locale.setlocale() is called for the first time diff --git a/tests/test_fixture.py b/tests/test_fixture.py index 3060299..0e74fe9 100644 --- a/tests/test_fixture.py +++ b/tests/test_fixture.py @@ -1,5 +1,3 @@ -import cgi - from paste.debug.debugapp import SimpleApplication, SlowConsumer from paste.fixture import TestApp from paste.wsgiwrappers import WSGIRequest diff --git a/tests/test_grantip.py b/tests/test_grantip.py index 34e184c..54beb22 100644 --- a/tests/test_grantip.py +++ b/tests/test_grantip.py @@ -1,5 +1,5 @@ from paste.auth import grantip -from paste.fixture import * +from paste.fixture import TestApp def _make_app(): def application(environ, start_response): diff --git a/tests/test_import_string.py b/tests/test_import_string.py index 262cbdd..f92cbc8 100644 --- a/tests/test_import_string.py +++ b/tests/test_import_string.py @@ -1,4 +1,4 @@ -from paste.util.import_string import * +from paste.util.import_string import eval_import, simple_import import sys import os diff --git a/tests/test_profilemiddleware.py b/tests/test_profilemiddleware.py index 4c189f8..2ab176a 100644 --- a/tests/test_profilemiddleware.py +++ b/tests/test_profilemiddleware.py @@ -1,6 +1,6 @@ -from paste.fixture import * +from paste.fixture import TestApp try: - from paste.debug.profile import * + from paste.debug.profile import ProfileMiddleware, profile_decorator disable = False except ImportError: disable = True diff --git a/tests/test_recursive.py b/tests/test_recursive.py index 1cb1984..64036f9 100644 --- a/tests/test_recursive.py +++ b/tests/test_recursive.py @@ -1,5 +1,5 @@ from .test_errordocument import simple_app -from paste.fixture import * +from paste.fixture import TestApp from paste.recursive import RecursiveMiddleware, ForwardRequestException def error_docs_app(environ, start_response): diff --git a/tests/test_registry.py b/tests/test_registry.py index 80fac29..9b36fc5 100644 --- a/tests/test_registry.py +++ b/tests/test_registry.py @@ -4,9 +4,13 @@ import pytest -from paste.fixture import * -from paste.registry import * -from paste.registry import Registry +from paste.fixture import TestApp +from paste.registry import ( + Registry, + RegistryManager, + StackedObjectProxy, + restorer, +) from paste.evalexception.middleware import EvalException regobj = StackedObjectProxy() diff --git a/tests/test_request.py b/tests/test_request.py index 4028642..8993f15 100644 --- a/tests/test_request.py +++ b/tests/test_request.py @@ -1,8 +1,8 @@ # (c) 2005 Ben Bangert # This module is part of the Python Paste Project and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php -from paste.fixture import * -from paste.request import * +from paste.fixture import TestApp +from paste.request import get_cookie_dict from paste.wsgiwrappers import WSGIRequest def simpleapp(environ, start_response): diff --git a/tests/test_request_form.py b/tests/test_request_form.py index 76a0149..fe0c21b 100644 --- a/tests/test_request_form.py +++ b/tests/test_request_form.py @@ -1,6 +1,6 @@ import io -from paste.request import * +from paste.request import parse_formvars, parse_querystring from paste.util.multidict import MultiDict def test_parse_querystring(): diff --git a/tests/test_response.py b/tests/test_response.py index 71f6f97..55bdfee 100644 --- a/tests/test_response.py +++ b/tests/test_response.py @@ -1,4 +1,4 @@ -from paste.response import * +from paste.response import replace_header def test_replace_header(): h = [('content-type', 'text/plain'), diff --git a/tests/test_urlparser.py b/tests/test_urlparser.py index 21c210e..ba1d770 100644 --- a/tests/test_urlparser.py +++ b/tests/test_urlparser.py @@ -1,6 +1,7 @@ import os -from paste.urlparser import * -from paste.fixture import * + +from paste.urlparser import PkgResourcesParser, StaticURLParser, URLParser +from paste.fixture import TestApp from pkg_resources import get_distribution def relative_path(name): diff --git a/tests/test_util/test_mimeparse.py b/tests/test_util/test_mimeparse.py index 9b9b675..86d29da 100644 --- a/tests/test_util/test_mimeparse.py +++ b/tests/test_util/test_mimeparse.py @@ -2,7 +2,15 @@ # This module is part of the Python Paste Project and is released under # the MIT License: http://www.opensource.org/licenses/mit-license.php -from paste.util.mimeparse import * +from paste.util.mimeparse import ( + best_match, + desired_matches, + fitness_and_quality_parsed, + parse_media_range, + parse_mime_type, + quality, + quality_parsed, +) def test_parse_mime_type(): parse = parse_mime_type