Skip to content

Commit

Permalink
1.0.4 - formatted code
Browse files Browse the repository at this point in the history
  • Loading branch information
mauro-balades committed Oct 3, 2021
1 parent d439ef8 commit 40bba8b
Show file tree
Hide file tree
Showing 9 changed files with 118 additions and 105 deletions.
98 changes: 49 additions & 49 deletions expross/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
THE SOFTWARE.
"""

version = "1.0.3"
version = "1.0.4"

from expross.main import Expross

Expand All @@ -34,52 +34,52 @@

# Errors used for handling
_errors = (
'CompatibilityError',
'DelimiterError',
'HeaderNotSupported',
'HTTPBadGateway',
'HTTPBadRequest',
'HTTPConflict',
'HTTPFailedDependency',
'HTTPForbidden',
'HTTPGatewayTimeout',
'HTTPGone',
'HTTPInsufficientStorage',
'HTTPInternalServerError',
'HTTPInvalidHeader',
'HTTPInvalidParam',
'HTTPLengthRequired',
'HTTPLocked',
'HTTPLoopDetected',
'HTTPMethodNotAllowed',
'HTTPMissingHeader',
'HTTPMissingParam',
'HTTPNetworkAuthenticationRequired',
'HTTPNotAcceptable',
'HTTPNotFound',
'HTTPNotImplemented',
'HTTPPayloadTooLarge',
'HTTPPreconditionFailed',
'HTTPPreconditionRequired',
'HTTPRangeNotSatisfiable',
'HTTPRequestHeaderFieldsTooLarge',
'HTTPRouteNotFound',
'HTTPServiceUnavailable',
'HTTPTooManyRequests',
'HTTPUnauthorized',
'HTTPUnavailableForLegalReasons',
'HTTPUnprocessableEntity',
'HTTPUnsupportedMediaType',
'HTTPUriTooLong',
'HTTPVersionNotSupported',
'MediaMalformedError',
'MediaNotFoundError',
'OperationNotAllowed',
'PayloadTypeError',
'UnsupportedError',
'UnsupportedScopeError',
'WebSocketDisconnected',
'WebSocketHandlerNotFound',
'WebSocketPathNotFound',
'WebSocketServerError',
"CompatibilityError",
"DelimiterError",
"HeaderNotSupported",
"HTTPBadGateway",
"HTTPBadRequest",
"HTTPConflict",
"HTTPFailedDependency",
"HTTPForbidden",
"HTTPGatewayTimeout",
"HTTPGone",
"HTTPInsufficientStorage",
"HTTPInternalServerError",
"HTTPInvalidHeader",
"HTTPInvalidParam",
"HTTPLengthRequired",
"HTTPLocked",
"HTTPLoopDetected",
"HTTPMethodNotAllowed",
"HTTPMissingHeader",
"HTTPMissingParam",
"HTTPNetworkAuthenticationRequired",
"HTTPNotAcceptable",
"HTTPNotFound",
"HTTPNotImplemented",
"HTTPPayloadTooLarge",
"HTTPPreconditionFailed",
"HTTPPreconditionRequired",
"HTTPRangeNotSatisfiable",
"HTTPRequestHeaderFieldsTooLarge",
"HTTPRouteNotFound",
"HTTPServiceUnavailable",
"HTTPTooManyRequests",
"HTTPUnauthorized",
"HTTPUnavailableForLegalReasons",
"HTTPUnprocessableEntity",
"HTTPUnsupportedMediaType",
"HTTPUriTooLong",
"HTTPVersionNotSupported",
"MediaMalformedError",
"MediaNotFoundError",
"OperationNotAllowed",
"PayloadTypeError",
"UnsupportedError",
"UnsupportedScopeError",
"WebSocketDisconnected",
"WebSocketHandlerNotFound",
"WebSocketPathNotFound",
"WebSocketServerError",
)
1 change: 1 addition & 0 deletions expross/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from expross.utils import get_response
from expross.errors import CustomBaseException


class ErrorHandler(CustomBaseException):
"""Handles any errors user whants to handle.
Expand Down
103 changes: 55 additions & 48 deletions expross/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,73 +24,80 @@

