Skip to content

Commit

Permalink
Join wrappers on only one module
Browse files Browse the repository at this point in the history
  • Loading branch information
nycholas committed Sep 27, 2024
1 parent ab5463d commit 889e4ca
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 66 deletions.
6 changes: 1 addition & 5 deletions src/flask_jsonrpc/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

from .globals import default_jsonrpc_site, default_jsonrpc_site_api
from .helpers import urn
from .handlers import JSONRPCErrorHandlerDecoratorMixin
from .wrappers import JSONRPCDecoratorMixin
from .contrib.browse import JSONRPCBrowse

Expand All @@ -47,7 +46,7 @@
from .blueprints import JSONRPCBlueprint


class JSONRPC(JSONRPCDecoratorMixin, JSONRPCErrorHandlerDecoratorMixin):
class JSONRPC(JSONRPCDecoratorMixin):
def __init__(
self: Self,
app: t.Optional[Flask] = None,
Expand Down Expand Up @@ -136,9 +135,6 @@ def register_blueprint(
if app.config['DEBUG'] or enable_web_browsable_api:
self.register_browse(jsonrpc_app)

def register_error_handler(self: Self, exception: t.Type[Exception], fn: t.Callable[[t.Any], t.Any]) -> None:
super().register_error_handler(exception, fn)

def init_browse_app(self: Self, app: Flask, path: t.Optional[str] = None, base_url: t.Optional[str] = None) -> None:
browse_url = self._make_jsonrpc_browse_url(path or self.path)
self.jsonrpc_browse = JSONRPCBrowse(app, url_prefix=browse_url, base_url=base_url or self.base_url)
Expand Down
8 changes: 1 addition & 7 deletions src/flask_jsonrpc/blueprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@
# POSSIBILITY OF SUCH DAMAGE.
import typing as t

from flask import typing as ft

from .globals import default_jsonrpc_site, default_jsonrpc_site_api
from .handlers import JSONRPCErrorHandlerDecoratorMixin
from .wrappers import JSONRPCDecoratorMixin

# Python 3.10+
Expand All @@ -43,7 +40,7 @@
from .views import JSONRPCView


class JSONRPCBlueprint(JSONRPCDecoratorMixin, JSONRPCErrorHandlerDecoratorMixin):
class JSONRPCBlueprint(JSONRPCDecoratorMixin):
def __init__(
self: Self,
name: str,
Expand All @@ -61,6 +58,3 @@ def get_jsonrpc_site(self: Self) -> 'JSONRPCSite':

def get_jsonrpc_site_api(self: Self) -> t.Type['JSONRPCView']:
return self.jsonrpc_site_api

def register_error_handler(self: Self, exception: t.Type[Exception], fn: ft.ErrorHandlerCallable) -> None:
super().register_error_handler(exception, fn)
53 changes: 0 additions & 53 deletions src/flask_jsonrpc/handlers.py

This file was deleted.

2 changes: 1 addition & 1 deletion src/flask_jsonrpc/site.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def batch_dispatch(
resp_views = []
headers = Headers()
status_code = JSONRPC_DEFAULT_HTTP_STATUS_CODE
for rv, _, hdrs in (self.handle_dispatch_except(rq) for rq in reqs_json):
for rv, _, hdrs in [self.handle_dispatch_except(rq) for rq in reqs_json]:
headers.update([hdrs] if isinstance(hdrs, tuple) else hdrs) # type: ignore
if rv is None:
continue
Expand Down
12 changes: 12 additions & 0 deletions src/flask_jsonrpc/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,15 @@ def decorator(fn: t.Callable[..., t.Any]) -> t.Callable[..., t.Any]:
return self.register_view_function(fn, name, **options)

return decorator

def register_error_handler(self: Self, exception: t.Type[Exception], fn: t.Callable[[t.Any], t.Any]) -> None:
self.get_jsonrpc_site().register_error_handler(exception, fn)

def errorhandler(
self: Self, exception: t.Type[Exception]
) -> t.Callable[[t.Callable[[t.Any], t.Any]], t.Callable[[t.Any], t.Any]]:
def decorator(fn: t.Callable[[t.Any], t.Any]) -> t.Callable[[t.Any], t.Any]:
self.register_error_handler(exception, fn)
return fn

return decorator

0 comments on commit 889e4ca

Please sign in to comment.