'Returns an (attribute, value)-tuple for the given attribute selector.'

def _parse_attribute(self, s):

    s = s.strip('[]')
    s = s.replace("'", '')
    s = s.replace('"', '')
    s = _decode_space(s)
    s = re.sub('(\\~|\\||\\^|\\$|\\*)\\=', '=\\1', s)
    s = (s.split('=') + [True])
    s = s[:2]
    if (s[1] is not True):
        r = '^%s$'
        if s[1].startswith(('~', '|', '^', '$', '*')):
            (p, s[1]) = (s[1][0], s[1][1:])
            if (p == '~'):
                r = '(^|\\s)%s(\\s|$)'
            if (p == '|'):
                r = '^%s(-|$)'
            if (p == '^'):
                r = '^%s'
            if (p == '$'):
                r = '%s$'
            if (p == '*'):
                r = '%s'
        s[1] = re.compile((r % s[1]), re.I)
    return s[:2]