# Errors
__all__ = (
'CompatibilityError',
'DelimiterError',
'HeaderNotSupported',
'HTTPBadGateway',
'HTTPBadRequest',
'HTTPConflict',
'HTTPFailedDependency',
'HTTPForbidden',
'HTTPGatewayTimeout',
'HTTPGone',
'HTTPInsufficientStorage',
'HTTPInternalServerError',
'HTTPInvalidHeader',
'HTTPInvalidParam',
'HTTPLengthRequired',
'HTTPLocked',
'HTTPLoopDetected',
'HTTPMethodNotAllowed',
'HTTPMissingHeader',
'HTTPMissingParam',
'HTTPNetworkAuthenticationRequired',
'HTTPNotAcceptable',
'HTTPNotFound',
'HTTPNotImplemented',
'HTTPPayloadTooLarge',
'HTTPPreconditionFailed',
'HTTPPreconditionRequired',
'HTTPRangeNotSatisfiable',
'HTTPRequestHeaderFieldsTooLarge',
'HTTPRouteNotFound',
'HTTPServiceUnavailable',
'HTTPTooManyRequests',
'HTTPUnauthorized',
'HTTPUnavailableForLegalReasons',
'HTTPUnprocessableEntity',
'HTTPUnsupportedMediaType',
'HTTPUriTooLong',
'HTTPVersionNotSupported',
'MediaMalformedError',
'MediaNotFoundError',
'OperationNotAllowed',
'PayloadTypeError',
'UnsupportedError',
'UnsupportedScopeError',
'WebSocketDisconnected',
'WebSocketHandlerNotFound',
'WebSocketPathNotFound',
'WebSocketServerError',
"CompatibilityError",
"DelimiterError",
"HeaderNotSupported",
"HTTPBadGateway",
"HTTPBadRequest",
"HTTPConflict",
"HTTPFailedDependency",
"HTTPForbidden",
"HTTPGatewayTimeout",
"HTTPGone",
"HTTPInsufficientStorage",
"HTTPInternalServerError",
"HTTPInvalidHeader",
"HTTPInvalidParam",
"HTTPLengthRequired",
"HTTPLocked",
"HTTPLoopDetected",
"HTTPMethodNotAllowed",
"HTTPMissingHeader",
"HTTPMissingParam",
"HTTPNetworkAuthenticationRequired",
"HTTPNotAcceptable",
"HTTPNotFound",
"HTTPNotImplemented",
"HTTPPayloadTooLarge",
"HTTPPreconditionFailed",
"HTTPPreconditionRequired",
"HTTPRangeNotSatisfiable",
"HTTPRequestHeaderFieldsTooLarge",
"HTTPRouteNotFound",
"HTTPServiceUnavailable",
"HTTPTooManyRequests",
"HTTPUnauthorized",
"HTTPUnavailableForLegalReasons",
"HTTPUnprocessableEntity",
"HTTPUnsupportedMediaType",
"HTTPUriTooLong",
"HTTPVersionNotSupported",
"MediaMalformedError",
"MediaNotFoundError",
"OperationNotAllowed",
"PayloadTypeError",
"UnsupportedError",
"UnsupportedScopeError",
"WebSocketDisconnected",
"WebSocketHandlerNotFound",
"WebSocketPathNotFound",
"WebSocketServerError",
)


class NoRouteName(Exception):
"""when a router's name has not been specified"""


class NoFunctionSpecified(Exception):
"""when a router's function has not been specified"""


class RouteAlreadyExists(Exception):
"""when a router is repeated"""


class MethodNotAvailable(Exception):
"""this is triggered when a method is not avaiable for a route"""


class ErrorCodeExists(Exception):
"""When a error code (like 404) is repeated"""


class ErrorHandlerExists(Exception):
"""This is triggered when a function with same name has another error code"""


class CustomBaseException(Exception):
"""Error used for server errors like 500 or 404"""
13 changes: 6 additions & 7 deletions expross/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@
import falcon
import os

"""
Expross is a web server for litle web projects
"""


class Expross(object):
"""Expross is a lightweight web server to introduce JavaScript developers familiar with Express to Python.
Expand All @@ -58,7 +53,6 @@ class Expross(object):
"""


default_host_name = "localhost"
default_port = 8000
default_templates = "templates"
Expand Down Expand Up @@ -89,7 +83,9 @@ def __init__(self, *argv, **kwargs):
self.jinja_env.lstrip_blocks = True
self.jinja_env.rstrip_blocks = True

def serve_static(self, route: str = "/" + default_static, folder: str = "./" + default_static):
def serve_static(
self, route: str = "/" + default_static, folder: str = "./" + default_static
):
"""Serves static files
Usage:
Expand Down Expand Up @@ -124,6 +120,7 @@ def error():
Args:
error (int | ErrorLike): error to be handled
"""

def decorator(func):

for err in self.errors:
Expand All @@ -144,6 +141,7 @@ def get(self, _route: str = None):
Args:
route (str): route to be added to the router's list
"""

def decorator(func):
self._check_for_repeated_route(_route, "GET", func)
_repeated = self._check_for_mentioned_route(_route)
Expand All @@ -163,6 +161,7 @@ def post(self, _route: str = None):
Args:
route (str): route to be added to the router's list
"""

def decorator(func):
self._check_for_repeated_route(_route, "POST", func)
_repeated = self._check_for_mentioned_route(_route)
Expand Down
1 change: 1 addition & 0 deletions expross/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

from falcon import Request, Response


class Resource:
"""This used every request the server recieves
Expand Down
1 change: 1 addition & 0 deletions expross/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from expross.resource import Resource
from typing import Callable


class Route(Resource):
"""This is a router service used for every individual route
Expand Down
1 change: 1 addition & 0 deletions expross/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

import re


class _ContentTypes:
"""A list of Content-Types used for a server response
Expand Down
1 change: 1 addition & 0 deletions expross/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@

import inspect


def get_response(data):
"""Create a response that will be directly used for a server response
Expand Down
4 changes: 3 additions & 1 deletion test/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

app.serve_static()


@app.error(HTTPNotFound)
def err():
return "<h1>ups! 404</h1>"
Expand All @@ -37,7 +38,7 @@ def err():
@app.get("/")
def main():

if app.req.params.get('pdf', None) == "active":
if app.req.params.get("pdf", None) == "active":
return app.redirect("/public/test.pdf")

return "<h1>Hello, world!</h1>"
Expand All @@ -47,4 +48,5 @@ def main():
def test(number: int):
return f"this is number is a {number}"


app.listen()

0 comments on commit 40bba8b

Please sign in to comment.