summaryrefslogtreecommitdiff
path: root/bs4/element.py
diff options
context:
space:
mode:
authorLeonard Richardson <leonard.richardson@canonical.com>2012-03-01 09:06:25 -0500
committerLeonard Richardson <leonard.richardson@canonical.com>2012-03-01 09:06:25 -0500
commit4a5136d31bf07a7b28b58343f0c32e41d895e110 (patch)
tree271f5140137f4143774081ea92d872fc7f95bd92 /bs4/element.py
parent8bbc84dfc6324a32066b87cf3a78ce0eb719e289 (diff)
Test that CSS selectors work within the tree as well as at the top level.
Diffstat (limited to 'bs4/element.py')
-rw-r--r--bs4/element.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/bs4/element.py b/bs4/element.py
index 3baafe3..584e171 100644
--- a/bs4/element.py
+++ b/bs4/element.py
@@ -446,9 +446,11 @@ class PageElement(object):
combination.
"""
if operator == '=':
- # string representation of attribute is equal to value
+ # 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):
@@ -456,17 +458,19 @@ class PageElement(object):
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)
+ # 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)
+ # 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
+ # 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-
+ # 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(