diff --git a/fastapi_startkit/src/fastapi_startkit/collection/__init__.py b/fastapi_startkit/src/fastapi_startkit/collection/__init__.py deleted file mode 100644 index 969ac3fe..00000000 --- a/fastapi_startkit/src/fastapi_startkit/collection/__init__.py +++ /dev/null @@ -1 +0,0 @@ -from .collection import Collection diff --git a/fastapi_startkit/src/fastapi_startkit/console/publish_command.py b/fastapi_startkit/src/fastapi_startkit/console/publish_command.py index 736bdaa4..0c6452cc 100644 --- a/fastapi_startkit/src/fastapi_startkit/console/publish_command.py +++ b/fastapi_startkit/src/fastapi_startkit/console/publish_command.py @@ -4,7 +4,7 @@ from fastapi_startkit.console import Command from cleo.helpers import option -from fastapi_startkit.helpers.string import Str +from fastapi_startkit.support import Str if TYPE_CHECKING: from fastapi_startkit.application import Application diff --git a/fastapi_startkit/src/fastapi_startkit/exceptions.backup/DD.py b/fastapi_startkit/src/fastapi_startkit/exceptions.backup/DD.py deleted file mode 100644 index 972c8cc9..00000000 --- a/fastapi_startkit/src/fastapi_startkit/exceptions.backup/DD.py +++ /dev/null @@ -1,38 +0,0 @@ -import inspect -import warnings - -from .exceptions import DumpException - - -warnings.warn( - "DD class will be removed in Masonite 5. Please use Dump facade instead.", - DeprecationWarning, -) - - -class DD: - def __init__(self, container): - self.app = container - - def die_and_dump(self, *args): - """Dump all provided args and die, ie raise a DumpException.""" - self.dump(*args) - raise DumpException - - def dump(self, *args): - """Dump all provided args and let flow continue. This does not raise a DumpException.""" - print( - inspect.stack()[1].function, - inspect.stack()[1].filename, - inspect.stack()[1].lineno, - ) - if self.app.has("ObjDumpList"): - dump_list = self.app.make("ObjDumpList") - else: - dump_list = [] - start = len(dump_list) - for i, obj in enumerate(args): - dump_name = f"ObjDump{start + i}" - self.app.bind(dump_name, obj) - dump_list.append(dump_name) - self.app.bind("ObjDumpList", dump_list) diff --git a/fastapi_startkit/src/fastapi_startkit/exceptions.backup/ExceptionHandler.py b/fastapi_startkit/src/fastapi_startkit/exceptions.backup/ExceptionHandler.py deleted file mode 100644 index 43aefb4a..00000000 --- a/fastapi_startkit/src/fastapi_startkit/exceptions.backup/ExceptionHandler.py +++ /dev/null @@ -1,70 +0,0 @@ -class ExceptionHandler: - def __init__(self, application, driver_config=None): - self.application = application - self.drivers = {} - self.driver_config = driver_config or {} - self.options = {} - - def set_options(self, options): - self.options = options - return self - - def add_driver(self, name, driver): - self.drivers.update({name: driver}) - - def set_configuration(self, config): - self.driver_config = config - return self - - def get_driver(self, name=None): - if name is None: - return self.drivers[self.driver_config.get("default")] - return self.drivers[name] - - def get_config_options(self, driver=None): - if driver is None: - return self.driver_config[self.driver_config.get("default")] - - return self.driver_config.get(driver, {}) - - def handle(self, exception): - response = self.application.make("response") - request = self.application.make("request") - - self.application.make("event").fire(f"masonite.exception.{exception.__class__.__name__}", exception) - - # add headers to response if any - if hasattr(exception, "get_headers"): - headers = exception.get_headers() - response.with_headers(headers) - - # if an exception handler is registered for this exception, use it instead - # add headers to response if any - if hasattr(exception, "get_headers"): - headers = exception.get_headers() - response.with_headers(headers) - - if self.application.has(f"{exception.__class__.__name__}Handler"): - return self.application.make(f"{exception.__class__.__name__}Handler").handle(exception) - - # handle exception in production - if not self.application.is_debug(): - # for HTTP error codes (500, 404, 403...) a specific page should be displayed - # if a renderable exception is raised let it be displayed - if hasattr(exception, "is_http_exception") or hasattr(exception, "get_response"): - return self.application.make("HttpExceptionHandler").handle(exception) - - # else fallback to an unknown exception that should be displayed as a 500 error - exception.get_status = lambda: 500 - exception.get_response = lambda: str(exception) or "Unknown error" - return self.application.make("HttpExceptionHandler").handle(exception) - - # handle exception in development mode with Exceptionite - exceptionite = self.get_driver("exceptionite") - exceptionite.start(exception) - exceptionite.render("terminal") - - if request.accepts_json(): - return response.view(exceptionite.render("json"), status=500) - else: - return response.view(exceptionite.render("web"), status=500) diff --git a/fastapi_startkit/src/fastapi_startkit/exceptions.backup/__init__.py b/fastapi_startkit/src/fastapi_startkit/exceptions.backup/__init__.py deleted file mode 100644 index 590a19b7..00000000 --- a/fastapi_startkit/src/fastapi_startkit/exceptions.backup/__init__.py +++ /dev/null @@ -1,38 +0,0 @@ -from .ExceptionHandler import ExceptionHandler -from .handlers.DumpExceptionHandler import DumpExceptionHandler -from .handlers.HttpExceptionHandler import HttpExceptionHandler -from .handlers.ModelNotFoundHandler import ModelNotFoundHandler -from .DD import DD -from .exceptions import ( - AuthorizationException, - InvalidRouteCompileException, - RouteMiddlewareNotFound, - ContainerError, - MissingContainerBindingNotFound, - StrictContainerException, - ResponseError, - InvalidHTTPStatusCode, - RequiredContainerBindingNotFound, - ViewException, - RouteNotFoundException, - DumpException, - InvalidSecretKey, - InvalidCSRFToken, - NotificationException, - InvalidToken, - ProjectLimitReached, - ProjectProviderTimeout, - ProjectProviderHttpError, - ProjectTargetNotEmpty, - MixFileNotFound, - MixManifestNotFound, - InvalidConfigurationLocation, - InvalidConfigurationSetup, - InvalidPackageName, - LoaderNotFound, - QueueException, - AmbiguousError, - MethodNotAllowedException, - ModelNotFoundException, - ThrottleRequestsException, -) diff --git a/fastapi_startkit/src/fastapi_startkit/exceptions.backup/exceptionite/blocks.py b/fastapi_startkit/src/fastapi_startkit/exceptions.backup/exceptionite/blocks.py deleted file mode 100644 index 0236b09d..00000000 --- a/fastapi_startkit/src/fastapi_startkit/exceptions.backup/exceptionite/blocks.py +++ /dev/null @@ -1,101 +0,0 @@ -from exceptionite import Block - -from ... import __version__ -from ...helpers import optional -from ...utils.str import get_controller_name - - -def recursive_serializer(data): - if isinstance(data, (int, bool, str, bytes)): - return data - elif isinstance(data, (list, tuple)): - return [recursive_serializer(item) for item in data] - elif isinstance(data, dict): - return {key: recursive_serializer(val) for key, val in data.items()} - elif callable(data): - return str(data) - elif hasattr(data, "serialize"): - return data.serialize() - else: - return str(data) - - -class AppBlock(Block): - id = "application" - name = "Application" - icon = "DesktopComputerIcon" - has_sections = True - - def build(self): - request = self.handler.app.make("request") - route = request.get_route() - - data = { - "Info": { - "Masonite Version": __version__, - "Environment": self.handler.app.environment(), - "Debug": self.handler.app.is_debug(), - } - } - - # add app route data - if route: - data.update( - { - "Route": { - "Controller": get_controller_name(route.controller), - "Name": route.get_name(), - "Middlewares": route.get_middlewares(), - } - } - ) - - # add user route data - user = request.user() - if user: - data.update( - { - "User": { - "E-mail": optional(user).email, - "ID": optional(user).id, - } - } - ) - - return data - - -class RequestBlock(Block): - id = "request" - name = "Request" - icon = "SwitchHorizontalIcon" - has_sections = True - - def build(self): - request = self.handler.app.make("request") - # serialize inputs (e.g. in case of file) - inputs = {} - for name, value in request.all().items(): - inputs[name] = recursive_serializer(value) - return { - "Parameters": { - "Path": request.get_path(), - "Input": inputs or None, - "Request Method": request.get_request_method(), - }, - "Headers": request.header_bag.to_dict(), - } - - -class ConfigBlock(Block): - id = "config" - name = "Configuration" - icon = "CogIcon" - has_sections = True - - def build(self): - data = {} - for section, config_data in self.handler.app.make("config").all().items(): - section_name = section.title() - data[section_name] = recursive_serializer(config_data) - return data diff --git a/fastapi_startkit/src/fastapi_startkit/exceptions.backup/exceptionite/controllers.py b/fastapi_startkit/src/fastapi_startkit/exceptions.backup/exceptionite/controllers.py deleted file mode 100644 index 35fd676c..00000000 --- a/fastapi_startkit/src/fastapi_startkit/exceptions.backup/exceptionite/controllers.py +++ /dev/null @@ -1,13 +0,0 @@ -from ...request import Request -from ...controllers import Controller -from ...response import Response - - -class ExceptioniteController(Controller): - def run_action(self, request: Request, response: Response): - handler = request.app.make("exception_handler").get_driver("exceptionite") - data = handler.run_action(request.input("action_id"), request.input("options")) - try: - return response.json({"message": "ok", "data": data}, 200) - except: # noqa: E722 - return response.json({"message": "An error happened", "data": data}, 400) diff --git a/fastapi_startkit/src/fastapi_startkit/exceptions.backup/exceptionite/solutions.py b/fastapi_startkit/src/fastapi_startkit/exceptions.backup/exceptionite/solutions.py deleted file mode 100644 index b5b8bf6d..00000000 --- a/fastapi_startkit/src/fastapi_startkit/exceptions.backup/exceptionite/solutions.py +++ /dev/null @@ -1,66 +0,0 @@ -class TableNotFound: - def title(self): - return "Table Not Found" - - def description(self): - return "You are trying to make a query on a table that cannot be found. Check that :table migration exists and that migrations have been ran with 'python craft migrate' command." - - def regex(self): - return r"no such table: (?P(\w+))" - - -class MissingCSRFToken: - def title(self): - return "Missing CSRF Token" - - def description(self): - return "You are trying to make a sensitive request without providing a CSRF token. Your request might be vulnerable to Cross Site Request Forgery. To resolve this issue you should use {{ csrf_field }} in HTML forms or add X-CSRF-TOKEN header in AJAX requests." - - def regex(self): - return r"Missing CSRF Token" - - -class InvalidCSRFToken: - def title(self): - return "The session does not match the CSRF token" - - def description(self): - return "Try clearing your cookies for the localhost domain in your browsers developer tools." - - def regex(self): - return r"Invalid CSRF Token" - - -class TemplateNotFound: - def title(self): - return "Template Not Found" - - def description(self): - return """':template.html' view file has not been found in registered view locations. Please verify the spelling of the template and that it exists in locations declared in Kernel file. You can check - available view locations with app.make('view.locations').""" - - def regex(self): - return r"Template '(?P