def to_bytestring(value):
    if isinstance(value, six.text_type):
        return value.encode('utf8')
    if isinstance(value, six.binary_type):
        return value
    if six.PY2:
        return str(value)
    return bytes(str(value), 'utf8')
Encode a string as a UTF8 bytestring.  This function could be passed a
dataset/ETHPy150Open codeinthehole/django-cacheback/cacheback/base.py/to_bytestring