code: def quote_attrval (s):
      
      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)
docs: 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