rbtools.utils.mimetypes¶
Utilities for working with MIME types.
Added in version 5.0.
Functions
|
Guess the MIME type of the given file content. |
|
Return a score for how well the pattern matches the mimetype. |
|
Parse a MIME type into its component parts. |
Classes
A MIME type, parsed into its component parts. |
- class rbtools.utils.mimetypes.MIMEType[source]¶
Bases:
TypedDictA MIME type, parsed into its component parts.
Added in version 5.0.
- __firstlineno__ = 23¶
- __static_attributes__ = ()¶
- format: str¶
The sub-type format, if available.
For example, “json” in “application/vnd.reviewboard.org.test+json”.
- Type:
- rbtools.utils.mimetypes.guess_mimetype(*, data: bytes, filename: str | None = None) str[source]¶
Guess the MIME type of the given file content.
Added in version 5.0.
- rbtools.utils.mimetypes.match_mimetype(pattern: MIMEType, test: MIMEType) float[source]¶
Return a score for how well the pattern matches the mimetype.
This is an ordered list of precedence (
_indicates non-match):Format
Precedence
Type/Vendor+Subtype2.0
Type/Subtype1.9
Type/*1.8
*/Vendor+Subtype1.7
*/_ +Subtype1.6
*/*1.5
_0
Added in version 5.0.
- Parameters:
pattern (
MIMEType) – A parsed mimetype pattern to score. This is a 3-tuple of the type, subtype, and parameters as returned bymimeparse.parse_mime_type(). This may include*wildcards.test (
MIMEType) – A parsed mimetype to match against the pattern. This is a 3-tuple of the type, subtype, and parameters as returned bymimeparse.parse_mime_type().
- Returns:
The resulting score for the match.
- Return type:
- rbtools.utils.mimetypes.parse_mimetype(mime_type: str) MIMEType[source]¶
Parse a MIME type into its component parts.
Added in version 5.0.
- Parameters:
mime_type (
str) – The MIME type to parse.- Returns:
The type, parsed into its component parts.
- Return type:
ParsedMIMEType- Raises:
ValueError – The given MIME type could not be parsed.