Skip to content

Commit

Permalink
Merge pull request #98 from dapper91/dev
Browse files Browse the repository at this point in the history
- client headers passing bug fixed.
  • Loading branch information
dapper91 authored Nov 28, 2023
2 parents 21edb43 + cbe54a0 commit d404454
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 104 deletions.
15 changes: 10 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ default_stages:

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: check-yaml
- id: check-toml
Expand All @@ -25,21 +25,21 @@ repos:
args:
- --fix=no
- repo: https://github.com/asottile/add-trailing-comma
rev: v3.0.0
rev: v3.1.0
hooks:
- id: add-trailing-comma
stages:
- commit
- repo: https://github.com/pre-commit/mirrors-autopep8
rev: v2.0.2
rev: v2.0.4
hooks:
- id: autopep8
stages:
- commit
args:
- --diff
- repo: https://github.com/pycqa/flake8
rev: 6.0.0
rev: 6.1.0
hooks:
- id: flake8
- repo: https://github.com/pycqa/isort
Expand All @@ -63,11 +63,16 @@ repos:
- --multi-line=9
- --project=pjrpc
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.4.1
rev: v1.7.1
hooks:
- id: mypy
stages:
- commit
name: mypy
pass_filenames: false
args: ["--package", "pjrpc"]
additional_dependencies:
- aiohttp>=3.7
- httpx>=0.23.0
- pydantic>=2.0
- types-requests>=2.0
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

1.8.1 (2023-11-28)
------------------

- client headers passing bug fixed.


1.8.0 (2023-09-26)
------------------

Expand Down
2 changes: 1 addition & 1 deletion examples/aio_pika_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def add_user(message: aio_pika.IncomingMessage, user_info: UserInfo) -> AddedUse


executor = integration.Executor(
broker_url=URL('amqp://guest:guest@localhost:5672/v1'), queue_name='jsonrpc'
broker_url=URL('amqp://guest:guest@localhost:5672/v1'), queue_name='jsonrpc',
)
executor.dispatcher.add_methods(methods)

Expand Down
2 changes: 1 addition & 1 deletion pjrpc/__about__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
__description__ = 'Extensible JSON-RPC library'
__url__ = 'https://github.com/dapper91/pjrpc'

__version__ = '1.8.0'
__version__ = '1.8.1'

