Skip to content

Commit

Permalink
Merge pull request #10 from Ousret/release-1.1.1
Browse files Browse the repository at this point in the history
Release 1.1.1
  • Loading branch information
Ousret authored Mar 28, 2020
2 parents bf8483e + 181895b commit 71dfec3
Show file tree
Hide file tree
Showing 11 changed files with 257 additions and 99 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ python:
- "3.8"

install:
- pip install nose codecov black
- pip install nose codecov black requests httpx mypy
- python setup.py install

script:
- "black kiss_headers/ --check"
- "black tests/ --check"
- "black --check --diff --target-version=py36 kiss_headers/"
- "black --check --diff --target-version=py36 tests/"
- "mypy kiss_headers"
- "nosetests --with-coverage --cover-package=kiss_headers tests/*.py"

after_success:
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<img alt="Download Count /Month" src="https://pepy.tech/badge/kiss-headers/month"/>
</a>
<a href="https://github.com/ousret/kiss-headers/blob/master/LICENSE">
<img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-purple.svg" target="_blank" />
<img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-purple.svg" />
</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"/>
Expand All @@ -25,6 +25,9 @@
<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>
<img alt="Download Count Total" src="https://pepy.tech/badge/kiss-headers" />
</p>

Expand Down Expand Up @@ -58,7 +61,7 @@ Plus all the features that you would expect from handling headers...

* Properties syntax for headers and attribute in header.
* Supports headers and attributes OneToOne and OneToMany.
* Capable of parsing `bytes`, `fp`, `str`, `dict` and `requests.Response`.
* Capable of parsing `bytes`, `fp`, `str`, `dict`, `requests.Response` and `httpx._models.Response`.
* Automatically unquote value of an attribute when retrieving it.
* Case insensitive with header name and attribute key.
* Character `-` equal `_` in addition of above feature.
Expand All @@ -77,7 +80,7 @@ pip install kiss-headers

### 🍰 Usage

`parse_it()` method takes `bytes`, `str`, `fp`, `dict` or even `requests.Response` itself and returns a `Headers` object.
`parse_it()` method takes `bytes`, `str`, `fp`, `dict` or even `requests.Response` or `httpx._models.Response` itself and returns a `Headers` object.

```python
from requests import get
Expand All @@ -89,7 +92,7 @@ headers = parse_it(response)
headers.content_type.charset # output: ISO-8859-1
```

Do not forget that headers are not 1 to 1. One header can be repeated multiple times and attributes can have multiple values within the same header.
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
from kiss_headers import parse_it
Expand All @@ -103,6 +106,8 @@ type(headers.set_cookie) # output: list
headers.set_cookie[0].expires # output Wed, 15-Apr-2020 21:27:31 GMT
```

If this behaviour does bother you, you can lock output to always be a list. Just call `lock_output_type()` method.

Just a note: Accessing a header that has the same name as a reserved keyword must be done this way :
```python
headers = parse_it('From: Ousret; origin=www.github.com\nIS: 1\nWhile: Not-True')
Expand Down
2 changes: 1 addition & 1 deletion kiss_headers/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@
:license: MIT, see LICENSE for more details.
"""

from kiss_headers.utils import Headers, Header, parse_it
from kiss_headers.utils import Headers, Header, parse_it, lock_output_type
from kiss_headers.version import __version__, VERSION
6 changes: 3 additions & 3 deletions kiss_headers/structures.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from collections import MutableMapping, OrderedDict, Mapping
from typing import Any, NoReturn, Iterator, Tuple, Optional
from typing import Any, Iterator, Tuple, Optional

"""
Disclaimer : CaseInsensitiveDict has been borrowed from `psf/requests`.
Expand Down Expand Up @@ -40,15 +40,15 @@ def __init__(self, data: Optional[Mapping] = None, **kwargs):
data = {}
self.update(data, **kwargs)

def __setitem__(self, key: str, value: Any) -> NoReturn:
def __setitem__(self, key: str, value: Any):
# Use the lowercased key for lookups, but store the actual
# key alongside the value.
self._store[key.lower().replace("-", "_")] = (key, value)

def __getitem__(self, key: str) -> Any:
return self._store[key.lower().replace("-", "_")][1]

def __delitem__(self, key: str) -> NoReturn:
def __delitem__(self, key: str):
del self._store[key.lower().replace("-", "_")]

def __iter__(self) -> Iterator[Tuple[str, Any]]:
Expand Down
Loading

0 comments on commit 71dfec3

Please sign in to comment.