From 5ba368c75414fe2eb88fd1af29da471048773159 Mon Sep 17 00:00:00 2001 From: Vuk Manojlovic Date: Wed, 25 Oct 2023 15:32:09 +0200 Subject: [PATCH 1/3] CTX-4793: Moved request functions success and badRequest to networking.utils --- coretex/networking/__init__.py | 1 + coretex/networking/utils.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/coretex/networking/__init__.py b/coretex/networking/__init__.py index b931c2a1..677df819 100644 --- a/coretex/networking/__init__.py +++ b/coretex/networking/__init__.py @@ -22,3 +22,4 @@ from .request_type import RequestType from .chunk_upload_session import ChunkUploadSession, MAX_CHUNK_SIZE from .file_data import FileData +from .utils import badRequest, success diff --git a/coretex/networking/utils.py b/coretex/networking/utils.py index fb6778ec..de93e8eb 100644 --- a/coretex/networking/utils.py +++ b/coretex/networking/utils.py @@ -66,3 +66,22 @@ def logRequestFailure(endpoint: str, response: NetworkResponse) -> None: logging.getLogger("coretexpylib").debug(f"\tResponse: {responseJson}") except (ValueError, TypeError): logging.getLogger("coretexpylib").debug(f"\tResponse: {response.getContent()!r}") + + +def badRequest(error: str) -> Dict[str, Any]: + return { + "code": 400, + "body": { + "error": error + } + } + + +def success(data: Optional[Any] = None) -> Dict[str, Any]: + if data is None: + data = {} + + return { + "code": 200, + "body": data + } From 133a4116dcf21da185aceb6af1cbb0b7a94a1952 Mon Sep 17 00:00:00 2001 From: Vuk Manojlovic Date: Fri, 27 Oct 2023 14:34:48 +0200 Subject: [PATCH 2/3] CTX-4793: Moved functions related code to top-level module "functions" and added documentation --- coretex/functions.py | 46 ++++++++++++++++++++++++++++++++++ coretex/networking/__init__.py | 1 - coretex/networking/utils.py | 19 -------------- 3 files changed, 46 insertions(+), 20 deletions(-) create mode 100644 coretex/functions.py diff --git a/coretex/functions.py b/coretex/functions.py new file mode 100644 index 00000000..2cc978d4 --- /dev/null +++ b/coretex/functions.py @@ -0,0 +1,46 @@ +from typing import Optional, Any, Dict + + +def badRequest(error: str) -> Dict[str, Any]: + """ + Creates a json object for bad request + + Parameters + ---------- + error : str + Error message + + Returns + ------- + dict -> Json object for bad request + """ + + return { + "code": 400, + "body": { + "error": error + } + } + + +def success(data: Optional[Any] = None) -> Dict[str, Any]: + """ + Creates a json object for successful request + + Parameters + ---------- + data : Optional[Any] + Response data + + Returns + ------- + dict -> Json object for successful request + """ + + if data is None: + data = {} + + return { + "code": 200, + "body": data + } diff --git a/coretex/networking/__init__.py b/coretex/networking/__init__.py index 677df819..b931c2a1 100644 --- a/coretex/networking/__init__.py +++ b/coretex/networking/__init__.py @@ -22,4 +22,3 @@ from .request_type import RequestType from .chunk_upload_session import ChunkUploadSession, MAX_CHUNK_SIZE from .file_data import FileData -from .utils import badRequest, success diff --git a/coretex/networking/utils.py b/coretex/networking/utils.py index de93e8eb..fb6778ec 100644 --- a/coretex/networking/utils.py +++ b/coretex/networking/utils.py @@ -66,22 +66,3 @@ def logRequestFailure(endpoint: str, response: NetworkResponse) -> None: logging.getLogger("coretexpylib").debug(f"\tResponse: {responseJson}") except (ValueError, TypeError): logging.getLogger("coretexpylib").debug(f"\tResponse: {response.getContent()!r}") - - -def badRequest(error: str) -> Dict[str, Any]: - return { - "code": 400, - "body": { - "error": error - } - } - - -def success(data: Optional[Any] = None) -> Dict[str, Any]: - if data is None: - data = {} - - return { - "code": 200, - "body": data - } From 0b4a92f0e5b2084551e5d252a6b7cd2a36683ad3 Mon Sep 17 00:00:00 2001 From: Vuk Manojlovic Date: Tue, 31 Oct 2023 14:54:05 +0100 Subject: [PATCH 3/3] CTX-4793: Added copyright header to functions.py --- coretex/functions.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/coretex/functions.py b/coretex/functions.py index 2cc978d4..e546bec6 100644 --- a/coretex/functions.py +++ b/coretex/functions.py @@ -1,3 +1,20 @@ +# Copyright (C) 2023 Coretex LLC + +# This file is part of Coretex.ai + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + from typing import Optional, Any, Dict