Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consolidate AcceptXXXHeader classes into Accept #460

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 34 additions & 5 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,21 @@ Feature

- Add Request.remote_host, exposing REMOTE_HOST environment variable.

- Added ``acceptparse.Accept.parse_offer`` to codify what types of offers
are compatible with ``acceptparse.AcceptValidHeader.acceptable_offers``,
``acceptparse.AcceptMissingHeader.acceptable_offers``, and
``acceptparse.AcceptInvalidHeader.acceptable_offers``. This API also
normalizes the offer with lowercased type/subtype and parameter names.
- Added ``webob.acceptparse.Accept.parse_offer`` to codify what types of offers
are compatible with ``webob.acceptparse.Accept.acceptable_offers``. This API
also normalizes the offer with lowercased type/subtype and parameter names.
See https://github.com/Pylons/webob/pull/376 and
https://github.com/Pylons/webob/pull/379

- Consolidation of ``Accept`` header handling into a single class.
See backward incompatibilities below for more information.
See https://github.com/Pylons/webob/pull/460

- ``webob.acceptparse.Accept``, methods ``best_match``, ``quality``, and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would "webob.acceptparse.Accept's methods...", without the comma, be clearer?

``__contains__`` are undeprecated and their logic is made consistent with
``acceptable_offers``. See backward incompatibilities below.
See https://github.com/Pylons/webob/pull/460

Compatibility
~~~~~~~~~~~~~

Expand All @@ -27,6 +34,28 @@ Backwards Incompatibilities

- Drop support for Python 2.7, 3.4, 3.5, 3.6, and 3.7.

- Remove ``AcceptValidHeader``, ``AcceptNoHeader`` and ``AcceptInvalidHeader``.
These classes are consolidated into ``Accept`` with a ``header_state``
attribute for users that need to know the exact state of the header.
See https://github.com/Pylons/webob/pull/460

- Remove previously-deprecated ``webob.acceptparse.MIMEAccept``.
See https://github.com/Pylons/webob/pull/460

- Remove previously-deprecated ``webob.acceptparse.Accept.__iter__``.
See https://github.com/Pylons/webob/pull/460

- ``webob.acceptparse.Accept`` methods, ``best_match``, ``quality``, and
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would "webob.acceptparse.Accept's methods best_match, ..." be clearer?

``__contains__`` are now thin wrappers around ``acceptable_offers`` which
modifies their behavior slightly:

