Networking¶
mom.net¶
module: | mom.net |
---|
synopsis: | Makes working with Data URI-schemes easier. |
---|---|
module: | mom.net.data |
see: | http://en.wikipedia.org/wiki/Data_URI_scheme |
see: | https://tools.ietf.org/html/rfc2397 |
-
mom.net.data_uri.
data_uri_encode
(raw_bytes, mime_type='text/plain', charset='US-ASCII', encoder='base64')¶ Encodes raw bytes into a data URI scheme string.
Parameters: - raw_bytes – Raw bytes
- mime_type – The mime type, e.g. b”text/css” or b”image/png”. Default b”text/plain”.
- charset – b”utf-8” if you want the data URI to contain a b”charset=utf-8” component. Default b”US-ASCII”. This does not mean however, that your raw_bytes will be encoded by this function. You must ensure that if you specify, b”utf-8” (or anything else) as the encoding, you have encoded your raw data appropriately.
- encoder – “base64” or None.
Returns: Data URI.
-
mom.net.data_uri.
data_uri_parse
(data_uri)¶ Parses a data URI into raw bytes and metadata.
Parameters: data_uri – The data url string. If a mime-type definition is missing in the metadata, “text/plain;charset=US-ASCII” will be used as default mime-type. Returns: - A 2-tuple::
- (bytes, mime_type)
See
mom.http.mimeparse.mimeparse.parse_mime_type()
for whatmime_type
looks like.