__author__ = 'Dmitry Pershin'
__email__ = '[email protected]'
Expand Down
6 changes: 2 additions & 4 deletions pjrpc/client/backend/aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ async def _request(self, request_text: str, is_notification: bool = False, **kwa
:returns: response text
"""

kwargs = {
'headers': {'Content-Type': pjrpc.common.DEFAULT_CONTENT_TYPE},
**kwargs,
}
headers = kwargs.setdefault('headers', {})
headers['Content-Type'] = pjrpc.common.DEFAULT_CONTENT_TYPE

resp = await self._session.post(self._endpoint, data=request_text, **kwargs)
resp.raise_for_status()
Expand Down
14 changes: 5 additions & 9 deletions pjrpc/client/backend/httpx.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Any, Dict, List, Optional
from typing import Any, List, Optional

import httpx

Expand Down Expand Up @@ -29,10 +29,8 @@ def _request(self, request_text: str, is_notification: bool = False, **kwargs: A
:returns: response text
"""

kwargs: Dict[str, Any] = {
'headers': {'Content-Type': pjrpc.common.DEFAULT_CONTENT_TYPE},
**kwargs,
}
headers = kwargs.setdefault('headers', {})
headers['Content-Type'] = pjrpc.common.DEFAULT_CONTENT_TYPE

resp = self._client.post(self._endpoint, content=request_text, **kwargs)
resp.raise_for_status()
Expand Down Expand Up @@ -84,10 +82,8 @@ async def _request(self, request_text: str, is_notification: bool = False, **kwa
:returns: response text
"""

kwargs: Dict[str, Any] = {
'headers': {'Content-Type': pjrpc.common.DEFAULT_CONTENT_TYPE},
**kwargs,
}
headers = kwargs.setdefault('headers', {})
headers['Content-Type'] = pjrpc.common.DEFAULT_CONTENT_TYPE

resp = await self._client.post(self._endpoint, content=request_text, **kwargs)
resp.raise_for_status()
Expand Down
6 changes: 2 additions & 4 deletions pjrpc/client/backend/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ def _request(self, request_text: str, is_notification: bool = False, **kwargs: A
:returns: response text
"""

kwargs = {
'headers': {'Content-Type': pjrpc.common.DEFAULT_CONTENT_TYPE},
**kwargs,
}
headers = kwargs.setdefault('headers', {})
headers['Content-Type'] = pjrpc.common.DEFAULT_CONTENT_TYPE

resp = self._session.post(self._endpoint, data=request_text, **kwargs)
resp.raise_for_status()
Expand Down
11 changes: 2 additions & 9 deletions pjrpc/common/common.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
import json
import sys
from typing import Any, Dict, TypeVar, Union

if sys.version_info >= (3, 8):
from typing import Literal
FalseType = Literal[False]
else:
FalseType = bool
from typing import Any, Dict, Literal, TypeVar, Union

import pjrpc
from pjrpc.common.typedefs import Json # noqa: for back compatibility
Expand All @@ -18,7 +11,7 @@ class UnsetType:
Used to distinct unset (missing) values from ``None`` ones.
"""

def __bool__(self) -> FalseType:
def __bool__(self) -> Literal[False]:
return False

def __repr__(self) -> str:
Expand Down
9 changes: 4 additions & 5 deletions pjrpc/server/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,13 +537,12 @@ async def dispatch(self, request_text: str, context: Optional[Any] = None) -> Op
else:
if isinstance(request, BatchRequest):
response = self._batch_response(
*filter(
lambda resp: resp is not UNSET, await asyncio.gather(
*(self._handle_request(request, context) for request in request),
),
*(
resp
for resp in await asyncio.gather(*(self._handle_request(req, context) for req in request))
if resp
),
)

else:
response = await self._handle_request(request, context)

Expand Down
2 changes: 1 addition & 1 deletion pjrpc/server/validators/pydantic.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def __init__(self, coerce: bool = True, **config_args: Any):
config_args.setdefault('extra', 'forbid')

# https://pydantic-docs.helpmanual.io/usage/model_config/
self._model_config = pydantic.ConfigDict(**config_args)
self._model_config = pydantic.ConfigDict(**config_args) # type: ignore[typeddict-item]

def validate_method(
self, method: Callable[..., Any], params: Optional['JsonRpcParams'], exclude: Iterable[str] = (), **kwargs: Any,
Expand Down
65 changes: 5 additions & 60 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "pjrpc"
version = "1.8.0"
version = "1.8.1"
description = "Extensible JSON-RPC library"
authors = ["Dmitry Pershin <[email protected]>"]
license = "Unlicense"
Expand All @@ -22,6 +22,7 @@ classifiers = [
"Framework :: Django",
"Framework :: Flask",
"Framework :: Pytest",
"Typing :: Typed",
"Topic :: Internet :: WWW/HTTP",
"Topic :: Software Development :: Libraries",
"Topic :: Software Development :: Libraries :: Application Frameworks",
Expand Down Expand Up @@ -78,7 +79,7 @@ docs = [
'aiohttp', 'aio-pika', 'flask', 'jsonschema', 'pydantic', 'requests', 'kombu'
]

[tool.poetry.dev-dependencies]
[tool.poetry.group.dev.dependencies]
aioresponses = "^0.7.4"
asynctest = "^0.13.0"
codecov = "^2.1.13"
Expand All @@ -88,8 +89,8 @@ pytest-cov = "^4.1.0"
pytest-mock = "^3.11.1"
responses = "^0.23.3"
respx = "^0.20.2"
mypy = "^1.4.1"
pre-commit = "^2.19"
mypy = "^1.7.1"
pre-commit = "~3.2.0"

[build-system]
requires = ["poetry-core>=1.0.0"]
Expand All @@ -107,62 +108,6 @@ strict_equality = true
warn_unused_ignores = true


[[tool.mypy.overrides]]
module = "aiohttp.*"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "aio_pika.*"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "docstring_parser.*"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "django.*"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "flask.*"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "jsonschema.*"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "starlette.*"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "openapi_ui_bundles.*"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "werkzeug.*"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "httpx.*"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "kombu.*"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "pydantic.*"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "pytest.*"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "requests.*"
ignore_missing_imports = true

[[tool.mypy.overrides]]
module = "yarl.*"
ignore_missing_imports = true
10 changes: 5 additions & 5 deletions tests/server/test_werkzeug.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def test_request(json_rpc, path, mocker, request_id, params, result):
test_response = cli.post(
path, json=v20.Request(method=method_name, params=params, id=request_id).to_json(),
)
if type(test_response) == tuple: # werkzeug 1.0
if type(test_response) is tuple: # werkzeug 1.0
body_iter, code, header = test_response
body = b''.join(body_iter)
else: # werkzeug >= 2.1
Expand Down Expand Up @@ -72,7 +72,7 @@ def test_notify(json_rpc, path, mocker):
test_response = cli.post(
path, json=v20.Request(method=method_name, params=params).to_json(),
)
if type(test_response) == tuple: # werkzeug 1.0
if type(test_response) is tuple: # werkzeug 1.0
body_iter, code, header = test_response
body = b''.join(body_iter)
else: # werkzeug >= 2.1
Expand All @@ -98,7 +98,7 @@ def error_method(*args, **kwargs):
test_response = cli.post(
path, json=v20.Request(method='unknown_method', params=params, id=request_id).to_json(),
)
if type(test_response) == tuple: # werkzeug 1.0
if type(test_response) is tuple: # werkzeug 1.0
body_iter, code, header = test_response
body = b''.join(body_iter)
else: # werkzeug >= 2.1
Expand All @@ -114,7 +114,7 @@ def error_method(*args, **kwargs):
test_response = cli.post(
path, json=v20.Request(method=method_name, params=params, id=request_id).to_json(),
)
if type(test_response) == tuple: # werkzeug 1.0
if type(test_response) is tuple: # werkzeug 1.0
body_iter, code, header = test_response
body = b''.join(body_iter)
else: # werkzeug >= 2.1
Expand All @@ -131,7 +131,7 @@ def error_method(*args, **kwargs):
test_response = cli.post(
path, headers={'Content-Type': 'application/json'}, data='',
)
if type(test_response) == tuple: # werkzeug 1.0
if type(test_response) is tuple: # werkzeug 1.0
body_iter, code, header = test_response
body = b''.join(body_iter)
else:
Expand Down

0 comments on commit d404454

Please sign in to comment.