Escape a string according for use in LIKE operator

    >>> sqlalchemy_escape("text_table", "\\", "%_")
    'text\_table'

def sqlalchemy_escape(val, escape_char, special_chars):
    """Escape a string according for use in LIKE operator

    >>> sqlalchemy_escape("text_table", "\\", "%_")
    'text\_table'
    """
    if sys.version_info[:2] >= (3, 0):
        assert isinstance(val, str)
    else:
        assert isinstance(val, basestring)
    result = []
    for c in val:
        if c in special_chars + escape_char:
            result.extend(escape_char + c)
        else:
            result.extend(c)
    return ''.join(result)