remove more compat code
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Lord · committed by David Lord · parent 662c245 · Browse files · 9 files·+37 added−89 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
9 files+37 added−89 removed
- tests:+12 added−40 removed
- other:+25 added−49 removed
Provenance
- Commit
57d628c- Tree
6ba7f64- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent
662c245
9 files changed+37 added−89 removed
modified:src/flask/cli.py+2 added-6 removed
719 unmodified lines720 return value721 722 obj = import_string(value, silent=True)723 724- if sys.version_info < (2, 7, 9):725- if obj:726- return obj727- else:728- if isinstance(obj, ssl.SSLContext):729- return obj724+ if isinstance(obj, ssl.SSLContext):725+ return obj726 727 raise728 729 233 unmodified linesmodified:src/flask/ctx.py+1 added-13 removed
219 unmodified lines220 221 def push(self):222 """Binds the app context to the current context."""223 self._refcnt += 1224- if hasattr(sys, "exc_clear"):225- sys.exc_clear()224 _app_ctx_stack.push(self)225 appcontext_pushed.send(self.app)226 227 def pop(self, exc=_sentinel):140 unmodified lines368 self._implicit_app_ctx_stack.append(app_ctx)369 else:370 self._implicit_app_ctx_stack.append(None)371 374- if hasattr(sys, "exc_clear"):375- sys.exc_clear()376-372 _request_ctx_stack.push(self)373 374 # Open the session at the moment that the request context is available.375 # This allows a custom open_session method to use the request context.17 unmodified lines393 .. versionchanged:: 0.9394 Added the `exc` argument.395 """396 app_ctx = self._implicit_app_ctx_stack.pop()397+ clear_request = False398 399 try:404- clear_request = False400 if not self._implicit_app_ctx_stack:401 self.preserved = False402 self._preserved_exc = None403 if exc is _sentinel:404 exc = sys.exc_info()[1]405 self.app.do_teardown_request(exc)406 412- # If this interpreter supports clearing the exception information413- # we do that now. This will only go into effect on Python 2.x,414- # on 3.x it disappears automatically at the end of the exception415- # stack.416- if hasattr(sys, "exc_clear"):417- sys.exc_clear()418-407 request_close = getattr(self.request, "close", None)408 if request_close is not None:409 request_close()410 clear_request = True45 unmodified linesmodified:src/flask/helpers.py+22 added-30 removed
632 unmodified lines633 file = open(filename, "rb")634 mtime = os.path.getmtime(filename)635 fsize = os.path.getsize(filename)636 elif isinstance(file, io.BytesIO):637- try:638- fsize = file.getbuffer().nbytes637+ fsize = file.getbuffer().nbytes639- except AttributeError:640- # Python 2 doesn't have getbuffer641- fsize = len(file.getvalue())638 elif isinstance(file, io.TextIOBase):639 raise ValueError("Files must be opened in binary mode or use BytesIO.")640 641 data = wrap_file(request.environ, file)152 unmodified lines794 # current working directory.795 if loader is None or import_name == "__main__":796 return os.getcwd()797 802- # For .egg, zipimporter does not have get_filename until Python 2.7.803- # Some other loaders might exhibit the same behavior.798 if hasattr(loader, "get_filename"):799 filepath = loader.get_filename(import_name)800 else:801 # Fall back to imports.48 unmodified lines850 851 852 def _find_package_path(root_mod_name):853 """Find the path where the module's root exists in"""860- if sys.version_info >= (3, 4):861- import importlib.util854+ import importlib.util855 863- try:864- spec = importlib.util.find_spec(root_mod_name)865- if spec is None:866- raise ValueError("not found")867- # ImportError: the machinery told us it does not exist868- # ValueError:869- # - the module name was invalid870- # - the module name is __main__871- # - *we* raised `ValueError` due to `spec` being `None`872- except (ImportError, ValueError):873- pass # handled below856+ try:857+ spec = importlib.util.find_spec(root_mod_name)858+ if spec is None:859+ raise ValueError("not found")860+ # ImportError: the machinery told us it does not exist861+ # ValueError:862+ # - the module name was invalid863+ # - the module name is __main__864+ # - *we* raised `ValueError` due to `spec` being `None`865+ except (ImportError, ValueError):866+ pass # handled below867+ else:868+ # namespace package869+ if spec.origin in {"namespace", None}:870+ return os.path.dirname(next(iter(spec.submodule_search_locations)))871+ # a package (with __init__.py)872+ elif spec.submodule_search_locations:873+ return os.path.dirname(os.path.dirname(spec.origin))874+ # just a normal module875 else:875- # namespace package876- if spec.origin in {"namespace", None}:877- return os.path.dirname(next(iter(spec.submodule_search_locations)))878- # a package (with __init__.py)879- elif spec.submodule_search_locations:880- return os.path.dirname(os.path.dirname(spec.origin))881- # just a normal module882- else:883- return os.path.dirname(spec.origin)876+ return os.path.dirname(spec.origin)877 878 # we were unable to find the `package_path` using PEP 451 loaders879 loader = pkgutil.get_loader(root_mod_name)880 if loader is None or root_mod_name == "__main__":881 # import name is not found, or interactive/main module882 return os.getcwd()883 else:891- # For .egg, zipimporter does not have get_filename until Python 2.7.884 if hasattr(loader, "get_filename"):885 filename = loader.get_filename(root_mod_name)886 elif hasattr(loader, "archive"):887 # zipimporter's loader.archive points to the .egg or .zip258 unmodified linesmodified:tests/test_basic.py+2 added-11 removed
89 unmodified lines90 rv = client.post("/")91 assert rv.status_code == 40592 assert sorted(rv.allow) == ["GET", "HEAD"]93 94- # Older versions of Werkzeug.test.Client don't have an options method95- if hasattr(client, "options"):96- rv = client.options("/")97- else:98- rv = client.open("/", method="OPTIONS")94+ rv = client.open("/", method="OPTIONS")99-95 assert rv.status_code == 40596 97 rv = client.head("/")98 assert rv.status_code == 2004 unmodified lines103 rv = client.delete("/more")104 assert rv.status_code == 405105 assert sorted(rv.allow) == ["GET", "HEAD", "POST"]106 112- if hasattr(client, "options"):113- rv = client.options("/more")114- else:115- rv = client.open("/more", method="OPTIONS")107+ rv = client.open("/more", method="OPTIONS")116-108 assert rv.status_code == 405109 110 111 def test_request_dispatching(app, client):1858 unmodified linesmodified:tests/test_cli.py+3 added-8 removed
587 unmodified lines588 # ImportError589 with pytest.raises(click.BadParameter):590 run_command.make_context("run", ["--cert", "not_here"])591 592- # not an SSLContext593- if sys.version_info >= (2, 7, 9):594- with pytest.raises(click.BadParameter):595- run_command.make_context("run", ["--cert", "flask"])592+ with pytest.raises(click.BadParameter):593+ run_command.make_context("run", ["--cert", "flask"])594 595 # SSLContext598- if sys.version_info < (2, 7, 9):599- ssl_context = object()600- else:601- ssl_context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)596+ ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)597 598 monkeypatch.setitem(sys.modules, "ssl_context", ssl_context)599 ctx = run_command.make_context("run", ["--cert", "ssl_context"])600 assert ctx.params["cert"] is ssl_context62 unmodified linesmodified:tests/test_helpers.py-3 removed
90 unmodified lines91 ),92 )93 def test_detect_encoding(self, value, encoding):94 data = json.dumps(value).encode(encoding)95- assert json.detect_encoding(data) == encoding95 assert json.loads(data) == value96 97 @pytest.mark.parametrize("debug", (True, False))98 def test_bad_request_debug_message(self, app, client, debug):578 unmodified lines677 '"Nandu/pinguino.txt"',678 "%C3%91and%C3%BA%EF%BC%8Fping%C3%BCino.txt",679 ),680 (u"Vögel.txt", "Vogel.txt", "V%C3%B6gel.txt"),682- # Native string not marked as Unicode on Python 2683- ("tést.txt", "test.txt", "t%C3%A9st.txt"),681 # ":/" are not safe in filename* value682 (u"те:/ст", '":/"', "%D1%82%D0%B5%3A%2F%D1%81%D1%82"),683 ),684 )346 unmodified linesmodified:tests/test_regression.py+5 added-6 removed
7 unmodified lines8 :copyright: 2010 Pallets9 :license: BSD-3-Clause10 """11 import gc12-import sys12+import platform13 import threading14 15 import pytest16 from werkzeug.exceptions import NotFound26 unmodified lines43 _gc_lock.release()44 gc.enable()45 46 47+@pytest.mark.skipif(platform.python_implementation() == "PyPy", reason="CPython only")48 def test_memory_consumption():49 app = flask.Flask(__name__)50 51 @app.route("/")8 unmodified lines60 61 # Trigger caches62 fire()63 63- # This test only works on CPython 2.7.64- if sys.version_info >= (2, 7) and not hasattr(sys, "pypy_translation_info"):65- with assert_no_leak():66- for _x in range(10):67- fire()64+ with assert_no_leak():65+ for _x in range(10):66+ fire()67 68 69 def test_safe_join_toplevel_pardir():70 from flask.helpers import safe_join26 unmodified linesmodified:tests/test_reqctx.py-8 removed
283 unmodified lines284 285 def test_bad_environ_raises_bad_request():286 app = flask.Flask(__name__)287 288- # We cannot use app.test_client() for the Unicode-rich Host header,289- # because werkzeug enforces latin1 on Python 2.290- # However it works when actually passed to the server.291-288 from flask.testing import EnvironBuilder289 290 builder = EnvironBuilder(app)291 environ = builder.get_environ()12 unmodified lines304 @app.route("/")305 def index():306 return "Hello World!"307 312- # We cannot use app.test_client() for the Unicode-rich Host header,313- # because werkzeug enforces latin1 on Python 2.314- # However it works when actually passed to the server.315-308 from flask.testing import EnvironBuilder309 310 builder = EnvironBuilder(app)311 environ = builder.get_environ()19 unmodified linesmodified:tests/test_testing.py+2 added-4 removed
167 unmodified lines168 169 rv = client.get("/")170 assert rv.data == b"index"171 assert flask.session.get("data") == "foo"172+173 rv = client.post("/", data={}, follow_redirects=True)174 assert rv.data == b"foo"175+ assert flask.session.get("data") == "foo"176 175- # This support requires a new Werkzeug version176- if not hasattr(client, "redirect_client"):177- assert flask.session.get("data") == "foo"178-177 rv = client.get("/getsession")178 assert rv.data == b"foo"179 180 254 unmodified lines