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 input b 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 a bytes or bytearray object in Python3.3 or any bytes-like object after Python3.4. This function will raise TypeError if b 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 input s which returned by urlsafe_encode() is encode from bytes or bytearray object, it will return bytes object. If s is encode from str object, it will return str 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 or bytearray.

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