http
ContentType
dataclass
dataclass
for describing value of Content-Type
header.
Its object is often used when handling the value of Content-Type
in
Bamboo.
parse(raw)
classmethod
Parse and make new instance of this class.
Parameters
raw : str
Value of Content-Type
header
Returns
ContentType
New instance of this class based on the raw
data
Source code in bamboo/http.py
@classmethod
def parse(cls, raw: str) -> ContentType:
"""Parse and make new instance of this class.
Parameters
----------
raw : str
Value of `Content-Type` header
Returns
-------
ContentType
New instance of this class based on the `raw` data
"""
raw = re.split(";\s*", raw)
result = cls(raw[0])
for directive, val in [item.split("=") for item in raw[1:]]:
if directive == "charset":
result.charset = val.lower()
elif directive == "boundary":
result.boundary = val
return result
to_header(self)
Format contents as a Content-Type header.
Returns:
Type | Description |
---|---|
t.Tuple[str, str] |
Header name and value of the header. |
Source code in bamboo/http.py
def to_header(self) -> t.Tuple[str, str]:
"""Format contents as a Content-Type header.
Returns:
Header name and value of the header.
"""
params = {}
if self.charset:
params["charset"] = self.charset
if self.boundary:
params["boundary"] = self.boundary
return make_header("Content-Type", self.media_type, **params)
ContentTypeHolder
Abstract class with properties about Content-Type
.
HTTPStatus
Enum which describes HTTP status.
Each class variables of the class have four main attributes:
- value
- wsgi
- asgi
- description
value
means the enum value and describes HTTP status as int.
wsgi
is str and used only for WSGI servers.
Similarly, asgi
is int and only for ASGI servers.
'description' describes short message of corresponding HTTP satus.