Skip to content

Commit

Permalink
fix prints
Browse files Browse the repository at this point in the history
  • Loading branch information
jefer94 committed Mar 21, 2024
1 parent 29c2519 commit b77cc3d
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 97 deletions.
2 changes: 1 addition & 1 deletion src/linked_services/__about__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: 2024-present jefer94 <[email protected]>
#
# SPDX-License-Identifier: LGPL-3.0-or-later
__version__ = "1.2.0"
__version__ = "1.2.1"
196 changes: 100 additions & 96 deletions src/linked_services/core/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

__all__ = ["Service"]

logger = logging.getLogger(__name__)
DEBUG = os.getenv("LOG_LEVEL") == "DEBUG"

LIBRARIES = {
Expand Down Expand Up @@ -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

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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

Expand All @@ -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)

Expand Down

0 comments on commit b77cc3d

Please sign in to comment.