@@ -21,11 +21,9 @@ def __init__(self, ctx: aiopenapi3.plugin.Message.Context) -> None:
2121 self .ctx = ctx
2222
2323 def add_unredirected_header (self , key : str , value : str ) -> None :
24- if key .lower () == "cookie" :
25- name , _ , value = value .partition ("=" )
26- self .ctx .cookies [name ] = value
27- else :
28- self .ctx .headers [key ] = value
24+ assert key .lower () == "cookie"
25+ name , _ , value = value .partition ("=" )
26+ self .ctx .cookies [name ] = value
2927
3028 class _Response :
3129 """
@@ -45,22 +43,23 @@ def info(self) -> email.message.Message:
4543 def __init__ (
4644 self , cookiejar : http .cookiejar .CookieJar = None , policy : Literal ["jar" , "securitySchemes" ] = "jar"
4745 ) -> None :
48- self .cookiejar = cookiejar or http .cookiejar .CookieJar ()
49- self .policy = policy
50- self .schemes : dict [str , str ] = None
46+ self .cookiejar : http .cookiejar .CookieJar = cookiejar or http .cookiejar .CookieJar ()
47+ self .policy : Literal ["jar" , "securitySchemes" ] = policy
48+ self .schemes : dict [str , str ] = dict ()
49+
50+ if policy not in ["jar" , "securitySchemes" ]:
51+ raise ValueError (f"policy { self .policy } is not a valid policy" )
52+
5153 super ().__init__ ()
5254
5355 def initialized (self , ctx : "aiopenapi3.plugin.Init.Context" ) -> "aiopenapi3.plugin.Init.Context" :
54- if self .policy in ["securitySchemes" , "jar" ]:
55- self .schemes = {
56- v .root .name : k
57- for k , v in filter (
58- lambda x : (x [1 ].root .type .lower (), x [1 ].root .in_ ) == ("apikey" , "cookie" ),
59- self .api .components .securitySchemes .items (),
60- )
61- }
62- else :
63- raise ValueError (f"policy { self .policy } is not a valid policy" )
56+ self .schemes = {
57+ v .root .name : k
58+ for k , v in filter (
59+ lambda x : (x [1 ].root .type .lower (), x [1 ].root .in_ ) == ("apikey" , "cookie" ),
60+ self .api .components .securitySchemes .items (),
61+ )
62+ }
6463 return ctx
6564
6665 def received (self , ctx : "aiopenapi3.plugin.Message.Context" ) -> "aiopenapi3.plugin.Message.Context" :
0 commit comments