'A selector is a chain of one or more simple selectors,
separated by combinators (e.g., ">").'

def __init__(self, s):

    self.string = s
    for s in s.split(','):
        s = s.lower()
        s = s.strip()
        s = re.sub('    +', '    ', s)
        s = re.sub('    *\\>    *', '    >', s)
        s = re.sub('    *\\<    *', '    <', s)
        s = re.sub('    *\\+    *', '    +', s)
        s = re.sub('\\[.*?\\]', (lambda m: _encode_space(m.group(0))), s)
        s = re.sub(':contains\\(.*?\\)', (lambda m: _encode_space(m.group(0))), s)
        self.append([])
        for s in s.split('    '):
            if (not s.startswith(('>', '<', '+'))):
                self[(-1)].append(('    ', Selector(s)))
            elif s.startswith('>'):
                self[(-1)].append(('>', Selector(s[1:])))
            elif s.startswith('<'):
                self[(-1)].append(('<', Selector(s[1:])))
            elif s.startswith('+'):
                self[(-1)].append(('+', Selector(s[1:])))