- Offers containing wildcards are no longer allowed.
- A tuple can no longer be an offer containing server-side quality values.
- An offer will only match a wildcard clause in the header, such as ``*/*``
or ``text/*`` if it does not match something more specific.
Comment on lines +50 to +55
Copy link
Contributor

@whiteroses whiteroses Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I remember correctly, their behaviour has been modified more than slightly: the switch from the old algorithms to the one in .acceptable_offers involved many changes - some of which were documented in several of the docstrings that are being removed, but even those docstrings didn't include everything. As these methods have been deprecated for such a long time, it may be more helpful and accurate/precise to say that the methods have switched to using the algorithm in .acceptable_offers to conform to RFC 7231?

(I also had trouble understanding "A tuple can no longer be an offer containing server-side quality values." - is it saying that offers can no longer contain server-side quality values?)

(The same text is used in the docstrings of .best_match, .quality and .__contains__, so this also applies to them.)


See https://github.com/Pylons/webob/pull/460

Experimental Features
~~~~~~~~~~~~~~~~~~~~~

Expand Down
44 changes: 15 additions & 29 deletions docs/api/webob.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,85 +23,71 @@ a certain type:
The classes that may be returned by one of the functions above, and their
methods:

.. autoclass:: Accept
:members: parse

.. autoclass:: AcceptOffer
:members: __str__

.. autoclass:: AcceptValidHeader
:members: parse, header_value, parsed, __init__, __add__, __bool__,
__contains__, __iter__, __radd__, __repr__, __str__,
accept_html, accepts_html, acceptable_offers, best_match, quality

.. autoclass:: AcceptNoHeader
:members: parse, header_value, parsed, __init__, __add__, __bool__,
__contains__, __iter__, __radd__, __repr__, __str__,
accept_html, accepts_html, acceptable_offers, best_match, quality
.. autoenum:: HeaderState
Comment on lines 23 to +29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"and their methods" makes the sentence quite ambiguous, and as the documentation for the classes also includes their non-method attributes, perhaps "and their methods" could be removed? (Assuming I'm reading the intended meaning correctly.)

Under this, AcceptOffer and HeaderState are included - but they are not classes that "may be returned by one of the functions above"?


.. autoclass:: AcceptInvalidHeader
:members: parse, header_value, parsed, __init__, __add__, __bool__,
__contains__, __iter__, __radd__, __repr__, __str__,
accept_html, accepts_html, acceptable_offers, best_match, quality
.. autoclass:: Accept
:members:
parse, header_value, parsed, header_state, __init__, __add__,
__bool__, __radd__, __repr__, __str__, __contains__,
accept_html, accepts_html, acceptable_offers, best_match, quality

.. autoclass:: AcceptCharset
:members: parse

.. autoclass:: AcceptCharsetValidHeader
:members: parse, header_value, parsed, __init__, __add__, __bool__,
__contains__, __iter__, __radd__, __repr__, __str__,
__contains__, __iter__, __radd__, __repr__, __str__,
acceptable_offers, best_match, quality

.. autoclass:: AcceptCharsetNoHeader
:members: parse, header_value, parsed, __init__, __add__, __bool__,
__contains__, __iter__, __radd__, __repr__, __str__,
__contains__, __iter__, __radd__, __repr__, __str__,
acceptable_offers, best_match, quality

.. autoclass:: AcceptCharsetInvalidHeader
:members: parse, header_value, parsed, __init__, __add__, __bool__,
__contains__, __iter__, __radd__, __repr__, __str__,
__contains__, __iter__, __radd__, __repr__, __str__,
acceptable_offers, best_match, quality

.. autoclass:: AcceptEncoding
:members: parse

.. autoclass:: AcceptEncodingValidHeader
:members: parse, header_value, parsed, __init__, __add__, __bool__,
__contains__, __iter__, __radd__, __repr__, __str__,
__contains__, __iter__, __radd__, __repr__, __str__,
acceptable_offers, best_match, quality

.. autoclass:: AcceptEncodingNoHeader
:members: parse, header_value, parsed, __init__, __add__, __bool__,
__contains__, __iter__, __radd__, __repr__, __str__,
__contains__, __iter__, __radd__, __repr__, __str__,
acceptable_offers, best_match, quality

.. autoclass:: AcceptEncodingInvalidHeader
:members: parse, header_value, parsed, __init__, __add__, __bool__,
__contains__, __iter__, __radd__, __repr__, __str__,
__contains__, __iter__, __radd__, __repr__, __str__,
acceptable_offers, best_match, quality

.. autoclass:: AcceptLanguage
:members: parse

.. autoclass:: AcceptLanguageValidHeader
:members: header_value, parsed, __init__, __add__, __contains__, __iter__,
__radd__, __str__, parse, basic_filtering, best_match, lookup,
__radd__, __str__, parse, basic_filtering, best_match, lookup,
quality

.. autoclass:: AcceptLanguageNoHeader
:members: header_value, parsed, __init__, __add__, __contains__, __iter__,
__radd__, __str__, parse, basic_filtering, best_match, lookup,
__radd__, __str__, parse, basic_filtering, best_match, lookup,
quality

.. autoclass:: AcceptLanguageInvalidHeader
:members: header_value, parsed, __init__, __add__, __contains__, __iter__,
__radd__, __str__, parse, basic_filtering, best_match, lookup,
__radd__, __str__, parse, basic_filtering, best_match, lookup,
quality

Deprecated:

.. autoclass:: MIMEAccept


Cache-Control
~~~~~~~~~~~~~
Expand Down
5 changes: 3 additions & 2 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import pkg_resources
import importlib.metadata
import sys
import os
import shlex

extensions = [
"sphinx.ext.autodoc",
"sphinx.ext.intersphinx",
"enum_tools.autoenum",
]

# Add any paths that contain templates here, relative to this directory.
Expand All @@ -27,7 +28,7 @@
copyright = "2018, Ian Bicking, Pylons Project and contributors"
author = "Ian Bicking, Pylons Project, and contributors"

version = release = pkg_resources.get_distribution("webob").version
version = release = importlib.metadata.distribution("webob").version

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
4 changes: 3 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ license_file = docs/license.txt
python_files = test_*.py
testpaths =
tests
addopts = -W always --cov --cov-report=term-missing
addopts = --cov --cov-report=term-missing
filterwarnings =
always
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
"pytest-xdist",
]

docs_extras = ["Sphinx >= 1.7.5", "pylons-sphinx-themes"]
docs_extras = [
"Sphinx >= 1.7.5",
"pylons-sphinx-themes",
"enum-tools[sphinx]",
]

setup(
name="WebOb",
Expand Down
Loading