willpyre.structure¶
- class willpyre.structure.Cookie(value: str, max_age: int = 0, same_site: str = 'Lax', secure: bool = True, http_only: bool = True)[source]¶
Bases:
object
This class is used to send cookies to the user.
- Parameters:
value (str) – Cookie value
max_age (int) – Max age of the cookie (default = 0)
same_site (str) – Same-site attribute value (default = “Lax”)
secure (bool) – Secure attribute of the cookie. (default=True)
http_only (bool) – If True, cookie cannot be accesed from JavaScript. (default = True)
It is not a callable class.
Note
Try to keep the http_only to True as it prevents XSS attacks. Attackers cannot steal cookies from users through Cross-Site scripting if it is set. However, it requires an HTTPS connection, so you can disable it during development.
- cookie_str¶
- http_only¶
- max_age¶
- same_site¶
- secure¶
- value¶
- class willpyre.structure.HTMLResponse(data='', status=200, content_type='text/html', headers={}, cookies={})[source]¶
Bases:
Response
- exception willpyre.structure.HTTPException(status: int = 404, body: str = 'Not found', content_type='text/html')[source]¶
Bases:
Exception
,Response
- class willpyre.structure.JSONResponse(data={}, status=200, content_type='application/json', headers={'content-type': 'application/json'}, cookies={})[source]¶
Bases:
Response
- class willpyre.structure.Redirect(location: str, status: int = 303)[source]¶
Bases:
Response
Sends a redirect response to the user. Args: - location(str): Path to send the user after redirect. - status(int): The HTTP status during redirect. Defaults to 303. (More about redirects)[https://developer.mozilla.org/en-US/docs/Web/HTTP/Redirections]
- class willpyre.structure.Request(method: str, path: str, raw_body: bytes, raw_query: bytes, headers, *args)[source]¶
Bases:
object
This class contains the information requested by the user. The functions called by
maglev.Router.handle
take this as the first argument.- Parameters:
headers (list[list[bytes,bytes]]) – Array of headers passed by the server, and converts them to a dict.
method (str) – It is the HTTP request method.
path (str) – It is the HTTP request path.
query (dict[str,list[str]]) – It is obtained from the server as a string and is then parsed into the dictionary with urllib.parse.parse_qs
- class willpyre.structure.Response(status=200, content_type='text/html', body='', headers={'content-type': 'text/html'}, cookies={})[source]¶
Bases:
object
This class contains the Response data to be sent, in a manageable format. The response argument of the functions defined, objects of this class.
The response object does not require external parameters, but has some attributes which can be set: :param headers: It is the HTTP headers set as a dict. Only [content-type] = text/html is set by default. :type headers: dict[str,str] :param cookies: :type cookies: dict[str,maglev.Structure.Cookie] :param body: :type body: str :param status: :type status: int
- class willpyre.structure.TextResponse(data='', status=200, content_type='text/plain', headers={}, cookies={})[source]¶
Bases:
Response
- class willpyre.structure.TypedMultiMap(mapping: Any | None = None)[source]¶
Bases:
dict
- willpyre.structure.parse_multipart(content_type: str, data: bytes, decode: bool = False) Tuple[TypedMultiMap, TypedMultiMap] [source]¶