From b77cc3d07b36f1a2c4cd9ffab5c9aa103510ee21 Mon Sep 17 00:00:00 2001 From: jefer94 Date: Thu, 21 Mar 2024 01:56:06 -0500 Subject: [PATCH] fix prints --- src/linked_services/__about__.py | 2 +- src/linked_services/core/service.py | 196 ++++++++++++++-------------- 2 files changed, 101 insertions(+), 97 deletions(-) diff --git a/src/linked_services/__about__.py b/src/linked_services/__about__.py index 120a059..f6e5738 100644 --- a/src/linked_services/__about__.py +++ b/src/linked_services/__about__.py @@ -1,4 +1,4 @@ # SPDX-FileCopyrightText: 2024-present jefer94 # # SPDX-License-Identifier: LGPL-3.0-or-later -__version__ = "1.2.0" +__version__ = "1.2.1" diff --git a/src/linked_services/core/service.py b/src/linked_services/core/service.py index 54a8aca..c4bbb1c 100644 --- a/src/linked_services/core/service.py +++ b/src/linked_services/core/service.py @@ -14,7 +14,6 @@ __all__ = ["Service"] -logger = logging.getLogger(__name__) DEBUG = os.getenv("LOG_LEVEL") == "DEBUG" LIBRARIES = { @@ -100,10 +99,11 @@ def _sync_proxy(self, request: Callable[[], requests.Response], stream: bool) -> resource[header] = response.headers[header] if DEBUG: - logger.debug("Response") - logger.debug(" Content: no visible due to it's a stream") - logger.debug(" Headers: " + str(response.headers)) - logger.debug(" Status code: " + str(response.status_code)) + print("Response") + print(" Content: no visible due to it's a stream") + print(" Headers: " + str(response.headers)) + print(" Status code: " + str(response.status_code)) + print("") return resource @@ -113,11 +113,12 @@ def _sync_proxy(self, request: Callable[[], requests.Response], stream: bool) -> headers[header] = response.headers[header] if DEBUG: - logger.debug("Response") - logger.debug(" Type: Proxy") - logger.debug(" Content: " + response.content.decode()) - logger.debug(" Headers: " + str(headers)) - logger.debug(" Status code: " + str(response.status_code)) + print("Response") + print(" Type: Proxy") + print(" Content: " + response.content.decode()) + print(" Headers: " + str(headers)) + print(" Status code: " + str(response.status_code)) + print("") return HttpResponse(response.content, status=response.status_code, headers=headers) @@ -131,10 +132,10 @@ def _sync_get(self, url, params=None, **kwargs): def request() -> requests.Response: if DEBUG: - logger.debug("Request") - logger.debug(" Method: GET") - logger.debug(" Url: " + str(url)) - logger.debug("") + print("Request") + print(" Method: GET") + print(" Url: " + str(url)) + print("") return requests.get(url, params=params, **kwargs, headers=headers) @@ -151,10 +152,10 @@ def _sync_options(self, url, **kwargs): def request() -> requests.Response: if DEBUG: - logger.debug("Request") - logger.debug(" Method: OPTIONS") - logger.debug(" Url: " + str(url)) - logger.debug("") + print("Request") + print(" Method: OPTIONS") + print(" Url: " + str(url)) + print("") return requests.options(url, **kwargs, headers=headers) @@ -171,10 +172,10 @@ def _sync_head(self, url, **kwargs): def request() -> requests.Response: if DEBUG: - logger.debug("Request") - logger.debug(" Method: HEAD") - logger.debug(" Url: " + str(url)) - logger.debug("") + print("Request") + print(" Method: HEAD") + print(" Url: " + str(url)) + print("") return requests.head(url, **kwargs, headers=headers) @@ -191,10 +192,10 @@ def _sync_post(self, url, data=None, json=None, **kwargs): def request() -> requests.Response: if DEBUG: - logger.debug("Request") - logger.debug(" Method: POST") - logger.debug(" Url: " + str(url)) - logger.debug("") + print("Request") + print(" Method: POST") + print(" Url: " + str(url)) + print("") return requests.post(url, data=data, json=json, **kwargs, headers=headers) @@ -211,10 +212,10 @@ def _sync_webhook(self, url, data=None, json=None, **kwargs): def request() -> requests.Response: if DEBUG: - logger.debug("Request") - logger.debug(" Type: Webhook") - logger.debug(" Url: " + str(url)) - logger.debug("") + print("Request") + print(" Type: Webhook") + print(" Url: " + str(url)) + print("") return requests.post(url, data=data, json=json, **kwargs, headers=headers) @@ -231,10 +232,10 @@ def _sync_put(self, url, data=None, **kwargs): def request() -> requests.Response: if DEBUG: - logger.debug("Request") - logger.debug(" Method: PUT") - logger.debug(" Url: " + str(url)) - logger.debug("") + print("Request") + print(" Method: PUT") + print(" Url: " + str(url)) + print("") return requests.put(url, data=data, **kwargs, headers=headers) @@ -251,10 +252,10 @@ def _sync_patch(self, url, data=None, **kwargs): def request() -> requests.Response: if DEBUG: - logger.debug("Request") - logger.debug(" Method: PATCH") - logger.debug(" Url: " + str(url)) - logger.debug("") + print("Request") + print(" Method: PATCH") + print(" Url: " + str(url)) + print("") return requests.patch(url, data=data, **kwargs, headers=headers) @@ -271,10 +272,10 @@ def _sync_delete(self, url, **kwargs): def request() -> requests.Response: if DEBUG: - logger.debug("Request") - logger.debug(" Method: DELETE") - logger.debug(" Url: " + str(url)) - logger.debug("") + print("Request") + print(" Method: DELETE") + print(" Url: " + str(url)) + print("") return requests.delete(url, **kwargs, headers=headers) @@ -291,10 +292,10 @@ def _sync_request(self, method, url, **kwargs): def request() -> requests.Response: if DEBUG: - logger.debug("Request") - logger.debug(" Method: " + str(method).upper()) - logger.debug(" Url: " + str(url)) - logger.debug("") + print("Request") + print(" Method: " + str(method).upper()) + print(" Url: " + str(url)) + print("") return requests.request(method, url, **kwargs, headers=headers) @@ -364,11 +365,12 @@ async def _async_proxy(self, response: Coroutine[Any, Any, ClientResponse]) -> H content = await r.content.read() if DEBUG: - logger.debug("Response") - logger.debug(" Type: Proxy") - logger.debug(" Content: " + content.decode()) - logger.debug(" Headers: " + str(headers)) - logger.debug(" Status code: " + str(response.status_code)) + print("Response") + print(" Type: Proxy") + print(" Content: " + content.decode()) + print(" Headers: " + str(headers)) + print(" Status code: " + str(r.status)) + print("") return HttpResponse(content, status=r.status, headers=headers) @@ -382,10 +384,10 @@ def _async_get(self, url, params=None, **kwargs): res = obj.__aenter__() if DEBUG: - logger.debug("Request") - logger.debug(" Method: GET") - logger.debug(" Url: " + str(url)) - logger.debug("") + print("Request") + print(" Method: GET") + print(" Url: " + str(url)) + print("") # wraps client response to be used within django views if self.proxy: @@ -403,10 +405,10 @@ def _async_options(self, url, **kwargs): res = obj.__aenter__() if DEBUG: - logger.debug("Request") - logger.debug(" Method: OPTIONS") - logger.debug(" Url: " + str(url)) - logger.debug("") + print("Request") + print(" Method: OPTIONS") + print(" Url: " + str(url)) + print("") # wraps client response to be used within django views if self.proxy: @@ -424,10 +426,10 @@ def _async_head(self, url, **kwargs): res = obj.__aenter__() if DEBUG: - logger.debug("Request") - logger.debug(" Method: HEAD") - logger.debug(" Url: " + str(url)) - logger.debug("") + print("Request") + print(" Method: HEAD") + print(" Url: " + str(url)) + print("") # wraps client response to be used within django views if self.proxy: @@ -445,10 +447,10 @@ def _async_post(self, url, data=None, json=None, **kwargs): res = obj.__aenter__() if DEBUG: - logger.debug("Request") - logger.debug(" Method: POST") - logger.debug(" Url: " + str(url)) - logger.debug("") + print("Request") + print(" Method: POST") + print(" Url: " + str(url)) + print("") # wraps client response to be used within django views if self.proxy: @@ -466,10 +468,10 @@ def _async_webhook(self, url, data=None, json=None, **kwargs): res = obj.__aenter__() if DEBUG: - logger.debug("Request") - logger.debug(" Type: Webhook") - logger.debug(" Url: " + str(url)) - logger.debug("") + print("Request") + print(" Type: Webhook") + print(" Url: " + str(url)) + print("") # wraps client response to be used within django views if self.proxy: @@ -487,10 +489,10 @@ def _async_put(self, url, data=None, **kwargs): res = obj.__aenter__() if DEBUG: - logger.debug("Request") - logger.debug(" Method: PUT") - logger.debug(" Url: " + str(url)) - logger.debug("") + print("Request") + print(" Method: PUT") + print(" Url: " + str(url)) + print("") # wraps client response to be used within django views if self.proxy: @@ -508,10 +510,10 @@ def _async_patch(self, url, data=None, **kwargs): res = obj.__aenter__() if DEBUG: - logger.debug("Request") - logger.debug(" Method: PATCH") - logger.debug(" Url: " + str(url)) - logger.debug("") + print("Request") + print(" Method: PATCH") + print(" Url: " + str(url)) + print("") # wraps client response to be used within django views if self.proxy: @@ -529,10 +531,10 @@ def _async_delete(self, url, **kwargs): res = obj.__aenter__() if DEBUG: - logger.debug("Request") - logger.debug(" Method: DELETE") - logger.debug(" Url: " + str(url)) - logger.debug("") + print("Request") + print(" Method: DELETE") + print(" Url: " + str(url)) + print("") # wraps client response to be used within django views if self.proxy: @@ -550,10 +552,10 @@ def _async_request(self, method, url, **kwargs): res = obj.__aenter__() if DEBUG: - logger.debug("Request") - logger.debug(" Method: " + str(method).upper()) - logger.debug(" Url: " + str(url)) - logger.debug("") + print("Request") + print(" Method: " + str(method).upper()) + print(" Url: " + str(url)) + print("") # wraps client response to be used within django views if self.proxy: @@ -594,10 +596,11 @@ def _async_proxy(self, response: requests.Response, stream: bool) -> StreamingHt resource[header] = response.headers[header] if DEBUG: - logger.debug("Response") - logger.debug(" Content: no visible due to it's a stream") - logger.debug(" Headers: " + str(response.headers)) - logger.debug(" Status code: " + str(response.status_code)) + print("Response") + print(" Content: no visible due to it's a stream") + print(" Headers: " + str(response.headers)) + print(" Status code: " + str(response.status_code)) + print("") return resource @@ -607,11 +610,12 @@ def _async_proxy(self, response: requests.Response, stream: bool) -> StreamingHt headers[header] = response.headers[header] if DEBUG: - logger.debug("Response") - logger.debug(" Type: Proxy") - logger.debug(" Content: " + response.content.decode()) - logger.debug(" Headers: " + str(headers)) - logger.debug(" Status code: " + str(response.status_code)) + print("Response") + print(" Type: Proxy") + print(" Content: " + response.content.decode()) + print(" Headers: " + str(headers)) + print(" Status code: " + str(response.status_code)) + print("") return HttpResponse(response.content, status=response.status_code, headers=headers)