'Create a function that performs a CSS selector operation.
Takes an operator, attribute and optional value. Returns a
function that will return True for elements that match that
combination.'

def _attribute_checker(self, operator, attribute, value=''):

    if (operator == '='):
        return (lambda el: (el._attr_value_as_string(attribute) == value))
    elif (operator == '~'):
        def _includes_value(element):
            attribute_value = element.get(attribute, [])
            if (not isinstance(attribute_value, list)):
                attribute_value = attribute_value.split()
            return (value in attribute_value)
        return _includes_value
    elif (operator == '^'):
        return (lambda el: el._attr_value_as_string(attribute, '').startswith(value))
    elif (operator == '$'):
        return (lambda el: el._attr_value_as_string(attribute, '').endswith(value))
    elif (operator == '*'):
        return (lambda el: (value in el._attr_value_as_string(attribute, '')))
    elif (operator == '|'):
        def _is_or_starts_with_dash(element):
            attribute_value = element._attr_value_as_string(attribute, '')
            return ((attribute_value == value) or attribute_value.startswith((value + '-')))
        return _is_or_starts_with_dash
    else:
        return (lambda el: el.has_attr(attribute))
