'Excape quotes and percent in given string.'

def escape(self, s, percent=True):

    if isinstance(s, text_type):
        s = (s or u'').encode(u'utf-8')
    s = text_type(MySQLdb.escape_string(s), u'utf-8').replace(u'`', u'\\`')
    if percent:
        s = s.replace(u'%', u'%%')
    return s
