(self, markup)
| 948 | return found |
| 949 | |
| 950 | def search(self, markup): |
| 951 | #print 'looking for %s in %s' % (self, markup) |
| 952 | found = None |
| 953 | # If given a list of items, scan it for a text element that |
| 954 | # matches. |
| 955 | if hasattr(markup, "__iter__") \ |
| 956 | and not isinstance(markup, Tag): |
| 957 | for element in markup: |
| 958 | if isinstance(element, NavigableString) \ |
| 959 | and self.search(element): |
| 960 | found = element |
| 961 | break |
| 962 | # If it's a Tag, make sure its name or attributes match. |
| 963 | # Don't bother with Tags if we're searching for text. |
| 964 | elif isinstance(markup, Tag): |
| 965 | if not self.text: |
| 966 | found = self.searchTag(markup) |
| 967 | # If it's text, make sure the text matches. |
| 968 | elif isinstance(markup, NavigableString) or \ |
| 969 | isinstance(markup, basestring): |
| 970 | if self._matches(markup, self.text): |
| 971 | found = markup |
| 972 | else: |
| 973 | raise Exception, "I don't know how to match against a %s" \ |
| 974 | % markup.__class__ |
| 975 | return found |
| 976 | |
| 977 | def _matches(self, markup, matchAgainst): |
| 978 | #print "Matching %s against %s" % (markup, matchAgainst) |
no test coverage detected