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