Skip to content

Commit 5b45da0

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 02ee414 commit 5b45da0

File tree

6 files changed

+303
-393
lines changed

6 files changed

+303
-393
lines changed

robyn/__init__.py

Lines changed: 100 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ class BaseRobyn(ABC):
3939
"""This is the python wrapper for the Robyn binaries."""
4040

4141
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(),
4848
) -> None:
4949
directory_path = os.path.dirname(os.path.abspath(file_object))
5050
self.file_path = file_object
@@ -101,24 +101,21 @@ def _handle_dev_mode(self):
101101
is_robyn = os.getenv("ROBYN_CLI", False)
102102

103103
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")
106105

107106
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")
112109

113110
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,
122119
):
123120
"""
124121
Connect a URI to a handler
@@ -202,11 +199,11 @@ def after_request(self, endpoint: Optional[str] = None) -> Callable[..., None]:
202199
return self.middleware_router.add_middleware(MiddlewareType.AFTER_REQUEST, endpoint)
203200

204201
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,
210207
):
211208
"""
212209
Serves a directory at the given route
@@ -291,12 +288,12 @@ def exception(self, exception_handler: Callable):
291288
self.exception_handler = exception_handler
292289

293290
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"],
300297
):
301298
"""
302299
The @app.get decorator to add a route with the GET method
@@ -314,11 +311,11 @@ def inner(handler):
314311
return inner
315312

316313
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"],
322319
):
323320
"""
324321
The @app.post decorator to add a route with POST method
@@ -330,17 +327,16 @@ def post(
330327
"""
331328

332329
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)
335331

336332
return inner
337333

338334
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"],
344340
):
345341
"""
346342
The @app.put decorator to add a get route with PUT method
@@ -352,17 +348,16 @@ def put(
352348
"""
353349

354350
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)
357352

358353
return inner
359354

360355
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"],
366361
):
367362
"""
368363
The @app.delete decorator to add a route with DELETE method
@@ -374,17 +369,16 @@ def delete(
374369
"""
375370

376371
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)
379373

380374
return inner
381375

382376
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"],
388382
):
389383
"""
390384
The @app.patch decorator to add a route with PATCH method
@@ -396,17 +390,16 @@ def patch(
396390
"""
397391

398392
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)
401394

402395
return inner
403396

404397
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"],
410403
):
411404
"""
412405
The @app.head decorator to add a route with HEAD method
@@ -418,17 +411,16 @@ def head(
418411
"""
419412

420413
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)
423415

424416
return inner
425417

426418
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"],
432424
):
433425
"""
434426
The @app.options decorator to add a route with OPTIONS method
@@ -440,17 +432,16 @@ def options(
440432
"""
441433

442434
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)
445436

446437
return inner
447438

448439
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"],
454445
):
455446
"""
456447
The @app.connect decorator to add a route with CONNECT method
@@ -462,17 +453,16 @@ def connect(
462453
"""
463454

464455
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)
467457

468458
return inner
469459

470460
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"],
476466
):
477467
"""
478468
The @app.trace decorator to add a route with TRACE method
@@ -484,8 +474,7 @@ def trace(
484474
"""
485475

486476
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)
489478

490479
return inner
491480

@@ -603,53 +592,36 @@ def start(self, host: str = "127.0.0.1", port: int = 8080, _check_port: bool = T
603592

604593

605594
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:
608596
super().__init__(file_object=file_object, config=config, openapi=openapi)
609597
self.prefix = prefix
610598

611599
def __add_prefix(self, endpoint: str):
612600
return f"{self.prefix}{endpoint}"
613601

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)
653625

654626

655627
def ALLOW_CORS(app: Robyn, origins: Union[List[str], str], headers: Union[List[str], str] = None):

robyn/argument_parser.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import argparse
22
import os
3-
import sys
43

54

65
class Config:

0 commit comments

Comments
 (0)