Skip to content

Commit

Permalink
Release 2.3.1 (#48)
Browse files Browse the repository at this point in the history
* ❇️ Migrate to GHA
* ❇️ Add support 3.11 explicit
* ❇️ Add __all__ to top-level package init
  • Loading branch information
Ousret authored Apr 16, 2022
1 parent 2a2eaf9 commit e079c36
Show file tree
Hide file tree
Showing 9 changed files with 363 additions and 223 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: 🎨 Linters

on: [push, pull_request]

jobs:
lint:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
python-version: [3.9]
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -U pip setuptools
pip install -r dev-requirements.txt
- name: Install the package
run: |
python setup.py install
- name: Type checking (Mypy)
run: |
mypy kiss_headers
- name: Import sorting check (isort)
run: |
isort --check kiss_headers
- name: Code format (Black)
run: |
black --check --diff --target-version=py36 kiss_headers
31 changes: 31 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Tests

on: [push, pull_request]

jobs:
tests:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false
matrix:
python-version: [3.6, 3.7, 3.8, 3.9, "3.10", "3.11.0-alpha.7"]
os: [ubuntu-latest]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
pip install -U pip setuptools
pip install -r dev-requirements.txt
- name: Install the package
run: |
python setup.py install
- name: Run tests
run: |
pytest
- uses: codecov/codecov-action@v1
33 changes: 0 additions & 33 deletions .travis.yml

This file was deleted.

7 changes: 4 additions & 3 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
include LICENSE
include README.md
include kiss_headers/py.typed
include LICENSE README.md kiss_headers/py.typed dev-requirements.txt UPGRADE.md
include kiss_headers/py.typed
recursive-include docs *
recursive-include tests *
71 changes: 56 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,12 @@

<p align="center">
<sup>Object-oriented headers. Kind of structured headers.</sup><br>
<a href="https://travis-ci.org/Ousret/kiss-headers">
<img src="https://travis-ci.com/Ousret/kiss-headers.svg?branch=master"/>
</a>
<a href='https://pypi.org/project/kiss-headers/'>
<img src="https://img.shields.io/pypi/pyversions/kiss-headers.svg?orange=blue" />
</a>
<a href="https://www.codacy.com/manual/Ousret/kiss-headers?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=Ousret/kiss-headers&amp;utm_campaign=Badge_Grade">
<img src="https://api.codacy.com/project/badge/Grade/0994a03546094b519601e33554c48535"/>
</a>
<a href="https://codecov.io/gh/Ousret/kiss-headers">
<img src="https://codecov.io/gh/Ousret/kiss-headers/branch/master/graph/badge.svg" />
</a>
<a href='https://pypi.org/project/kiss-headers/'>
<img src='https://badge.fury.io/py/kiss-headers.svg' alt='PyPi Publish Action' />
</a>
<a href="https://github.com/psf/black">
<img alt="Code style: black" src="https://img.shields.io/badge/code%20style-black-000000.svg">
</a>
<a href="http://mypy-lang.org/">
<img alt="Checked with mypy" src="http://www.mypy-lang.org/static/mypy_badge.svg"/>
</a>
<a href="https://pepy.tech/project/kiss-headers/">
<img alt="Download Count Total" src="https://pepy.tech/badge/kiss-headers" />
</a>
Expand All @@ -40,6 +25,17 @@ I have seen so many chunks of code trying to deal with these headers; often I sa
```python
# No more of that!
charset = headers['Content-Type'].split(';')[-1].split('=')[-1].replace('"', '')
# That too..
response = get(
"https://httpbin.org/headers",
headers={
"user-agent": "custom/2.22",
"referer": "https://www.google.com",
"accept": "text/html",
"accept-language": "en-US",
"custom-header-xyz": "hello; charset=utf-8"
}
)
```

**Scroll down and see how you could do it from now on.**
Expand Down Expand Up @@ -93,6 +89,51 @@ headers.content_type.charset # output: ISO-8859-1
headers["content-type"]["charset"] # output: ISO-8859-1
```

and also, the other way around:

```python
from requests import get
from kiss_headers import Headers, UserAgent, Referer, UpgradeInsecureRequests, Accept, AcceptLanguage, CustomHeader

class CustomHeaderXyz(CustomHeader):

__squash__ = False

def __init__(self, charset: str = "utf-8"):
super().__init__("hello", charset=charset)

# Officially supported with requests
response = get(
"https://httpbin.org/headers",
headers=Headers(
UserAgent("custom/2.22"),
Referer("https://www.google.com"),
UpgradeInsecureRequests(),
Accept("text/html"),
AcceptLanguage("en-US"),
CustomHeaderXyz()
)
)
```

httpbin should get back with:

```json
{
"headers": {
"Accept": "text/html",
"Accept-Encoding": "identity",
"Accept-Language": "en-US",
"Custom-Header-Xyz": "hello; charset=\"utf-8\"",
"Host": "httpbin.org",
"Referer": "https://www.google.com",
"Upgrade-Insecure-Requests": "1",
"User-Agent": "custom/2.22",
"X-Amzn-Trace-Id": "Root=1-622sz46b-973c5671113f58d611972de"
}
}
```

Do not forget that headers are not OneToOne. One header can be repeated multiple times and attributes can have multiple values within the same header.

```python
Expand Down
File renamed without changes.
Loading

0 comments on commit e079c36

Please sign in to comment.