MCPcopy Create free account
hub / github.com/clips/pattern / _matches

Method _matches

pattern/web/soup/BeautifulSoup.py:977–1007  ·  view source on GitHub ↗
(self, markup, matchAgainst)

Source from the content-addressed store, hash-verified

975 return found
976
977 def _matches(self, markup, matchAgainst):
978 #print "Matching %s against %s" % (markup, matchAgainst)
979 result = False
980 if matchAgainst is True:
981 result = markup is not None
982 elif callable(matchAgainst):
983 result = matchAgainst(markup)
984 else:
985 #Custom match methods take the tag as an argument, but all
986 #other ways of matching match the tag name as a string.
987 if isinstance(markup, Tag):
988 markup = markup.name
989 if markup and not isinstance(markup, basestring):
990 markup = unicode(markup)
991 #Now we know that chunk is either a string, or None.
992 if hasattr(matchAgainst, 'match'):
993 # It's a regexp object.
994 result = markup and matchAgainst.search(markup)
995 elif hasattr(matchAgainst, '__iter__'): # list-like
996 result = markup in matchAgainst
997 elif hasattr(matchAgainst, 'items'):
998 result = markup.has_key(matchAgainst)
999 elif matchAgainst and isinstance(markup, basestring):
1000 if isinstance(markup, unicode):
1001 matchAgainst = unicode(matchAgainst)
1002 else:
1003 matchAgainst = str(matchAgainst)
1004
1005 if not result:
1006 result = matchAgainst == markup
1007 return result
1008
1009class ResultSet(list):
1010 """A ResultSet is just a list that keeps track of the SoupStrainer

Callers 2

searchTagMethod · 0.95
searchMethod · 0.95

Calls 3

strFunction · 0.85
searchMethod · 0.45
has_keyMethod · 0.45

Tested by

no test coverage detected