def tobytes(value):
    """implicitly try to convert values to byte strings
    mainly for python 2 and 3 compatibility"""
    if not isinstance(value, bytes):
        value = value.encode('utf8')
    return value