Skip to content

Commit

Permalink
Merge pull request #44 from Ousret/develop
Browse files Browse the repository at this point in the history
Release 2.2.4
  • Loading branch information
Ousret authored Jan 27, 2021
2 parents 8377579 + c5cbacb commit 411c38d
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 28 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@ python:
- "3.6"
- "3.7"
- "3.8"
- "3.9-dev"
- "3.9"
- "pypy3"

jobs:
allow_failures:
- python: "3.5"
- python: "3.9-dev" # See https://github.com/python/mypy/issues/8627
- python: "pypy3"

before_install:
Expand All @@ -27,7 +26,7 @@ script:
- export SOURCE_FILES="kiss_headers tests"
- black --check --diff --target-version=py36 $SOURCE_FILES
- mypy kiss_headers
- isort --check --diff --project=kiss_headers --recursive $SOURCE_FILES
- isort --check --diff --project=kiss_headers $SOURCE_FILES
- pytest

after_success:
Expand Down
3 changes: 3 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
include LICENSE
include README.md
include kiss_headers/py.typed
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<p align="center">
<sup>Object oriented headers, parser and builder.</sup><br>
<a href="https://travis-ci.org/Ousret/kiss-headers">
<img src="https://travis-ci.org/Ousret/kiss-headers.svg?branch=master"/>
<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" />
Expand Down
19 changes: 13 additions & 6 deletions kiss_headers/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
unquote,
)


"""
Use https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ to create subclasses of CustomHeader.
"""
Expand Down Expand Up @@ -143,7 +142,10 @@ class Accept(CustomHeader):
__tags__: List[str] = ["request"]

def __init__(
self, mime: str = "*/*", qualifier: float = 1.0, **kwargs: Optional[str],
self,
mime: str = "*/*",
qualifier: float = 1.0,
**kwargs: Optional[str],
):
"""
:param mime: Describe the MIME using this syntax <MIME_type/MIME_subtype>
Expand All @@ -169,7 +171,8 @@ def __init__(
args.update(kwargs)

super().__init__(
mime, **args,
mime,
**args,
)

def get_mime(self) -> Optional[str]:
Expand Down Expand Up @@ -326,7 +329,8 @@ def __init__(
args.update(kwargs)

super().__init__(
disposition, **args,
disposition,
**args,
)

def get_disposition(self) -> Optional[str]:
Expand Down Expand Up @@ -812,7 +816,9 @@ class TransferEncoding(CustomHeader):
__squash__: bool = True

def __init__(
self, method: str, **kwargs: Optional[str],
self,
method: str,
**kwargs: Optional[str],
):
"""
:param method: Either chunked, compress, deflate, gzip, identity or br.
Expand Down Expand Up @@ -1106,7 +1112,8 @@ def __init__(
args.update(kwargs)

super().__init__(
language, **args,
language,
**args,
)

def get_qualifier(self, _default: Optional[float] = 1.0) -> Optional[float]:
Expand Down
30 changes: 15 additions & 15 deletions kiss_headers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ def pop(

if isinstance(__index, int):
__index = __index if __index >= 0 else __index % len(self._attrs)
key, value = self._attrs[__index]
key, value = self._attrs[__index] # type: ignore
elif isinstance(__index, str):
key, value = __index, self._attrs[__index] # type: ignore
else:
Expand Down Expand Up @@ -455,7 +455,7 @@ def attrs(self) -> List[str]:
return attrs

for i in range(0, len(self._attrs)):
attr, value = self._attrs[i]
attr, value = self._attrs[i] # type: ignore
attrs.append(attr)

return attrs
Expand All @@ -475,7 +475,7 @@ def valued_attrs(self) -> List[str]:
return attrs

for i in range(0, len(self._attrs)):
attr, value = self._attrs[i]
attr, value = self._attrs[i] # type: ignore

if value is not None and attr not in attrs:
attrs.append(attr)
Expand Down Expand Up @@ -648,10 +648,10 @@ def __init__(self, *headers: Union[List[Header], Header]):
"""
:param headers: Initial list of header. Can be empty.
"""
self._headers: List[Header] = headers[0] if len(headers) == 1 and isinstance(
headers[0], list
) else list(
headers # type: ignore
self._headers: List[Header] = (
headers[0]
if len(headers) == 1 and isinstance(headers[0], list)
else list(headers) # type: ignore
)

def has(self, header: str) -> bool:
Expand Down Expand Up @@ -706,13 +706,13 @@ def keys(self) -> List[str]:

return keys

def values(self) -> NotImplemented:
def values(self) -> None:
"""
I choose not to implement values() on Headers as it would bring more confusion...
Either we make it the same len as keys() or we don't. Either way don't please me. Hope to hear from the
community about this.
"""
return NotImplemented
raise NotImplementedError

def items(self) -> List[Tuple[str, str]]:
"""
Expand Down Expand Up @@ -1101,9 +1101,9 @@ def index(
"""

value_is_header: bool = isinstance(__value, Header)
normalized_value: Optional[str] = normalize_str(
__value # type: ignore
) if not value_is_header else None
normalized_value: Optional[str] = (
normalize_str(__value) if not value_is_header else None # type: ignore
)
headers_len: int = len(self)

# Convert indices to positive indices
Expand Down Expand Up @@ -1218,7 +1218,7 @@ def __str__(self) -> str:
return content

for i in range(0, len(self)):
key, value = self[i]
key, value = self[i] # type: ignore

if value is not None:
content += '{semi_colon_r}{key}="{value}"'.format(
Expand Down Expand Up @@ -1429,7 +1429,7 @@ def __contains__(self, item: Union[str, Dict[str, Union[List[str], str]]]) -> bo
target_key = normalize_str(target_key)

for i in range(0, len(self)):
key, value = self[i]
key, value = self[i] # type: ignore

if target_key == key and target_value == value:
return True
Expand Down Expand Up @@ -1463,7 +1463,7 @@ def __iter__(self) -> Iterator[Tuple[int, str, Optional[str]]]:
"""Provide an iterator over all attributes with or without associated value.
For each entry, output a tuple of index, attribute and a optional value."""
for i in range(0, len(self)):
key, value = self[i]
key, value = self[i] # type: ignore
yield i, key, value


Expand Down
1 change: 0 additions & 1 deletion kiss_headers/structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from kiss_headers.utils import normalize_str


"""
Disclaimer : CaseInsensitiveDict has been borrowed from `psf/requests`.
Minors changes has been made.
Expand Down
8 changes: 7 additions & 1 deletion kiss_headers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,10 +379,16 @@ def is_legal_header_name(name: str) -> bool:
False
>>> is_legal_header_name("Hello \\tWorld")
False
>>> is_legal_header_name('Hello World"')
False
>>> is_legal_header_name("Hello-World/")
True
>>> is_legal_header_name("\x07")
False
"""
return (
name != ""
and search(r"[^\x00-\x7F]|[:;(),<>=@?\[\]\r\n\t &{}\\]", name) is None
and search(r"[^\x21-\x7F]|[:;(),<>=@?\[\]\r\n\t &{}\"\\]", name) is None
)


Expand Down
2 changes: 1 addition & 1 deletion kiss_headers/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
Expose version
"""

__version__ = "2.2.3"
__version__ = "2.2.4"
VERSION = __version__.split(".")

0 comments on commit 411c38d

Please sign in to comment.