A library for deciding content-type based on media ranges in HTTP Accept headers.
Project description
content-negotiation
A small Python library for deciding content type based on a list of media ranges
Usage
Install
% pip install content-negotiation
Getting started
from content_negotiation import decide_content_type
accept_headers = ["application/json", "text/html", "text/plain, text/*;q=0.8"]
supported_content_types = ["text/turtle", "application/json"]
try:
content_type = decide_content_type(accept_headers, supported_content_types)
except NoAgreeableContentTypeError:
print("No agreeable content type found.")
# Handle error, by returning e.g. 406 Not Acceptable
Development
Requirements
% pipx install poetry==1.1.13
% pipx install nox==2022.1.7
% pipx inject nox nox-poetry==0.9.0
Install developer tools
% git clone https://github.com/Informasjonsforvaltning/content-negotiation.git
% cd content-negotiation
% pyenv install 3.8.12
% pyenv install 3.9.10
% pyenv local 3.8.12 3.9.10
% poetry install
Run all sessions
% nox
Run all tests with coverage reporting
% nox -rs tests
Debugging
You can enter into Pdb by passing --pdb
to pytest:
% nox -rs tests -- --pdb --log-cli-level=DEBUG
You can set breakpoints directly in code by using the function breakpoint()
.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for content-negotiation-1.0.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9717bb3a465f26e23d471498192a91aa612d3e7579c77899c9b884a1c79e5845 |
|
MD5 | a141ab12b2e5b24f317c4ca70642c881 |
|
BLAKE2b-256 | 405fda110cc69ca610a4356e8c814ad03681bca41cf9c68ee8f91cdfda9f6e19 |
Close
Hashes for content_negotiation-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5f94cdbe1b27cd5a9db63a77588712b5ecfcb1f93489378bb851ed6dbc99f4cc |
|
MD5 | 56a8cc8ad9eab6503306afb9317c3796 |
|
BLAKE2b-256 | b6dc3d96fb166ea238eded2286617d8db00767e13b868e11bf543396251c4885 |