@@ -629,12 +629,17 @@ def _to_response(self, result: Union[Dict, Response]) -> Response:
629
629
def _json_dump (self , obj : Any ) -> str :
630
630
return self ._serializer (obj )
631
631
632
+ def register_blueprint (self , blueprint : "Blueprint" ) -> None :
633
+ """Adds all routes defined in a blueprint"""
634
+ for route , func in blueprint .api .items ():
635
+ self .route (* route )(func (app = self ))
636
+
632
637
633
638
class Blueprint :
634
639
"""Blueprint helper class to allow splitting ApiGatewayResolver into multiple files"""
635
640
636
641
def __init__ (self ):
637
- self ._api : Dict [tuple , Callable ] = {}
642
+ self .api : Dict [tuple , Callable ] = {}
638
643
639
644
def route (
640
645
self ,
@@ -654,9 +659,9 @@ def inner_wrapper():
654
659
655
660
if isinstance (method , (list , tuple )):
656
661
for item in method :
657
- self ._api [(rule , item , cors , compress , cache_control )] = wrapper
662
+ self .api [(rule , item , cors , compress , cache_control )] = wrapper
658
663
else :
659
- self ._api [(rule , method , cors , compress , cache_control )] = wrapper
664
+ self .api [(rule , method , cors , compress , cache_control )] = wrapper
660
665
661
666
return actual_decorator
662
667
@@ -678,8 +683,3 @@ def patch(
678
683
self , rule : str , cors : Optional [bool ] = None , compress : bool = False , cache_control : Optional [str ] = None
679
684
):
680
685
return self .route (rule , "PATCH" , cors , compress , cache_control )
681
-
682
- def register_to_app (self , app : ApiGatewayResolver ):
683
- """Bind a blueprint object to an existing ApiGatewayResolver instance"""
684
- for route , func in self ._api .items ():
685
- app .route (* route )(func (app = app ))
0 commit comments