1919from threading import Thread
2020from types import FrameType as Frame
2121from types import TracebackType as Traceback
22- from typing import (
23- Any ,
24- AsyncIterator ,
25- Callable ,
26- Coroutine ,
27- Generic ,
28- Iterable ,
29- TextIO ,
30- TypeVar ,
31- get_type_hints ,
32- overload ,
33- )
22+ from typing import (Any , AsyncIterator , Callable , Coroutine , Generic , Iterable ,
23+ TextIO , TypeVar , get_type_hints , overload )
3424from urllib .parse import urlencode
3525
3626import ujson
4333from .__main__ import welcome
4434from ._docs import markdown_docs
4535from ._loader import finalize , load_fs , load_patterns , load_simple
46- from ._logging import (
47- LOGS ,
48- Internal ,
49- Service ,
50- enter_server ,
51- exit_server ,
52- format_warnings ,
53- )
36+ from ._logging import (LOGS , Internal , Service , enter_server , exit_server ,
37+ format_warnings )
5438from ._parsers import supply_parsers
5539from ._util import make_hint , needs_dep
5640from .build import build_app , build_steps
5741from .config import Config , load_config
58- from .exceptions import (
59- BadEnvironmentError ,
60- InvalidCustomLoaderError ,
61- ViewError ,
62- ViewInternalError ,
63- )
42+ from .exceptions import (BadEnvironmentError , InvalidCustomLoaderError ,
43+ ViewError , ViewInternalError )
6444from .logging import _LogArgs , log
6545from .response import HTML
6646from .routing import Path as _RouteDeco
67- from .routing import (
68- Route ,
69- RouteInput ,
70- RouteOrCallable ,
71- RouteOrWebsocket ,
72- V ,
73- _NoDefault ,
74- _NoDefaultType ,
75- )
47+ from .routing import (Route , RouteInput , RouteOrCallable , RouteOrWebsocket , V ,
48+ _NoDefault , _NoDefaultType )
7649from .routing import body as body_impl
7750from .routing import context as context_impl
7851from .routing import delete , get , options , patch , post , put
9265T = TypeVar ("T" )
9366P = ParamSpec ("P" )
9467
95- _ROUTES_WARN_MSG = "routes argument should only be passed when load strategy is manual"
68+ _ROUTES_WARN_MSG = (
69+ "routes argument should only be passed when load strategy is manual"
70+ )
9671_ConfigSpecified = None
9772
9873B = TypeVar ("B" , bound = BaseException )
@@ -202,7 +177,9 @@ async def _server_send(self, data: dict):
202177 self .send_queue .put_nowait (data )
203178
204179 async def send (self , message : str ) -> None :
205- self .recv_queue .put_nowait ({"type" : "websocket.receive" , "text" : message })
180+ self .recv_queue .put_nowait (
181+ {"type" : "websocket.receive" , "text" : message }
182+ )
206183
207184 async def receive (self ) -> str :
208185 data = await _to_thread (self .send_queue .get )
@@ -217,7 +194,9 @@ async def receive(self) -> str:
217194 return msg
218195
219196 async def handshake (self ) -> None :
220- assert (await _to_thread (self .send_queue .get ))["type" ] == "websocket.accept"
197+ assert (await _to_thread (self .send_queue .get ))[
198+ "type"
199+ ] == "websocket.accept"
221200
222201
223202class TestingContext :
@@ -241,9 +220,12 @@ async def send(_: dict[str, Any]):
241220 async def stop (self ) -> None :
242221 await self ._lifespan .put ("lifespan.shutdown" )
243222
244- def _gen_headers (self , headers : dict [str , str ]) -> list [tuple [bytes , bytes ]]:
223+ def _gen_headers (
224+ self , headers : dict [str , str ]
225+ ) -> list [tuple [bytes , bytes ]]:
245226 return [
246- (key .encode (), value .encode ()) for key , value in (headers or {}).items ()
227+ (key .encode (), value .encode ())
228+ for key , value in (headers or {}).items ()
247229 ]
248230
249231 def _truncate (self , route : str ) -> str :
@@ -477,7 +459,9 @@ def __init__(self, status: int = 400, message: str | None = None) -> None:
477459 message: The (optional) message to send back to the client. If none, uses the default error message (e.g. `Bad Request` for status `400`).
478460 """
479461 if status not in ERROR_CODES :
480- raise InvalidStatusError ("status code can only be a client or server error" )
462+ raise InvalidStatusError (
463+ "status code can only be a client or server error"
464+ )
481465
482466 self .status = status
483467 self .message = message
@@ -541,7 +525,9 @@ def _hook(tp: type[B], value: B, traceback: Traceback) -> None:
541525 print (value .hint )
542526
543527 if isinstance (value , ViewInternalError ):
544- print ("[bold dim red]This is an internal error, not your fault![/]" )
528+ print (
529+ "[bold dim red]This is an internal error, not your fault![/]"
530+ )
545531 print (
546532 "[bold dim red]Please report this at https://github.com/ZeroIntensity/view.py/issues[/]"
547533 )
@@ -564,7 +550,9 @@ def _finalize(self) -> None:
564550 if self .loaded :
565551 return
566552
567- warnings .warn ("load() was never called (did you forget to start the app?)" )
553+ warnings .warn (
554+ "load() was never called (did you forget to start the app?)"
555+ )
568556 split = self .config .app .app_path .split (":" , maxsplit = 1 )
569557
570558 if len (split ) != 2 :
@@ -696,7 +684,9 @@ async def index():
696684 app.run()
697685 ```
698686 """
699- return self ._method_wrapper (path , doc , cache_rate , get , steps , parallel_build )
687+ return self ._method_wrapper (
688+ path , doc , cache_rate , get , steps , parallel_build
689+ )
700690
701691 def post (
702692 self ,
@@ -841,7 +831,9 @@ async def index():
841831 app.run()
842832 ```
843833 """
844- return self ._method_wrapper (path , doc , cache_rate , put , steps , parallel_build )
834+ return self ._method_wrapper (
835+ path , doc , cache_rate , put , steps , parallel_build
836+ )
845837
846838 def options (
847839 self ,
@@ -930,7 +922,9 @@ def query(
930922 """
931923
932924 def inner (func : RouteOrCallable [P ]) -> Route [P ]:
933- route : Route [P ] = query_impl (name , * tps , doc = doc , default = default )(func )
925+ route : Route [P ] = query_impl (name , * tps , doc = doc , default = default )(
926+ func
927+ )
934928 self ._push_route (route )
935929 return route
936930
@@ -953,7 +947,9 @@ def body(
953947 """
954948
955949 def inner (func : RouteOrCallable [P ]) -> Route [P ]:
956- route : Route [P ] = body_impl (name , * tps , doc = doc , default = default )(func )
950+ route : Route [P ] = body_impl (name , * tps , doc = doc , default = default )(
951+ func
952+ )
957953 self ._push_route (route )
958954 return route
959955
@@ -977,7 +973,9 @@ async def template(
977973 else :
978974 f = frame # type: ignore
979975
980- return await template (name , directory , engine , f , app = self , ** parameters )
976+ return await template (
977+ name , directory , engine , f , app = self , ** parameters
978+ )
981979
982980 async def markdown (
983981 self ,
0 commit comments