(self, operator, attribute, value='')
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.
Create a function that performs a CSS selector operation.
Create a function that performs a CSS selector operation .
def _attribute_checker(self, operator, attribute, value=''):
        """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.
        """
        if operator == '=':
            # string representation of `attribute` is equal to `value`
            return lambda el: el._attr_value_as_string(attribute) == value
        elif operator == '~':
            # space-separated list representation of `attribute`
            # contains `value`
            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 == '^':
            # string representation of `attribute` starts with `value`
            return lambda el: el._attr_value_as_string(
                attribute, '').startswith(value)
        elif operator == '$':
            # string represenation of `attribute` ends with `value`
            return lambda el: el._attr_value_as_string(
                attribute, '').endswith(value)
        elif operator == '*':
            # string representation of `attribute` contains `value`
            return lambda el: value in el._attr_value_as_string(attribute, '')
        elif operator == '|':
            # string representation of `attribute` is either exactly
            # `value` or starts with `value` and then a dash.
            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)
def _attribute_checker ( self , operator , attribute , value = '' ) : if operator == '=' : # string representation of `attribute` is equal to `value` return lambda el : el . _attr_value_as_string ( attribute ) == value elif operator == '~' : # space-separated list representation of `attribute` # contains `value` 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 == '^' : # string representation of `attribute` starts with `value` return lambda el : el . _attr_value_as_string ( attribute , '' ) . startswith ( value ) elif operator == '$' : # string represenation of `attribute` ends with `value` return lambda el : el . _attr_value_as_string ( attribute , '' ) . endswith ( value ) elif operator == '*' : # string representation of `attribute` contains `value` return lambda el : value in el . _attr_value_as_string ( attribute , '' ) elif operator == '|' : # string representation of `attribute` is either exactly # `value` or starts with `value` and then a dash. 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 )