_libmuprivpython3.py 481 Bytes
Newer Older
1 2 3 4 5
from _libmuprivcommon import _assert_instance

def _is_str_like(v):
    return isinstance(v, str) or isinstance(v, bytes)

6
def _encode(v, encoding):
7 8
    _assert_instance(v, bytes, str)
    if isinstance(v, str):
9
        return v.encode(encoding)
10 11 12
    else:
        return v

13
def _decode(v, encoding):
14 15
    _assert_instance(v, bytes, str)
    if isinstance(v, bytes):
16
        return v.decode(encoding)
17 18 19 20 21
    else:
        return v

def _assert_int_like(v):
    _assert_instance(v, int)