@@ -39,12 +39,12 @@ class BaseRobyn(ABC):
39
39
"""This is the python wrapper for the Robyn binaries."""
40
40
41
41
def __init__ (
42
- self ,
43
- file_object : str ,
44
- config : Config = Config (),
45
- openapi_file_path : Optional [str ] = None ,
46
- openapi : Optional [OpenAPI ] = None ,
47
- dependencies : DependencyMap = DependencyMap (),
42
+ self ,
43
+ file_object : str ,
44
+ config : Config = Config (),
45
+ openapi_file_path : Optional [str ] = None ,
46
+ openapi : Optional [OpenAPI ] = None ,
47
+ dependencies : DependencyMap = DependencyMap (),
48
48
) -> None :
49
49
directory_path = os .path .dirname (os .path .abspath (file_object ))
50
50
self .file_path = file_object
@@ -101,24 +101,21 @@ def _handle_dev_mode(self):
101
101
is_robyn = os .getenv ("ROBYN_CLI" , False )
102
102
103
103
if cli_dev_mode and not is_robyn :
104
- raise SystemExit (
105
- "Dev mode is not supported in the python wrapper. Please use the Robyn CLI. e.g. python3 -m robyn app.py --dev" )
104
+ raise SystemExit ("Dev mode is not supported in the python wrapper. Please use the Robyn CLI. e.g. python3 -m robyn app.py --dev" )
106
105
107
106
if env_dev_mode and not is_robyn :
108
- logger .error (
109
- "Ignoring ROBYN_DEV_MODE environment variable. Dev mode is not supported in the python wrapper." )
110
- raise SystemExit (
111
- "Dev mode is not supported in the python wrapper. Please use the Robyn CLI. e.g. python3 -m robyn app.py" )
107
+ logger .error ("Ignoring ROBYN_DEV_MODE environment variable. Dev mode is not supported in the python wrapper." )
108
+ raise SystemExit ("Dev mode is not supported in the python wrapper. Please use the Robyn CLI. e.g. python3 -m robyn app.py" )
112
109
113
110
def add_route (
114
- self ,
115
- route_type : Union [HttpMethod , str ],
116
- endpoint : str ,
117
- handler : Callable ,
118
- is_const : bool = False ,
119
- auth_required : bool = False ,
120
- openapi_name : str = "" ,
121
- openapi_tags : Union [List [str ], None ] = None ,
111
+ self ,
112
+ route_type : Union [HttpMethod , str ],
113
+ endpoint : str ,
114
+ handler : Callable ,
115
+ is_const : bool = False ,
116
+ auth_required : bool = False ,
117
+ openapi_name : str = "" ,
118
+ openapi_tags : Union [List [str ], None ] = None ,
122
119
):
123
120
"""
124
121
Connect a URI to a handler
@@ -202,11 +199,11 @@ def after_request(self, endpoint: Optional[str] = None) -> Callable[..., None]:
202
199
return self .middleware_router .add_middleware (MiddlewareType .AFTER_REQUEST , endpoint )
203
200
204
201
def serve_directory (
205
- self ,
206
- route : str ,
207
- directory_path : str ,
208
- index_file : Optional [str ] = None ,
209
- show_files_listing : bool = False ,
202
+ self ,
203
+ route : str ,
204
+ directory_path : str ,
205
+ index_file : Optional [str ] = None ,
206
+ show_files_listing : bool = False ,
210
207
):
211
208
"""
212
209
Serves a directory at the given route
@@ -291,12 +288,12 @@ def exception(self, exception_handler: Callable):
291
288
self .exception_handler = exception_handler
292
289
293
290
def get (
294
- self ,
295
- endpoint : str ,
296
- const : bool = False ,
297
- auth_required : bool = False ,
298
- openapi_name : str = "" ,
299
- openapi_tags : List [str ] = ["get" ],
291
+ self ,
292
+ endpoint : str ,
293
+ const : bool = False ,
294
+ auth_required : bool = False ,
295
+ openapi_name : str = "" ,
296
+ openapi_tags : List [str ] = ["get" ],
300
297
):
301
298
"""
302
299
The @app.get decorator to add a route with the GET method
@@ -314,11 +311,11 @@ def inner(handler):
314
311
return inner
315
312
316
313
def post (
317
- self ,
318
- endpoint : str ,
319
- auth_required : bool = False ,
320
- openapi_name : str = "" ,
321
- openapi_tags : List [str ] = ["post" ],
314
+ self ,
315
+ endpoint : str ,
316
+ auth_required : bool = False ,
317
+ openapi_name : str = "" ,
318
+ openapi_tags : List [str ] = ["post" ],
322
319
):
323
320
"""
324
321
The @app.post decorator to add a route with POST method
@@ -330,17 +327,16 @@ def post(
330
327
"""
331
328
332
329
def inner (handler ):
333
- return self .add_route (HttpMethod .POST , endpoint , handler , auth_required = auth_required ,
334
- openapi_name = openapi_name , openapi_tags = openapi_tags )
330
+ return self .add_route (HttpMethod .POST , endpoint , handler , auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
335
331
336
332
return inner
337
333
338
334
def put (
339
- self ,
340
- endpoint : str ,
341
- auth_required : bool = False ,
342
- openapi_name : str = "" ,
343
- openapi_tags : List [str ] = ["put" ],
335
+ self ,
336
+ endpoint : str ,
337
+ auth_required : bool = False ,
338
+ openapi_name : str = "" ,
339
+ openapi_tags : List [str ] = ["put" ],
344
340
):
345
341
"""
346
342
The @app.put decorator to add a get route with PUT method
@@ -352,17 +348,16 @@ def put(
352
348
"""
353
349
354
350
def inner (handler ):
355
- return self .add_route (HttpMethod .PUT , endpoint , handler , auth_required = auth_required ,
356
- openapi_name = openapi_name , openapi_tags = openapi_tags )
351
+ return self .add_route (HttpMethod .PUT , endpoint , handler , auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
357
352
358
353
return inner
359
354
360
355
def delete (
361
- self ,
362
- endpoint : str ,
363
- auth_required : bool = False ,
364
- openapi_name : str = "" ,
365
- openapi_tags : List [str ] = ["delete" ],
356
+ self ,
357
+ endpoint : str ,
358
+ auth_required : bool = False ,
359
+ openapi_name : str = "" ,
360
+ openapi_tags : List [str ] = ["delete" ],
366
361
):
367
362
"""
368
363
The @app.delete decorator to add a route with DELETE method
@@ -374,17 +369,16 @@ def delete(
374
369
"""
375
370
376
371
def inner (handler ):
377
- return self .add_route (HttpMethod .DELETE , endpoint , handler , auth_required = auth_required ,
378
- openapi_name = openapi_name , openapi_tags = openapi_tags )
372
+ return self .add_route (HttpMethod .DELETE , endpoint , handler , auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
379
373
380
374
return inner
381
375
382
376
def patch (
383
- self ,
384
- endpoint : str ,
385
- auth_required : bool = False ,
386
- openapi_name : str = "" ,
387
- openapi_tags : List [str ] = ["patch" ],
377
+ self ,
378
+ endpoint : str ,
379
+ auth_required : bool = False ,
380
+ openapi_name : str = "" ,
381
+ openapi_tags : List [str ] = ["patch" ],
388
382
):
389
383
"""
390
384
The @app.patch decorator to add a route with PATCH method
@@ -396,17 +390,16 @@ def patch(
396
390
"""
397
391
398
392
def inner (handler ):
399
- return self .add_route (HttpMethod .PATCH , endpoint , handler , auth_required = auth_required ,
400
- openapi_name = openapi_name , openapi_tags = openapi_tags )
393
+ return self .add_route (HttpMethod .PATCH , endpoint , handler , auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
401
394
402
395
return inner
403
396
404
397
def head (
405
- self ,
406
- endpoint : str ,
407
- auth_required : bool = False ,
408
- openapi_name : str = "" ,
409
- openapi_tags : List [str ] = ["head" ],
398
+ self ,
399
+ endpoint : str ,
400
+ auth_required : bool = False ,
401
+ openapi_name : str = "" ,
402
+ openapi_tags : List [str ] = ["head" ],
410
403
):
411
404
"""
412
405
The @app.head decorator to add a route with HEAD method
@@ -418,17 +411,16 @@ def head(
418
411
"""
419
412
420
413
def inner (handler ):
421
- return self .add_route (HttpMethod .HEAD , endpoint , handler , auth_required = auth_required ,
422
- openapi_name = openapi_name , openapi_tags = openapi_tags )
414
+ return self .add_route (HttpMethod .HEAD , endpoint , handler , auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
423
415
424
416
return inner
425
417
426
418
def options (
427
- self ,
428
- endpoint : str ,
429
- auth_required : bool = False ,
430
- openapi_name : str = "" ,
431
- openapi_tags : List [str ] = ["options" ],
419
+ self ,
420
+ endpoint : str ,
421
+ auth_required : bool = False ,
422
+ openapi_name : str = "" ,
423
+ openapi_tags : List [str ] = ["options" ],
432
424
):
433
425
"""
434
426
The @app.options decorator to add a route with OPTIONS method
@@ -440,17 +432,16 @@ def options(
440
432
"""
441
433
442
434
def inner (handler ):
443
- return self .add_route (HttpMethod .OPTIONS , endpoint , handler , auth_required = auth_required ,
444
- openapi_name = openapi_name , openapi_tags = openapi_tags )
435
+ return self .add_route (HttpMethod .OPTIONS , endpoint , handler , auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
445
436
446
437
return inner
447
438
448
439
def connect (
449
- self ,
450
- endpoint : str ,
451
- auth_required : bool = False ,
452
- openapi_name : str = "" ,
453
- openapi_tags : List [str ] = ["connect" ],
440
+ self ,
441
+ endpoint : str ,
442
+ auth_required : bool = False ,
443
+ openapi_name : str = "" ,
444
+ openapi_tags : List [str ] = ["connect" ],
454
445
):
455
446
"""
456
447
The @app.connect decorator to add a route with CONNECT method
@@ -462,17 +453,16 @@ def connect(
462
453
"""
463
454
464
455
def inner (handler ):
465
- return self .add_route (HttpMethod .CONNECT , endpoint , handler , auth_required = auth_required ,
466
- openapi_name = openapi_name , openapi_tags = openapi_tags )
456
+ return self .add_route (HttpMethod .CONNECT , endpoint , handler , auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
467
457
468
458
return inner
469
459
470
460
def trace (
471
- self ,
472
- endpoint : str ,
473
- auth_required : bool = False ,
474
- openapi_name : str = "" ,
475
- openapi_tags : List [str ] = ["trace" ],
461
+ self ,
462
+ endpoint : str ,
463
+ auth_required : bool = False ,
464
+ openapi_name : str = "" ,
465
+ openapi_tags : List [str ] = ["trace" ],
476
466
):
477
467
"""
478
468
The @app.trace decorator to add a route with TRACE method
@@ -484,8 +474,7 @@ def trace(
484
474
"""
485
475
486
476
def inner (handler ):
487
- return self .add_route (HttpMethod .TRACE , endpoint , handler , auth_required = auth_required ,
488
- openapi_name = openapi_name , openapi_tags = openapi_tags )
477
+ return self .add_route (HttpMethod .TRACE , endpoint , handler , auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
489
478
490
479
return inner
491
480
@@ -603,53 +592,36 @@ def start(self, host: str = "127.0.0.1", port: int = 8080, _check_port: bool = T
603
592
604
593
605
594
class SubRouter (BaseRobyn ):
606
- def __init__ (self , file_object : str , prefix : str = "" , config : Config = Config (),
607
- openapi : OpenAPI = OpenAPI ()) -> None :
595
+ def __init__ (self , file_object : str , prefix : str = "" , config : Config = Config (), openapi : OpenAPI = OpenAPI ()) -> None :
608
596
super ().__init__ (file_object = file_object , config = config , openapi = openapi )
609
597
self .prefix = prefix
610
598
611
599
def __add_prefix (self , endpoint : str ):
612
600
return f"{ self .prefix } { endpoint } "
613
601
614
- def get (self , endpoint : str , const : bool = False , auth_required : bool = False , openapi_name : str = "" ,
615
- openapi_tags : List [str ] = ["get" ]):
616
- return super ().get (endpoint = self .__add_prefix (endpoint ), const = const , auth_required = auth_required ,
617
- openapi_name = openapi_name , openapi_tags = openapi_tags )
618
-
619
- def post (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" ,
620
- openapi_tags : List [str ] = ["post" ]):
621
- return super ().post (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required ,
622
- openapi_name = openapi_name , openapi_tags = openapi_tags )
623
-
624
- def put (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" ,
625
- openapi_tags : List [str ] = ["put" ]):
626
- return super ().put (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required , openapi_name = openapi_name ,
627
- openapi_tags = openapi_tags )
628
-
629
- def delete (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" ,
630
- openapi_tags : List [str ] = ["delete" ]):
631
- return super ().delete (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required ,
632
- openapi_name = openapi_name , openapi_tags = openapi_tags )
633
-
634
- def patch (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" ,
635
- openapi_tags : List [str ] = ["patch" ]):
636
- return super ().patch (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required ,
637
- openapi_name = openapi_name , openapi_tags = openapi_tags )
638
-
639
- def head (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" ,
640
- openapi_tags : List [str ] = ["head" ]):
641
- return super ().head (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required ,
642
- openapi_name = openapi_name , openapi_tags = openapi_tags )
643
-
644
- def trace (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" ,
645
- openapi_tags : List [str ] = ["trace" ]):
646
- return super ().trace (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required ,
647
- openapi_name = openapi_name , openapi_tags = openapi_tags )
648
-
649
- def options (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" ,
650
- openapi_tags : List [str ] = ["options" ]):
651
- return super ().options (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required ,
652
- openapi_name = openapi_name , openapi_tags = openapi_tags )
602
+ def get (self , endpoint : str , const : bool = False , auth_required : bool = False , openapi_name : str = "" , openapi_tags : List [str ] = ["get" ]):
603
+ return super ().get (endpoint = self .__add_prefix (endpoint ), const = const , auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
604
+
605
+ def post (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" , openapi_tags : List [str ] = ["post" ]):
606
+ return super ().post (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
607
+
608
+ def put (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" , openapi_tags : List [str ] = ["put" ]):
609
+ return super ().put (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
610
+
611
+ def delete (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" , openapi_tags : List [str ] = ["delete" ]):
612
+ return super ().delete (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
613
+
614
+ def patch (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" , openapi_tags : List [str ] = ["patch" ]):
615
+ return super ().patch (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
616
+
617
+ def head (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" , openapi_tags : List [str ] = ["head" ]):
618
+ return super ().head (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
619
+
620
+ def trace (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" , openapi_tags : List [str ] = ["trace" ]):
621
+ return super ().trace (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
622
+
623
+ def options (self , endpoint : str , auth_required : bool = False , openapi_name : str = "" , openapi_tags : List [str ] = ["options" ]):
624
+ return super ().options (endpoint = self .__add_prefix (endpoint ), auth_required = auth_required , openapi_name = openapi_name , openapi_tags = openapi_tags )
653
625
654
626
655
627
def ALLOW_CORS (app : Robyn , origins : Union [List [str ], str ], headers : Union [List [str ], str ] = None ):
0 commit comments