<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def quote_attrval (s):
 """ Quote a HTML attribute to be able to wrap it in double quotes. @param s: the attribute string to quote @type s: string @return: the quoted HTML attribute @rtype: string """

    res = []
    for c in s:
        if ord(c) <= 127:
            # ASCII
            if c == u'&':
                res.append(u"&amp;")
            elif c == u'"':
                res.append(u"&quot;")
            else:
                res.append(c)
        else:
            res.append(u"&#%d;" % ord(c))
    return u"".join(res)