Skip to content

Commit

Permalink
fix(transport): set update_kwargs return to the original kwargs
Browse files Browse the repository at this point in the history
Fixes: #16
  • Loading branch information
piraz committed Jun 21, 2024
1 parent 9d77511 commit 13857cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
19 changes: 7 additions & 12 deletions peasant/client/transport_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,6 @@ def get_headers(self, **kwargs):
headers.update(_headers)
return headers

def update_kwargs(self, method, **kwargs):
if self.kwargs_updater is None:
return kwargs
return self.kwargs_updater(method, **kwargs)

def delete(self, path: str, **kwargs):
""" Sends a delete method with basic headers.
Expand All @@ -74,7 +69,7 @@ def delete(self, path: str, **kwargs):
:return: :class:`requests.Response <Response>` object
:rtype: requests.Response
"""
self.update_kwargs("DELETE", **kwargs)
kwargs = self.update_kwargs("DELETE", **kwargs)
url = self.get_url(path, **kwargs)
headers = self.get_headers(**kwargs)
kwargs['headers'] = headers
Expand All @@ -91,7 +86,7 @@ def get(self, path, **kwargs):
:return: :class:`requests.Response <Response>` object
:rtype: requests.Response
"""
self.update_kwargs(METHOD_GET, **kwargs)
kwargs = self.update_kwargs(METHOD_GET, **kwargs)
url = self.get_url(path, **kwargs)
headers = self.get_headers(**kwargs)
kwargs['headers'] = headers
Expand All @@ -108,7 +103,7 @@ def head(self, path, **kwargs):
:return: :class:`requests.Response <Response>` object
:rtype: requests.Response
"""
self.update_kwargs(METHOD_HEAD, **kwargs)
kwargs = self.update_kwargs(METHOD_HEAD, **kwargs)
url = self.get_url(path, **kwargs)
headers = self.get_headers(**kwargs)
kwargs['headers'] = headers
Expand All @@ -125,7 +120,7 @@ def options(self, path, **kwargs):
:return: :class:`requests.Response <Response>` object
:rtype: requests.Response
"""
self.update_kwargs(METHOD_OPTIONS, **kwargs)
kwargs = self.update_kwargs(METHOD_OPTIONS, **kwargs)
url = self.get_url(path, **kwargs)
headers = self.get_headers(**kwargs)
kwargs['headers'] = headers
Expand All @@ -142,7 +137,7 @@ def patch(self, path, **kwargs):
:return: :class:`requests.Response <Response>` object
:rtype: requests.Response
"""
self.update_kwargs(METHOD_PATCH, **kwargs)
kwargs = self.update_kwargs(METHOD_PATCH, **kwargs)
url = self.get_url(path, **kwargs)
headers = self.get_headers(**kwargs)
kwargs['headers'] = headers
Expand All @@ -159,7 +154,7 @@ def post(self, path, **kwargs):
:return: :class:`requests.Response <Response>` object
:rtype: requests.Response
"""
self.update_kwargs(METHOD_POST, **kwargs)
kwargs = self.update_kwargs(METHOD_POST, **kwargs)
url = self.get_url(path, **kwargs)
headers = self.get_headers(**kwargs)
kwargs['headers'] = headers
Expand All @@ -176,7 +171,7 @@ def put(self, path, **kwargs):
:return: :class:`requests.Response <Response>` object
:rtype: requests.Response
"""
self.update_kwargs(METHOD_PUT, **kwargs)
kwargs = self.update_kwargs(METHOD_PUT, **kwargs)
url = self.get_url(path, **kwargs)
headers = self.get_headers(**kwargs)
kwargs['headers'] = headers
Expand Down
7 changes: 7 additions & 0 deletions peasant/client/transport_tornado.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def get_headers(self, **kwargs):
return headers

async def delete(self, path: str, **kwargs: dict):
kwargs = self.update_kwargs(METHOD_DELETE, **kwargs)
url = self.get_url(path, **kwargs)
kwargs["method"] = METHOD_DELETE
request = get_tornado_request(url, **kwargs)
Expand All @@ -148,13 +149,15 @@ async def delete(self, path: str, **kwargs: dict):
return await self._client.fetch(request)

async def get(self, path: str, **kwargs: dict):
kwargs = self.update_kwargs(METHOD_GET, **kwargs)
url = self.get_url(path, **kwargs)
request = get_tornado_request(url, **kwargs)
headers = self.get_headers(**kwargs)
request.headers.update(headers)
return await self._client.fetch(request)

async def head(self, path: str, **kwargs: dict):
kwargs = self.update_kwargs(METHOD_HEAD, **kwargs)
url = self.get_url(path, **kwargs)
kwargs["method"] = METHOD_HEAD
request = get_tornado_request(url, **kwargs)
Expand All @@ -163,6 +166,7 @@ async def head(self, path: str, **kwargs: dict):
return await self._client.fetch(request)

async def options(self, path: str, **kwargs: dict):
kwargs = self.update_kwargs(METHOD_OPTIONS, **kwargs)
url = self.get_url(path, **kwargs)
kwargs["method"] = METHOD_OPTIONS
request = get_tornado_request(url, **kwargs)
Expand All @@ -171,6 +175,7 @@ async def options(self, path: str, **kwargs: dict):
return await self._client.fetch(request)

async def patch(self, path: str, **kwargs: dict):
kwargs = self.update_kwargs(METHOD_PATCH, **kwargs)
url = self.get_url(path, **kwargs)
kwargs["method"] = METHOD_PATCH
request = get_tornado_request(url, **kwargs)
Expand All @@ -179,6 +184,7 @@ async def patch(self, path: str, **kwargs: dict):
return await self._client.fetch(request)

async def post(self, path: str, **kwargs: dict):
kwargs = self.update_kwargs(METHOD_POST, **kwargs)
url = self.get_url(path, **kwargs)
kwargs["method"] = METHOD_POST
request = get_tornado_request(url, **kwargs)
Expand All @@ -187,6 +193,7 @@ async def post(self, path: str, **kwargs: dict):
return await self._client.fetch(request)

async def put(self, path: str, **kwargs: dict):
kwargs = self.update_kwargs(METHOD_PUT, **kwargs)
url = self.get_url(path, **kwargs)
kwargs["method"] = METHOD_PUT
request = get_tornado_request(url, **kwargs)
Expand Down

0 comments on commit 13857cf

Please sign in to comment.