_libmuprivpython2.py 579 Bytes
Newer Older
1 2 3 4 5 6 7
from __future__ import division, absolute_import, print_function, unicode_literals

from _libmuprivcommon import _assert_instance

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

8
def _encode(v, encoding):
9 10
    _assert_instance(v, str, unicode)
    if isinstance(v, unicode):
11
        return v.encode(encoding)
12 13 14
    else:
        return v

15
def _decode(v, encoding):
16 17
    _assert_instance(v, str, unicode)
    if isinstance(v, str):
18
        return v.decode(encoding)
19 20 21 22 23
    else:
        return v

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