def encode_unicode_bytes(my_string):
    if not isinstance(my_string, basestring):
        my_string = repr(my_string)

    # TODO refactor this to use six types
    if PYTHON_MAJOR_VERSION == 2:
        if isinstance(my_string, str):
            return my_string
        elif isinstance(my_string, unicode):
            return my_string.encode('utf-8')
    else:
        if isinstance(my_string, str):
            return my_string.encode('utf-8')
        elif isinstance(my_string, bytes):
            return my_string

# TODO create a full class that extends string.Template
Shim function, converts Unicode to UTF-8 encoded bytes regardless of the source format
dataset/ETHPy150Open svanoort/pyresttest/pyresttest/parsing.py/encode_unicode_bytes