Skip to content

Commit

Permalink
requests: default to requests.Session
Browse files Browse the repository at this point in the history
  • Loading branch information
laerfulaolun committed Feb 22, 2024
1 parent f6b1ae3 commit 4b051b5
Showing 1 changed file with 43 additions and 25 deletions.
68 changes: 43 additions & 25 deletions automon/integrations/requestsWrapper/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,16 +76,19 @@ def content(self):
if 'content' in dir(self.results):
return self.results.content

async def delete(self,
url: str = None,
data: dict = None,
headers: dict = None, **kwargs) -> bool:
async def delete(
self,
url: str = None,
data: dict = None,
headers: dict = None,
**kwargs
) -> bool:
"""requests.delete"""

url, data, headers = await self._params(url, data, headers)

try:
self.results = requests.delete(url=url, data=data, headers=headers, **kwargs)
self.results = self.session.delete(url=url, data=data, headers=headers, **kwargs)
await self._log_result()

if self.status_code == 200:
Expand All @@ -97,16 +100,19 @@ async def delete(self,
logger.error(f'delete failed. {e}')
return False

async def get(self,
url: str = None,
data: dict = None,
headers: dict = None, **kwargs) -> bool:
async def get(
self,
url: str = None,
data: dict = None,
headers: dict = None,
**kwargs
) -> bool:
"""requests.get"""

url, data, headers = await self._params(url, data, headers)

try:
self.results = requests.get(url=url, data=data, headers=headers, **kwargs)
self.results = self.session.get(url=url, data=data, headers=headers, **kwargs)

logger.debug(
f'{self.results.url} '
Expand All @@ -123,16 +129,19 @@ async def get(self,
logger.error(f'{e}')
return False

async def patch(self,
url: str = None,
data: dict = None,
headers: dict = None, **kwargs) -> bool:
async def patch(
self,
url: str = None,
data: dict = None,
headers: dict = None,
**kwargs
) -> bool:
"""requests.patch"""

url, data, headers = await self._params(url, data, headers)

try:
self.results = requests.patch(url=url, data=data, headers=headers, **kwargs)
self.results = self.session.patch(url=url, data=data, headers=headers, **kwargs)

logger.debug(
f'{self.results.url} '
Expand All @@ -149,16 +158,19 @@ async def patch(self,
logger.error(f'patch failed. {e}')
return False

async def post(self,
url: str = None,
data: dict = None,
headers: dict = None, **kwargs) -> bool:
async def post(
self,
url: str = None,
data: dict = None,
headers: dict = None,
**kwargs
) -> bool:
"""requests.post"""

url, data, headers = await self._params(url, data, headers)

try:
self.results = requests.post(url=url, data=data, headers=headers, **kwargs)
self.results = self.session.post(url=url, data=data, headers=headers, **kwargs)

logger.debug(
f'{self.results.url} '
Expand All @@ -175,16 +187,19 @@ async def post(self,
logger.error(f'post failed. {e}')
return False

async def put(self,
url: str = None,
data: dict = None,
headers: dict = None, **kwargs) -> bool:
async def put(
self,
url: str = None,
data: dict = None,
headers: dict = None,
**kwargs
) -> bool:
"""requests.put"""

url, data, headers = await self._params(url, data, headers)

try:
self.results = requests.put(url=url, data=data, headers=headers, **kwargs)
self.results = self.session.put(url=url, data=data, headers=headers, **kwargs)

logger.debug(
f'{self.results.url} '
Expand Down Expand Up @@ -224,6 +239,9 @@ async def to_json(self):
if self.content:
return json.dumps(json.loads(self.content))

async def update_headers(self, headers: dict):
return self.session.headers.update(headers)


class Requests(RequestsClient):
pass

0 comments on commit 4b051b5

Please sign in to comment.