Merge branch '2.0.x'
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 · parents 93a7f08, 1a1c7ea · Browse files · 4 files·+40 added−13 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
4 files+40 added−13 removed
- other:+40 added−13 removed
Provenance
- Commit
0fb5c2f- Tree
881f5a0- Author
David Lord <davidism@gmail.com>- Committer
David Lord <davidism@gmail.com>- Parent 1
93a7f08- Parent 2
1a1c7ea
4 files changed+40 added−13 removed
modified:docs/server.rst+13 added-6 removed
78 unmodified lines79 80 Either identify and stop the other program, or use81 ``flask run --port 5001`` to pick a different port.82 83-You can use ``netstat`` to identify what process id is using a port,84-then use other operating system tools stop that process. The following85-example shows that process id 6847 is using port 5000.83+You can use ``netstat`` or ``lsof`` to identify what process id is using84+a port, then use other operating system tools stop that process. The85+following example shows that process id 6847 is using port 5000.86 87 .. tabs::88 89- .. group-tab:: Linux/Mac89+ .. tab:: ``netstat`` (Linux)90 91 .. code-block:: text92 93 $ netstat -nlp | grep 500094 tcp 0 0 127.0.0.1:5000 0.0.0.0:* LISTEN 6847/python95 96- .. group-tab:: Windows96+ .. tab:: ``lsof`` (macOS / Linux)97 98 .. code-block:: text99 100+ $ lsof -P -i :5000101+ Python 6847 IPv4 TCP localhost:5000 (LISTEN)102+103+ .. tab:: ``netstat`` (Windows)104+105+ .. code-block:: text106+107 > netstat -ano | findstr 5000108 TCP 127.0.0.1:5000 0.0.0.0:0 LISTENING 6847109 103-MacOS Monterey and later automatically starts a service that uses port110+macOS Monterey and later automatically starts a service that uses port111 5000. To disable the service, go to System Preferences, Sharing, and112 disable "AirPlay Receiver".113 114 43 unmodified linesmodified:src/flask/json/__init__.py+9 added-3 removed
72 unmodified lines73 bp = app.blueprints.get(request.blueprint) if request else None # type: ignore74 if bp is not None and bp.json_encoder is not None:75 cls = bp.json_encoder76 77+ # Only set a custom encoder if it has custom behavior. This is78+ # faster on PyPy.79+ if cls is not _json.JSONEncoder:80+ kwargs.setdefault("cls", cls)81+82 kwargs.setdefault("cls", cls)83 kwargs.setdefault("ensure_ascii", app.config["JSON_AS_ASCII"])84 kwargs.setdefault("sort_keys", app.config["JSON_SORT_KEYS"])85 else:13 unmodified lines99 bp = app.blueprints.get(request.blueprint) if request else None # type: ignore100 if bp is not None and bp.json_decoder is not None:101 cls = bp.json_decoder102 98- kwargs.setdefault("cls", cls)99- else:100- kwargs.setdefault("cls", JSONDecoder)103+ # Only set a custom decoder if it has custom behavior. This is104+ # faster on PyPy.105+ if cls not in {JSONDecoder, _json.JSONDecoder}:106+ kwargs.setdefault("cls", cls)107 108 109 def dumps(obj: t.Any, app: t.Optional["Flask"] = None, **kwargs: t.Any) -> str:110 """Serialize an object to a string of JSON.189 unmodified linesmodified:src/flask/ctx.py+13 added-4 removed
128 unmodified lines129 some headers without converting the return value into a response object.130 131 .. versionadded:: 0.9132 """133+ top = _request_ctx_stack.top134+135+ if top is None:136+ raise RuntimeError(137+ "This decorator can only be used when a request context is"138+ " active, such as within a view function."139+ )140+133- _request_ctx_stack.top._after_request_functions.append(f)141+ top._after_request_functions.append(f)142 return f143 144 145 def copy_current_request_context(f: t.Callable) -> t.Callable:20 unmodified lines166 167 .. versionadded:: 0.10168 """169 top = _request_ctx_stack.top170+171 if top is None:172 raise RuntimeError(164- "This decorator can only be used at local scopes "165- "when a request context is on the stack. For instance within "166- "view functions."173+ "This decorator can only be used when a request context is"174+ " active, such as within a view function."175 )176+177 reqctx = top.copy()178 179 def wrapper(*args, **kwargs):180 with reqctx:327 unmodified linesmodified:CHANGES.rst+5 added
45 unmodified lines46 2.0.x. Use ``response.request.environ`` instead. :pr:`4341`47 - Fix type annotation for ``errorhandler`` decorator. :issue:`4295`48 - Revert a change to the CLI that caused it to hide ``ImportError``49 tracebacks when importing the application. :issue:`4307`50+- ``app.json_encoder`` and ``json_decoder`` are only passed to51+ ``dumps`` and ``loads`` if they have custom behavior. This improves52+ performance, mainly on PyPy. :issue:`4349`53+- Clearer error message when ``after_this_request`` is used outside a54+ request context. :issue:`4333`55 56 57 Version 2.0.258 -------------1180 unmodified lines