Skip to content
Myr

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

9 files+37 added−89 removed

modified:src/flask/cli.py+2 added-6 removed
719 unmodified lines
720 return value721722 obj = import_string(value, silent=True)723724 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 obj726727 raise728729
233 unmodified lines
modified:src/flask/ctx.py+1 added-13 removed
219 unmodified lines
220221 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)226227 def pop(self, exc=_sentinel):
140 unmodified lines
368 self._implicit_app_ctx_stack.append(app_ctx)369 else:370 self._implicit_app_ctx_stack.append(None)371374 if hasattr(sys, "exc_clear"):375 sys.exc_clear()376372 _request_ctx_stack.push(self)373374 # 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 lines
393 .. versionchanged:: 0.9394 Added the `exc` argument.395 """396 app_ctx = self._implicit_app_ctx_stack.pop()397 clear_request = False398399 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)406412 # 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()418407 request_close = getattr(self.request, "close", None)408 if request_close is not None:409 request_close()410 clear_request = True
45 unmodified lines
modified:src/flask/helpers.py+22 added-30 removed
632 unmodified lines
633 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.")640641 data = wrap_file(request.environ, file)
152 unmodified lines
794 # current working directory.795 if loader is None or import_name == "__main__":796 return os.getcwd()797802 # 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 lines
850851852def _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.util855863 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)877878 # 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 .zip
258 unmodified lines
modified:tests/test_basic.py+2 added-11 removed
89 unmodified lines
90 rv = client.post("/")91 assert rv.status_code == 40592 assert sorted(rv.allow) == ["GET", "HEAD"]9394 # 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")9995 assert rv.status_code == 4059697 rv = client.head("/")98 assert rv.status_code == 200
4 unmodified lines
103 rv = client.delete("/more")104 assert rv.status_code == 405105 assert sorted(rv.allow) == ["GET", "HEAD", "POST"]106112 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")116108 assert rv.status_code == 405109110111def test_request_dispatching(app, client):
1858 unmodified lines
modified:tests/test_cli.py+3 added-8 removed
587 unmodified lines
588 # ImportError589 with pytest.raises(click.BadParameter):590 run_command.make_context("run", ["--cert", "not_here"])591592 # 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"])594595 # 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)597598 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_context
62 unmodified lines
modified:tests/test_helpers.py-3 removed
90 unmodified lines
91 ),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) == value9697 @pytest.mark.parametrize("debug", (True, False))98 def test_bad_request_debug_message(self, app, client, debug):
578 unmodified lines
677 '"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 lines
modified:tests/test_regression.py+5 added-6 removed
7 unmodified lines
8 :copyright: 2010 Pallets9 :license: BSD-3-Clause10"""11import gc12import sys12import platform13import threading1415import pytest16from werkzeug.exceptions import NotFound
26 unmodified lines
43 _gc_lock.release()44 gc.enable()454647@pytest.mark.skipif(platform.python_implementation() == "PyPy", reason="CPython only")48def test_memory_consumption():49 app = flask.Flask(__name__)5051 @app.route("/")
8 unmodified lines
6061 # Trigger caches62 fire()6363 # 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()676869def test_safe_join_toplevel_pardir():70 from flask.helpers import safe_join
26 unmodified lines
modified:tests/test_reqctx.py-8 removed
283 unmodified lines
284285def test_bad_environ_raises_bad_request():286 app = flask.Flask(__name__)287288 # 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.291288 from flask.testing import EnvironBuilder289290 builder = EnvironBuilder(app)291 environ = builder.get_environ()
12 unmodified lines
304 @app.route("/")305 def index():306 return "Hello World!"307312 # 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.315308 from flask.testing import EnvironBuilder309310 builder = EnvironBuilder(app)311 environ = builder.get_environ()
19 unmodified lines
modified:tests/test_testing.py+2 added-4 removed
167 unmodified lines
168169 rv = client.get("/")170 assert rv.data == b"index"171 assert flask.session.get("data") == "foo"172173 rv = client.post("/", data={}, follow_redirects=True)174 assert rv.data == b"foo"175 assert flask.session.get("data") == "foo"176175 # This support requires a new Werkzeug version176 if not hasattr(client, "redirect_client"):177 assert flask.session.get("data") == "foo"178177 rv = client.get("/getsession")178 assert rv.data == b"foo"179180
254 unmodified lines