From d381049cfa75c7c0f34d01534dec6fdccd6f0bae Mon Sep 17 00:00:00 2001 From: TAHRI Ahmed R Date: Tue, 16 Jun 2020 17:23:17 +0200 Subject: [PATCH 01/12] Create MANIFEST.in --- MANIFEST.in | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 MANIFEST.in diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000..3bb94a0 --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,3 @@ +include LICENSE +include README.md +include kiss_headers/py.typed From 6128b6c9fc91b7d9dd35447c5509fde4f29fd69f Mon Sep 17 00:00:00 2001 From: Ahmed TAHRI Date: Wed, 27 Jan 2021 04:05:14 +0100 Subject: [PATCH 02/12] :bug: Improve is_legal_header_name fix issue #41 --- kiss_headers/utils.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/kiss_headers/utils.py b/kiss_headers/utils.py index ac427a1..2329aab 100644 --- a/kiss_headers/utils.py +++ b/kiss_headers/utils.py @@ -379,10 +379,18 @@ 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("\x00") + False + >>> 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 ) From 7928cfbc915a7cb4897a65ed6d7964638cc2c389 Mon Sep 17 00:00:00 2001 From: Ahmed TAHRI Date: Wed, 27 Jan 2021 04:24:42 +0100 Subject: [PATCH 03/12] :art: Small revision to fix mypy errors (due to newest mypy release) --- kiss_headers/models.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/kiss_headers/models.py b/kiss_headers/models.py index b59d510..1be074a 100644 --- a/kiss_headers/models.py +++ b/kiss_headers/models.py @@ -1,3 +1,4 @@ +from builtins import _NotImplementedType from copy import deepcopy from json import dumps from typing import Dict, Iterable, Iterator, List, Optional, Tuple, Type, Union @@ -170,7 +171,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: @@ -455,7 +456,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 @@ -475,7 +476,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) @@ -706,7 +707,7 @@ def keys(self) -> List[str]: return keys - def values(self) -> NotImplemented: + def values(self) -> _NotImplementedType: """ 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 @@ -1218,7 +1219,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( @@ -1429,7 +1430,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 @@ -1463,7 +1464,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 From 42ba2613eb930ca95c39df8529167d2a56374cfc Mon Sep 17 00:00:00 2001 From: Ahmed TAHRI Date: Wed, 27 Jan 2021 04:34:40 +0100 Subject: [PATCH 04/12] :bug: Fix method values() & NotImplemented --- kiss_headers/models.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/kiss_headers/models.py b/kiss_headers/models.py index 1be074a..dbb075a 100644 --- a/kiss_headers/models.py +++ b/kiss_headers/models.py @@ -1,4 +1,3 @@ -from builtins import _NotImplementedType from copy import deepcopy from json import dumps from typing import Dict, Iterable, Iterator, List, Optional, Tuple, Type, Union @@ -707,13 +706,13 @@ def keys(self) -> List[str]: return keys - def values(self) -> _NotImplementedType: + 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]]: """ From 8ff3b242b0846741a7626014294dcf159cd425f2 Mon Sep 17 00:00:00 2001 From: Ahmed TAHRI Date: Wed, 27 Jan 2021 04:38:38 +0100 Subject: [PATCH 05/12] :art: Reformat files --- kiss_headers/builder.py | 18 +++++++++++++----- kiss_headers/models.py | 14 +++++++------- 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/kiss_headers/builder.py b/kiss_headers/builder.py index 3e36b0f..687ea81 100644 --- a/kiss_headers/builder.py +++ b/kiss_headers/builder.py @@ -143,7 +143,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 @@ -169,7 +172,8 @@ def __init__( args.update(kwargs) super().__init__( - mime, **args, + mime, + **args, ) def get_mime(self) -> Optional[str]: @@ -326,7 +330,8 @@ def __init__( args.update(kwargs) super().__init__( - disposition, **args, + disposition, + **args, ) def get_disposition(self) -> Optional[str]: @@ -812,7 +817,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. @@ -1106,7 +1113,8 @@ def __init__( args.update(kwargs) super().__init__( - language, **args, + language, + **args, ) def get_qualifier(self, _default: Optional[float] = 1.0) -> Optional[float]: diff --git a/kiss_headers/models.py b/kiss_headers/models.py index dbb075a..4a515a1 100644 --- a/kiss_headers/models.py +++ b/kiss_headers/models.py @@ -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: @@ -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 From cef1e8a692acc2c9b2bdb2810b9fd56c687e9dfa Mon Sep 17 00:00:00 2001 From: Ahmed TAHRI Date: Wed, 27 Jan 2021 04:39:09 +0100 Subject: [PATCH 06/12] :wrench: drop --recursive arg with isort (travis) --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 1411dd6..93bf7d6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -27,7 +27,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: From e52d2799aabaefcc06a491f4d7b2e5145edac15e Mon Sep 17 00:00:00 2001 From: Ahmed TAHRI Date: Wed, 27 Jan 2021 04:39:36 +0100 Subject: [PATCH 07/12] :art: isort fix run --- kiss_headers/builder.py | 1 - kiss_headers/structures.py | 1 - 2 files changed, 2 deletions(-) diff --git a/kiss_headers/builder.py b/kiss_headers/builder.py index 687ea81..01c910a 100644 --- a/kiss_headers/builder.py +++ b/kiss_headers/builder.py @@ -14,7 +14,6 @@ unquote, ) - """ Use https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ to create subclasses of CustomHeader. """ diff --git a/kiss_headers/structures.py b/kiss_headers/structures.py index ba4a5dc..6213dc3 100644 --- a/kiss_headers/structures.py +++ b/kiss_headers/structures.py @@ -11,7 +11,6 @@ from kiss_headers.utils import normalize_str - """ Disclaimer : CaseInsensitiveDict has been borrowed from `psf/requests`. Minors changes has been made. From c48518113f0b15025a3a3d14d05e0bfd37a296d1 Mon Sep 17 00:00:00 2001 From: Ahmed TAHRI Date: Wed, 27 Jan 2021 04:45:40 +0100 Subject: [PATCH 08/12] :heavy_check_mark: Fix doctest case --- kiss_headers/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kiss_headers/utils.py b/kiss_headers/utils.py index 2329aab..544ac66 100644 --- a/kiss_headers/utils.py +++ b/kiss_headers/utils.py @@ -381,7 +381,7 @@ def is_legal_header_name(name: str) -> bool: False >>> is_legal_header_name('Hello World"') False - >>> is_legal_header_name("Hello World/") + >>> is_legal_header_name("Hello-World/") True >>> is_legal_header_name("\x00") False From 139931b4c6f3586067da47f48af8592cf2f2fec3 Mon Sep 17 00:00:00 2001 From: Ahmed TAHRI Date: Wed, 27 Jan 2021 04:46:25 +0100 Subject: [PATCH 09/12] :wrench: need to drop travis --- .travis.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 93bf7d6..89ac332 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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: From a7a0294328de9e01acd771a83f70dfb36b084ee5 Mon Sep 17 00:00:00 2001 From: Ahmed TAHRI Date: Wed, 27 Jan 2021 04:48:19 +0100 Subject: [PATCH 10/12] :heavy_check_mark: Remove doctest case with NULL char --- kiss_headers/utils.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/kiss_headers/utils.py b/kiss_headers/utils.py index 544ac66..c76f4f7 100644 --- a/kiss_headers/utils.py +++ b/kiss_headers/utils.py @@ -383,8 +383,6 @@ def is_legal_header_name(name: str) -> bool: False >>> is_legal_header_name("Hello-World/") True - >>> is_legal_header_name("\x00") - False >>> is_legal_header_name("\x07") False """ From b656c2aa60b20f843288960834577701e089b471 Mon Sep 17 00:00:00 2001 From: Ahmed TAHRI Date: Wed, 27 Jan 2021 05:03:43 +0100 Subject: [PATCH 11/12] :bookmark: Bump to 2.2.4 --- kiss_headers/version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kiss_headers/version.py b/kiss_headers/version.py index e9dab66..0dd6d9f 100644 --- a/kiss_headers/version.py +++ b/kiss_headers/version.py @@ -2,5 +2,5 @@ Expose version """ -__version__ = "2.2.3" +__version__ = "2.2.4" VERSION = __version__.split(".") From c5cbacb84bc88211adfacb03e742b776a3e16941 Mon Sep 17 00:00:00 2001 From: Ahmed TAHRI Date: Wed, 27 Jan 2021 05:04:10 +0100 Subject: [PATCH 12/12] :pencil: Update svg badge travis url --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7eed23f..1a05dcc 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@

Object oriented headers, parser and builder.
- +