@@ -47,12 +47,12 @@ class BaseRobyn(ABC):
4747 """This is the python wrapper for the Robyn binaries."""
4848
4949 def __init__ (
50- self ,
51- file_object : str ,
52- config : Config = Config (),
53- openapi_file_path : Optional [str ] = None ,
54- openapi : Optional [OpenAPI ] = None ,
55- dependencies : DependencyMap = DependencyMap (),
50+ self ,
51+ file_object : str ,
52+ config : Config = Config (),
53+ openapi_file_path : Optional [str ] = None ,
54+ openapi : Optional [OpenAPI ] = None ,
55+ dependencies : DependencyMap = DependencyMap (),
5656 ) -> None :
5757 directory_path = os .path .dirname (os .path .abspath (file_object ))
5858 self .file_path = file_object
@@ -109,24 +109,21 @@ def _handle_dev_mode(self):
109109 is_robyn = os .getenv ("ROBYN_CLI" , False )
110110
111111 if cli_dev_mode and not is_robyn :
112- raise SystemExit (
113- "Dev mode is not supported in the python wrapper. Please use the Robyn CLI. e.g. python3 -m robyn app.py --dev" )
112+ raise SystemExit ("Dev mode is not supported in the python wrapper. Please use the Robyn CLI. e.g. python3 -m robyn app.py --dev" )
114113
115114 if env_dev_mode and not is_robyn :
116- logger .error (
117- "Ignoring ROBYN_DEV_MODE environment variable. Dev mode is not supported in the python wrapper." )
118- raise SystemExit (
119- "Dev mode is not supported in the python wrapper. Please use the Robyn CLI. e.g. python3 -m robyn app.py" )
115+ logger .error ("Ignoring ROBYN_DEV_MODE environment variable. Dev mode is not supported in the python wrapper." )
116+ raise SystemExit ("Dev mode is not supported in the python wrapper. Please use the Robyn CLI. e.g. python3 -m robyn app.py" )
120117
121118 def add_route (
122- self ,
123- route_type : Union [HttpMethod , str ],
124- endpoint : str ,
125- handler : Callable ,
126- is_const : bool = False ,
127- auth_required : bool = False ,
128- openapi_name : str = "" ,
129- openapi_tags : Union [List [str ], None ] = None ,
119+ self ,
120+ route_type : Union [HttpMethod , str ],
121+ endpoint : str ,
122+ handler : Callable ,
123+ is_const : bool = False ,
124+ auth_required : bool = False ,
125+ openapi_name : str = "" ,
126+ openapi_tags : Union [List [str ], None ] = None ,
130127 ):
131128 """
132129 Connect a URI to a handler
@@ -210,11 +207,11 @@ def after_request(self, endpoint: Optional[str] = None) -> Callable[..., None]:
210207 return self .middleware_router .add_middleware (MiddlewareType .AFTER_REQUEST , endpoint )
211208
212209 def serve_directory (
213- self ,
214- route : str ,
215- directory_path : str ,
216- index_file : Optional [str ] = None ,
217- show_files_listing : bool = False ,
210+ self ,
211+ route : str ,
212+ directory_path : str ,
213+ index_file : Optional [str ] = None ,
214+ show_files_listing : bool = False ,
218215 ):
219216 """
220217 Serves a directory at the given route
@@ -299,12 +296,12 @@ def exception(self, exception_handler: Callable):
299296 self .exception_handler = exception_handler
300297
301298 def get (
302- self ,
303- endpoint : str ,
304- const : bool = False ,
305- auth_required : bool = False ,
306- openapi_name : str = "" ,
307- openapi_tags : List [str ] = ["get" ],
299+ self ,
300+ endpoint : str ,
301+ const : bool = False ,
302+ auth_required : bool = False ,
303+ openapi_name : str = "" ,
304+ openapi_tags : List [str ] = ["get" ],
308305 ):
309306 """
310307 The @app.get decorator to add a route with the GET method
@@ -322,11 +319,11 @@ def inner(handler):
322319 return inner
323320
324321 def post (
325- self ,
326- endpoint : str ,
327- auth_required : bool = False ,
328- openapi_name : str = "" ,
329- openapi_tags : List [str ] = ["post" ],
322+ self ,
323+ endpoint : str ,
324+ auth_required : bool = False ,
325+ openapi_name : str = "" ,
326+ openapi_tags : List [str ] = ["post" ],
330327 ):
331328 """
332329 The @app.post decorator to add a route with POST method
@@ -338,17 +335,16 @@ def post(
338335 """
339336
340337 def inner (handler ):
341- return self .add_route (HttpMethod .POST , endpoint , handler , auth_required = auth_required ,
342- openapi_name = openapi_name , openapi_tags = openapi_tags )
338+ return self .add_route (HttpMethod .POST , endpoint , handler , auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
343339
344340 return inner
345341
346342 def put (
347- self ,
348- endpoint : str ,
349- auth_required : bool = False ,
350- openapi_name : str = "" ,
351- openapi_tags : List [str ] = ["put" ],
343+ self ,
344+ endpoint : str ,
345+ auth_required : bool = False ,
346+ openapi_name : str = "" ,
347+ openapi_tags : List [str ] = ["put" ],
352348 ):
353349 """
354350 The @app.put decorator to add a get route with PUT method
@@ -360,17 +356,16 @@ def put(
360356 """
361357
362358 def inner (handler ):
363- return self .add_route (HttpMethod .PUT , endpoint , handler , auth_required = auth_required ,
364- openapi_name = openapi_name , openapi_tags = openapi_tags )
359+ return self .add_route (HttpMethod .PUT , endpoint , handler , auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
365360
366361 return inner
367362
368363 def delete (
369- self ,
370- endpoint : str ,
371- auth_required : bool = False ,
372- openapi_name : str = "" ,
373- openapi_tags : List [str ] = ["delete" ],
364+ self ,
365+ endpoint : str ,
366+ auth_required : bool = False ,
367+ openapi_name : str = "" ,
368+ openapi_tags : List [str ] = ["delete" ],
374369 ):
375370 """
376371 The @app.delete decorator to add a route with DELETE method
@@ -382,17 +377,16 @@ def delete(
382377 """
383378
384379 def inner (handler ):
385- return self .add_route (HttpMethod .DELETE , endpoint , handler , auth_required = auth_required ,
386- openapi_name = openapi_name , openapi_tags = openapi_tags )
380+ return self .add_route (HttpMethod .DELETE , endpoint , handler , auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
387381
388382 return inner
389383
390384 def patch (
391- self ,
392- endpoint : str ,
393- auth_required : bool = False ,
394- openapi_name : str = "" ,
395- openapi_tags : List [str ] = ["patch" ],
385+ self ,
386+ endpoint : str ,
387+ auth_required : bool = False ,
388+ openapi_name : str = "" ,
389+ openapi_tags : List [str ] = ["patch" ],
396390 ):
397391 """
398392 The @app.patch decorator to add a route with PATCH method
@@ -404,17 +398,16 @@ def patch(
404398 """
405399
406400 def inner (handler ):
407- return self .add_route (HttpMethod .PATCH , endpoint , handler , auth_required = auth_required ,
408- openapi_name = openapi_name , openapi_tags = openapi_tags )
401+ return self .add_route (HttpMethod .PATCH , endpoint , handler , auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
409402
410403 return inner
411404
412405 def head (
413- self ,
414- endpoint : str ,
415- auth_required : bool = False ,
416- openapi_name : str = "" ,
417- openapi_tags : List [str ] = ["head" ],
406+ self ,
407+ endpoint : str ,
408+ auth_required : bool = False ,
409+ openapi_name : str = "" ,
410+ openapi_tags : List [str ] = ["head" ],
418411 ):
419412 """
420413 The @app.head decorator to add a route with HEAD method
@@ -426,17 +419,16 @@ def head(
426419 """
427420
428421 def inner (handler ):
429- return self .add_route (HttpMethod .HEAD , endpoint , handler , auth_required = auth_required ,
430- openapi_name = openapi_name , openapi_tags = openapi_tags )
422+ return self .add_route (HttpMethod .HEAD , endpoint , handler , auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
431423
432424 return inner
433425
434426 def options (
435- self ,
436- endpoint : str ,
437- auth_required : bool = False ,
438- openapi_name : str = "" ,
439- openapi_tags : List [str ] = ["options" ],
427+ self ,
428+ endpoint : str ,
429+ auth_required : bool = False ,
430+ openapi_name : str = "" ,
431+ openapi_tags : List [str ] = ["options" ],
440432 ):
441433 """
442434 The @app.options decorator to add a route with OPTIONS method
@@ -448,17 +440,16 @@ def options(
448440 """
449441
450442 def inner (handler ):
451- return self .add_route (HttpMethod .OPTIONS , endpoint , handler , auth_required = auth_required ,
452- openapi_name = openapi_name , openapi_tags = openapi_tags )
443+ return self .add_route (HttpMethod .OPTIONS , endpoint , handler , auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
453444
454445 return inner
455446
456447 def connect (
457- self ,
458- endpoint : str ,
459- auth_required : bool = False ,
460- openapi_name : str = "" ,
461- openapi_tags : List [str ] = ["connect" ],
448+ self ,
449+ endpoint : str ,
450+ auth_required : bool = False ,
451+ openapi_name : str = "" ,
452+ openapi_tags : List [str ] = ["connect" ],
462453 ):
463454 """
464455 The @app.connect decorator to add a route with CONNECT method
@@ -470,17 +461,16 @@ def connect(
470461 """
471462
472463 def inner (handler ):
473- return self .add_route (HttpMethod .CONNECT , endpoint , handler , auth_required = auth_required ,
474- openapi_name = openapi_name , openapi_tags = openapi_tags )
464+ return self .add_route (HttpMethod .CONNECT , endpoint , handler , auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
475465
476466 return inner
477467
478468 def trace (
479- self ,
480- endpoint : str ,
481- auth_required : bool = False ,
482- openapi_name : str = "" ,
483- openapi_tags : List [str ] = ["trace" ],
469+ self ,
470+ endpoint : str ,
471+ auth_required : bool = False ,
472+ openapi_name : str = "" ,
473+ openapi_tags : List [str ] = ["trace" ],
484474 ):
485475 """
486476 The @app.trace decorator to add a route with TRACE method
@@ -492,8 +482,7 @@ def trace(
492482 """
493483
494484 def inner (handler ):
495- return self .add_route (HttpMethod .TRACE , endpoint , handler , auth_required = auth_required ,
496- openapi_name = openapi_name , openapi_tags = openapi_tags )
485+ return self .add_route (HttpMethod .TRACE , endpoint , handler , auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
497486
498487 return inner
499488
@@ -611,53 +600,36 @@ def start(self, host: str = "127.0.0.1", port: int = 8080, _check_port: bool = T
611600
612601
613602class SubRouter (BaseRobyn ):
614- def __init__ (self , file_object : str , prefix : str = "" , config : Config = Config (),
615- openapi : OpenAPI = OpenAPI ()) -> None :
603+ def __init__ (self , file_object : str , prefix : str = "" , config : Config = Config (), openapi : OpenAPI = OpenAPI ()) -> None :
616604 super ().__init__ (file_object = file_object , config = config , openapi = openapi )
617605 self .prefix = prefix
618606
619607 def __add_prefix (self , endpoint : str ):
620608 return f"{ self .prefix } { endpoint } "
621609
622- def get (self , endpoint : str , const : bool = False , auth_required : bool = False , openapi_name : str = "" ,
623- openapi_tags : List [str ] = ["get" ]):
624- return super ().get (endpoint = self .__add_prefix (endpoint ), const = const , auth_required = auth_required ,
625- openapi_name = openapi_name , openapi_tags = openapi_tags )
626-
627- def post (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" ,
628- openapi_tags : List [str ] = ["post" ]):
629- return super ().post (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required ,
630- openapi_name = openapi_name , openapi_tags = openapi_tags )
631-
632- def put (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" ,
633- openapi_tags : List [str ] = ["put" ]):
634- return super ().put (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required , openapi_name = openapi_name ,
635- openapi_tags = openapi_tags )
636-
637- def delete (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" ,
638- openapi_tags : List [str ] = ["delete" ]):
639- return super ().delete (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required ,
640- openapi_name = openapi_name , openapi_tags = openapi_tags )
641-
642- def patch (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" ,
643- openapi_tags : List [str ] = ["patch" ]):
644- return super ().patch (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required ,
645- openapi_name = openapi_name , openapi_tags = openapi_tags )
646-
647- def head (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" ,
648- openapi_tags : List [str ] = ["head" ]):
649- return super ().head (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required ,
650- openapi_name = openapi_name , openapi_tags = openapi_tags )
651-
652- def trace (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" ,
653- openapi_tags : List [str ] = ["trace" ]):
654- return super ().trace (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required ,
655- openapi_name = openapi_name , openapi_tags = openapi_tags )
656-
657- def options (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" ,
658- openapi_tags : List [str ] = ["options" ]):
659- return super ().options (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required ,
660- openapi_name = openapi_name , openapi_tags = openapi_tags )
610+ def get (self , endpoint : str , const : bool = False , auth_required : bool = False , openapi_name : str = "" , openapi_tags : List [str ] = ["get" ]):
611+ return super ().get (endpoint = self .__add_prefix (endpoint ), const = const , auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
612+
613+ def post (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" , openapi_tags : List [str ] = ["post" ]):
614+ return super ().post (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
615+
616+ def put (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" , openapi_tags : List [str ] = ["put" ]):
617+ return super ().put (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
618+
619+ def delete (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" , openapi_tags : List [str ] = ["delete" ]):
620+ return super ().delete (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
621+
622+ def patch (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" , openapi_tags : List [str ] = ["patch" ]):
623+ return super ().patch (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
624+
625+ def head (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" , openapi_tags : List [str ] = ["head" ]):
626+ return super ().head (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
627+
628+ def trace (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" , openapi_tags : List [str ] = ["trace" ]):
629+ return super ().trace (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
630+
631+ def options (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" , openapi_tags : List [str ] = ["options" ]):
632+ return super ().options (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
661633
662634
663635def ALLOW_CORS (app : Robyn , origins : Union [List [str ], str ], headers : Union [List [str ], str ] = None ):
0 commit comments