defrender(self,content:Any)->bytes:assertujsonisnotNone,"ujson must be installed to use UJSONResponse"returnujson.dumps(content,ensure_ascii=False).encode("utf-8")
defset_cookie(self,key:str,value:str="",max_age:typing.Optional[int]=None,expires:typing.Optional[typing.Union[datetime,str,int]]=None,path:str="/",domain:typing.Optional[str]=None,secure:bool=False,httponly:bool=False,samesite:typing.Optional[typing.Literal["lax","strict","none"]]="lax",)->None:cookie:"http.cookies.BaseCookie[str]"=http.cookies.SimpleCookie()cookie[key]=valueifmax_ageisnotNone:cookie[key]["max-age"]=max_ageifexpiresisnotNone:ifisinstance(expires,datetime):cookie[key]["expires"]=format_datetime(expires,usegmt=True)else:cookie[key]["expires"]=expiresifpathisnotNone:cookie[key]["path"]=pathifdomainisnotNone:cookie[key]["domain"]=domainifsecure:cookie[key]["secure"]=Trueifhttponly:cookie[key]["httponly"]=TrueifsamesiteisnotNone:assertsamesite.lower()in["strict","lax","none",],"samesite must be either 'strict', 'lax' or 'none'"cookie[key]["samesite"]=samesitecookie_val=cookie.output(header="").strip()self.raw_headers.append((b"set-cookie",cookie_val.encode("latin-1")))
defrender(self,content:Any)->bytes:assertorjsonisnotNone,"orjson must be installed to use ORJSONResponse"returnorjson.dumps(content,option=orjson.OPT_NON_STR_KEYS|orjson.OPT_SERIALIZE_NUMPY)
defset_cookie(self,key:str,value:str="",max_age:typing.Optional[int]=None,expires:typing.Optional[typing.Union[datetime,str,int]]=None,path:str="/",domain:typing.Optional[str]=None,secure:bool=False,httponly:bool=False,samesite:typing.Optional[typing.Literal["lax","strict","none"]]="lax",)->None:cookie:"http.cookies.BaseCookie[str]"=http.cookies.SimpleCookie()cookie[key]=valueifmax_ageisnotNone:cookie[key]["max-age"]=max_ageifexpiresisnotNone:ifisinstance(expires,datetime):cookie[key]["expires"]=format_datetime(expires,usegmt=True)else:cookie[key]["expires"]=expiresifpathisnotNone:cookie[key]["path"]=pathifdomainisnotNone:cookie[key]["domain"]=domainifsecure:cookie[key]["secure"]=Trueifhttponly:cookie[key]["httponly"]=TrueifsamesiteisnotNone:assertsamesite.lower()in["strict","lax","none",],"samesite must be either 'strict', 'lax' or 'none'"cookie[key]["samesite"]=samesitecookie_val=cookie.output(header="").strip()self.raw_headers.append((b"set-cookie",cookie_val.encode("latin-1")))
defset_cookie(self,key:str,value:str="",max_age:typing.Optional[int]=None,expires:typing.Optional[typing.Union[datetime,str,int]]=None,path:str="/",domain:typing.Optional[str]=None,secure:bool=False,httponly:bool=False,samesite:typing.Optional[typing.Literal["lax","strict","none"]]="lax",)->None:cookie:"http.cookies.BaseCookie[str]"=http.cookies.SimpleCookie()cookie[key]=valueifmax_ageisnotNone:cookie[key]["max-age"]=max_ageifexpiresisnotNone:ifisinstance(expires,datetime):cookie[key]["expires"]=format_datetime(expires,usegmt=True)else:cookie[key]["expires"]=expiresifpathisnotNone:cookie[key]["path"]=pathifdomainisnotNone:cookie[key]["domain"]=domainifsecure:cookie[key]["secure"]=Trueifhttponly:cookie[key]["httponly"]=TrueifsamesiteisnotNone:assertsamesite.lower()in["strict","lax","none",],"samesite must be either 'strict', 'lax' or 'none'"cookie[key]["samesite"]=samesitecookie_val=cookie.output(header="").strip()self.raw_headers.append((b"set-cookie",cookie_val.encode("latin-1")))
defset_cookie(self,key:str,value:str="",max_age:typing.Optional[int]=None,expires:typing.Optional[typing.Union[datetime,str,int]]=None,path:str="/",domain:typing.Optional[str]=None,secure:bool=False,httponly:bool=False,samesite:typing.Optional[typing.Literal["lax","strict","none"]]="lax",)->None:cookie:"http.cookies.BaseCookie[str]"=http.cookies.SimpleCookie()cookie[key]=valueifmax_ageisnotNone:cookie[key]["max-age"]=max_ageifexpiresisnotNone:ifisinstance(expires,datetime):cookie[key]["expires"]=format_datetime(expires,usegmt=True)else:cookie[key]["expires"]=expiresifpathisnotNone:cookie[key]["path"]=pathifdomainisnotNone:cookie[key]["domain"]=domainifsecure:cookie[key]["secure"]=Trueifhttponly:cookie[key]["httponly"]=TrueifsamesiteisnotNone:assertsamesite.lower()in["strict","lax","none",],"samesite must be either 'strict', 'lax' or 'none'"cookie[key]["samesite"]=samesitecookie_val=cookie.output(header="").strip()self.raw_headers.append((b"set-cookie",cookie_val.encode("latin-1")))
defset_cookie(self,key:str,value:str="",max_age:typing.Optional[int]=None,expires:typing.Optional[typing.Union[datetime,str,int]]=None,path:str="/",domain:typing.Optional[str]=None,secure:bool=False,httponly:bool=False,samesite:typing.Optional[typing.Literal["lax","strict","none"]]="lax",)->None:cookie:"http.cookies.BaseCookie[str]"=http.cookies.SimpleCookie()cookie[key]=valueifmax_ageisnotNone:cookie[key]["max-age"]=max_ageifexpiresisnotNone:ifisinstance(expires,datetime):cookie[key]["expires"]=format_datetime(expires,usegmt=True)else:cookie[key]["expires"]=expiresifpathisnotNone:cookie[key]["path"]=pathifdomainisnotNone:cookie[key]["domain"]=domainifsecure:cookie[key]["secure"]=Trueifhttponly:cookie[key]["httponly"]=TrueifsamesiteisnotNone:assertsamesite.lower()in["strict","lax","none",],"samesite must be either 'strict', 'lax' or 'none'"cookie[key]["samesite"]=samesitecookie_val=cookie.output(header="").strip()self.raw_headers.append((b"set-cookie",cookie_val.encode("latin-1")))
defset_cookie(self,key:str,value:str="",max_age:typing.Optional[int]=None,expires:typing.Optional[typing.Union[datetime,str,int]]=None,path:str="/",domain:typing.Optional[str]=None,secure:bool=False,httponly:bool=False,samesite:typing.Optional[typing.Literal["lax","strict","none"]]="lax",)->None:cookie:"http.cookies.BaseCookie[str]"=http.cookies.SimpleCookie()cookie[key]=valueifmax_ageisnotNone:cookie[key]["max-age"]=max_ageifexpiresisnotNone:ifisinstance(expires,datetime):cookie[key]["expires"]=format_datetime(expires,usegmt=True)else:cookie[key]["expires"]=expiresifpathisnotNone:cookie[key]["path"]=pathifdomainisnotNone:cookie[key]["domain"]=domainifsecure:cookie[key]["secure"]=Trueifhttponly:cookie[key]["httponly"]=TrueifsamesiteisnotNone:assertsamesite.lower()in["strict","lax","none",],"samesite must be either 'strict', 'lax' or 'none'"cookie[key]["samesite"]=samesitecookie_val=cookie.output(header="").strip()self.raw_headers.append((b"set-cookie",cookie_val.encode("latin-1")))
defset_cookie(self,key:str,value:str="",max_age:typing.Optional[int]=None,expires:typing.Optional[typing.Union[datetime,str,int]]=None,path:str="/",domain:typing.Optional[str]=None,secure:bool=False,httponly:bool=False,samesite:typing.Optional[typing.Literal["lax","strict","none"]]="lax",)->None:cookie:"http.cookies.BaseCookie[str]"=http.cookies.SimpleCookie()cookie[key]=valueifmax_ageisnotNone:cookie[key]["max-age"]=max_ageifexpiresisnotNone:ifisinstance(expires,datetime):cookie[key]["expires"]=format_datetime(expires,usegmt=True)else:cookie[key]["expires"]=expiresifpathisnotNone:cookie[key]["path"]=pathifdomainisnotNone:cookie[key]["domain"]=domainifsecure:cookie[key]["secure"]=Trueifhttponly:cookie[key]["httponly"]=TrueifsamesiteisnotNone:assertsamesite.lower()in["strict","lax","none",],"samesite must be either 'strict', 'lax' or 'none'"cookie[key]["samesite"]=samesitecookie_val=cookie.output(header="").strip()self.raw_headers.append((b"set-cookie",cookie_val.encode("latin-1")))
defset_cookie(self,key:str,value:str="",max_age:typing.Optional[int]=None,expires:typing.Optional[typing.Union[datetime,str,int]]=None,path:str="/",domain:typing.Optional[str]=None,secure:bool=False,httponly:bool=False,samesite:typing.Optional[typing.Literal["lax","strict","none"]]="lax",)->None:cookie:"http.cookies.BaseCookie[str]"=http.cookies.SimpleCookie()cookie[key]=valueifmax_ageisnotNone:cookie[key]["max-age"]=max_ageifexpiresisnotNone:ifisinstance(expires,datetime):cookie[key]["expires"]=format_datetime(expires,usegmt=True)else:cookie[key]["expires"]=expiresifpathisnotNone:cookie[key]["path"]=pathifdomainisnotNone:cookie[key]["domain"]=domainifsecure:cookie[key]["secure"]=Trueifhttponly:cookie[key]["httponly"]=TrueifsamesiteisnotNone:assertsamesite.lower()in["strict","lax","none",],"samesite must be either 'strict', 'lax' or 'none'"cookie[key]["samesite"]=samesitecookie_val=cookie.output(header="").strip()self.raw_headers.append((b"set-cookie",cookie_val.encode("latin-1")))
defset_cookie(self,key:str,value:str="",max_age:typing.Optional[int]=None,expires:typing.Optional[typing.Union[datetime,str,int]]=None,path:str="/",domain:typing.Optional[str]=None,secure:bool=False,httponly:bool=False,samesite:typing.Optional[typing.Literal["lax","strict","none"]]="lax",)->None:cookie:"http.cookies.BaseCookie[str]"=http.cookies.SimpleCookie()cookie[key]=valueifmax_ageisnotNone:cookie[key]["max-age"]=max_ageifexpiresisnotNone:ifisinstance(expires,datetime):cookie[key]["expires"]=format_datetime(expires,usegmt=True)else:cookie[key]["expires"]=expiresifpathisnotNone:cookie[key]["path"]=pathifdomainisnotNone:cookie[key]["domain"]=domainifsecure:cookie[key]["secure"]=Trueifhttponly:cookie[key]["httponly"]=TrueifsamesiteisnotNone:assertsamesite.lower()in["strict","lax","none",],"samesite must be either 'strict', 'lax' or 'none'"cookie[key]["samesite"]=samesitecookie_val=cookie.output(header="").strip()self.raw_headers.append((b"set-cookie",cookie_val.encode("latin-1")))