codec
— A module that help handle codec.¶
-
NIWLittleUtils.codec.
b64decode
(b)[source]¶ Decode a Base64 encoded byte string.
Decode a Base64 encoded byte string using a URL-safe alphabet, which substitutes
-
instead of+
and_
instead of/
in the standard Base64 alphabet. The inputb
may also be a ASCII-only Unicode strings.Return type: bytes
-
NIWLittleUtils.codec.
b64encode
(b)[source]¶ Base64 encodes a byte string.
Base64 encodes a byte string. The resulting bytestring is safe for putting into URLs. The input
b
should be abytes
orbytearray
object in Python3.3 or any bytes-like object after Python3.4. This function will raiseTypeError
ifb
is not bytes-like object (For example,str
).Return type: bytes
-
NIWLittleUtils.codec.
urlsafe_decode
(s)[source]¶ Decode a string that encode by
urlsafe_encode()
.Decode a string that encoded by
urlsafe_encode()
. If the inputs
which returned byurlsafe_encode()
is encode frombytes
orbytearray
object, it will returnbytes
object. Ifs
is encode fromstr
object, it will returnstr
object.Return type: str or bytes
-
NIWLittleUtils.codec.
urlsafe_encode
(s)[source]¶ Encode a string or byte string to url-safe string.
Encode a string or byte string to url-safe string. The input can be a object of
str
,bytes
orbytearray
.This function will make sure that return string contains characters that RFC 3986 section 2.3 specified only, but it won’t check the length. User should remember that browsers have limit for length of URLs. (For example, IE8’s maximum URL length is 2083 chars)
Return type: str