Skip to content

Commit

Permalink
remove previously deprecated code (#2768)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism authored Aug 14, 2023
2 parents 43d6cdc + 5ff0a57 commit ea77ffd
Show file tree
Hide file tree
Showing 23 changed files with 187 additions and 3,027 deletions.
21 changes: 11 additions & 10 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ Version 3.0.0

Unreleased

- Remove previously deprecated code. :pr:`2768`


Version 2.3.8
-------------
Expand Down Expand Up @@ -1031,7 +1033,7 @@ Released 2019-03-19
(:pr:`1358`)
- :func:`http.parse_cookie` ignores empty segments rather than
producing a cookie with no key or value. (:issue:`1245`, :pr:`1301`)
- :func:`~http.parse_authorization_header` (and
- ``http.parse_authorization_header`` (and
:class:`~datastructures.Authorization`,
:attr:`~wrappers.Request.authorization`) treats the authorization
header as UTF-8. On Python 2, basic auth username and password are
Expand Down Expand Up @@ -1796,8 +1798,8 @@ Version 0.9.2

(bugfix release, released on July 18th 2013)

- Added `unsafe` parameter to :func:`~werkzeug.urls.url_quote`.
- Fixed an issue with :func:`~werkzeug.urls.url_quote_plus` not quoting
- Added ``unsafe`` parameter to ``urls.url_quote``.
- Fixed an issue with ``urls.url_quote_plus`` not quoting
`'+'` correctly.
- Ported remaining parts of :class:`~werkzeug.contrib.RedisCache` to
Python 3.3.
Expand Down Expand Up @@ -1846,9 +1848,8 @@ Released on June 13nd 2013, codename Planierraupe.
certificates easily and load them from files.
- Refactored test client to invoke the open method on the class
for redirects. This makes subclassing more powerful.
- :func:`werkzeug.wsgi.make_chunk_iter` and
:func:`werkzeug.wsgi.make_line_iter` now support processing of
iterators and streams.
- ``wsgi.make_chunk_iter`` and ``make_line_iter`` now support processing
of iterators and streams.
- URL generation by the routing system now no longer quotes
``+``.
- URL fixing now no longer quotes certain reserved characters.
Expand Down Expand Up @@ -1946,7 +1947,7 @@ Version 0.8.3

(bugfix release, released on February 5th 2012)

- Fixed another issue with :func:`werkzeug.wsgi.make_line_iter`
- Fixed another issue with ``wsgi.make_line_iter``
where lines longer than the buffer size were not handled
properly.
- Restore stdout after debug console finished executing so
Expand Down Expand Up @@ -2014,7 +2015,7 @@ Released on September 29th 2011, codename Lötkolben
- Werkzeug now uses a new method to check that the length of incoming
data is complete and will raise IO errors by itself if the server
fails to do so.
- :func:`~werkzeug.wsgi.make_line_iter` now requires a limit that is
- ``wsgi.make_line_iter`` now requires a limit that is
not higher than the length the stream can provide.
- Refactored form parsing into a form parser class that makes it possible
to hook into individual parts of the parsing process for debugging and
Expand Down Expand Up @@ -2214,7 +2215,7 @@ Released on Feb 19th 2010, codename Hammer.
- the form data parser will now look at the filename instead the
content type to figure out if it should treat the upload as regular
form data or file upload. This fixes a bug with Google Chrome.
- improved performance of `make_line_iter` and the multipart parser
- improved performance of ``make_line_iter`` and the multipart parser
for binary uploads.
- fixed :attr:`~werkzeug.BaseResponse.is_streamed`
- fixed a path quoting bug in `EnvironBuilder` that caused PATH_INFO and
Expand Down Expand Up @@ -2343,7 +2344,7 @@ Released on April 24th, codename Schlagbohrer.
- added :mod:`werkzeug.contrib.lint`
- added `passthrough_errors` to `run_simple`.
- added `secure_filename`
- added :func:`make_line_iter`
- added ``make_line_iter``
- :class:`MultiDict` copies now instead of revealing internal
lists to the caller for `getlist` and iteration functions that
return lists.
Expand Down
4 changes: 0 additions & 4 deletions docs/http.rst
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ by :rfc:`2616`, Werkzeug implements some custom data structures that are

.. autofunction:: parse_cache_control_header

.. autofunction:: parse_authorization_header

.. autofunction:: parse_www_authenticate_header

.. autofunction:: parse_if_range_header

.. autofunction:: parse_range_header
Expand Down
4 changes: 0 additions & 4 deletions docs/wsgi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ iterator and the input stream.
.. autoclass:: LimitedStream
:members:

.. autofunction:: make_line_iter

.. autofunction:: make_chunk_iter

.. autofunction:: wrap_file


Expand Down
124 changes: 4 additions & 120 deletions src/werkzeug/_internal.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from __future__ import annotations

import logging
import operator
import re
import sys
import typing as t
Expand All @@ -26,102 +25,12 @@ def __reduce__(self) -> str:
_missing = _Missing()


@t.overload
def _make_encode_wrapper(reference: str) -> t.Callable[[str], str]:
...


@t.overload
def _make_encode_wrapper(reference: bytes) -> t.Callable[[str], bytes]:
...


def _make_encode_wrapper(reference: t.AnyStr) -> t.Callable[[str], t.AnyStr]:
"""Create a function that will be called with a string argument. If
the reference is bytes, values will be encoded to bytes.
"""
if isinstance(reference, str):
return lambda x: x

return operator.methodcaller("encode", "latin1")

def _wsgi_decoding_dance(s: str) -> str:
return s.encode("latin1").decode(errors="replace")

def _check_str_tuple(value: tuple[t.AnyStr, ...]) -> None:
"""Ensure tuple items are all strings or all bytes."""
if not value:
return

item_type = str if isinstance(value[0], str) else bytes

if any(not isinstance(item, item_type) for item in value):
raise TypeError(f"Cannot mix str and bytes arguments (got {value!r})")


_default_encoding = sys.getdefaultencoding()


def _to_bytes(
x: str | bytes, charset: str = _default_encoding, errors: str = "strict"
) -> bytes:
if x is None or isinstance(x, bytes):
return x

if isinstance(x, (bytearray, memoryview)):
return bytes(x)

if isinstance(x, str):
return x.encode(charset, errors)

raise TypeError("Expected bytes")


@t.overload
def _to_str( # type: ignore
x: None,
charset: str | None = ...,
errors: str = ...,
allow_none_charset: bool = ...,
) -> None:
...


@t.overload
def _to_str(
x: t.Any,
charset: str | None = ...,
errors: str = ...,
allow_none_charset: bool = ...,
) -> str:
...


def _to_str(
x: t.Any | None,
charset: str | None = _default_encoding,
errors: str = "strict",
allow_none_charset: bool = False,
) -> str | bytes | None:
if x is None or isinstance(x, str):
return x

if not isinstance(x, (bytes, bytearray)):
return str(x)

if charset is None:
if allow_none_charset:
return x

return x.decode(charset, errors) # type: ignore


def _wsgi_decoding_dance(
s: str, charset: str = "utf-8", errors: str = "replace"
) -> str:
return s.encode("latin1").decode(charset, errors)


def _wsgi_encoding_dance(s: str, charset: str = "utf-8", errors: str = "strict") -> str:
return s.encode(charset).decode("latin1", errors)
def _wsgi_encoding_dance(s: str) -> str:
return s.encode().decode("latin1")


def _get_environ(obj: WSGIEnvironment | Request) -> WSGIEnvironment:
Expand Down Expand Up @@ -287,31 +196,6 @@ def __repr__(self) -> str:
return f"<{type(self).__name__} {self.name}>"


def _decode_idna(domain: str) -> str:
try:
data = domain.encode("ascii")
except UnicodeEncodeError:
# If the domain is not ASCII, it's decoded already.
return domain

try:
# Try decoding in one shot.
return data.decode("idna")
except UnicodeDecodeError:
pass

# Decode each part separately, leaving invalid parts as punycode.
parts = []

for part in data.split(b"."):
try:
parts.append(part.decode("idna"))
except UnicodeDecodeError:
parts.append(part.decode("ascii"))

return ".".join(parts)


_plain_int_re = re.compile(r"-?\d+", re.ASCII)


Expand Down
Loading

0 comments on commit ea77ffd

Please sign in to comment.