From f7e49815dfcd427af639b1e3f9aefcf4f8f581e4 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Sat, 21 May 2011 11:14:01 -0400 Subject: Got rid of isList utility function. --- bs4/__init__.py | 2 +- bs4/element.py | 6 ++---- bs4/util.py | 15 +++++++++++++++ 3 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 bs4/util.py diff --git a/bs4/__init__.py b/bs4/__init__.py index e0eba75..e84e699 100644 --- a/bs4/__init__.py +++ b/bs4/__init__.py @@ -27,7 +27,7 @@ __all__ = ['BeautifulSoup'] import re -from util import isList, buildSet +from util import buildSet from builder import builder_registry from dammit import UnicodeDammit from element import DEFAULT_OUTPUT_ENCODING, NavigableString, Tag diff --git a/bs4/element.py b/bs4/element.py index 6fb6210..587078c 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -6,8 +6,6 @@ except ImportError: name2codepoint = {} from bs4.dammit import EntitySubstitution -from util import isList - DEFAULT_OUTPUT_ENCODING = "utf-8" @@ -771,7 +769,7 @@ class SoupStrainer(object): found = None # If given a list of items, scan it for a text element that # matches. - if isList(markup) and not isinstance(markup, Tag): + if hasattr(markup, '__iter__') and not isinstance(markup, Tag): for element in markup: if isinstance(element, NavigableString) \ and self.search(element): @@ -810,7 +808,7 @@ class SoupStrainer(object): if hasattr(matchAgainst, 'match'): # It's a regexp object. result = markup and matchAgainst.search(markup) - elif (isList(matchAgainst) + elif (hasattr(matchAgainst, '__iter__') and (markup is not None or not isinstance(matchAgainst, basestring))): result = markup in matchAgainst diff --git a/bs4/util.py b/bs4/util.py new file mode 100644 index 0000000..3cfeaf5 --- /dev/null +++ b/bs4/util.py @@ -0,0 +1,15 @@ +# Helper functions and mixin classes for Beautiful Soup + +import types +try: + set +except NameError: + from sets import Set as set + +def buildSet(args=None): + """Turns a list or a string into a set.""" + if isinstance(args, str): + return set([args]) + if args is None: + return set() + return set(args) -- cgit v1.2.3 From 640fdc0fa7f2ffd53fb92dbeac8b456bb09dcaa7 Mon Sep 17 00:00:00 2001 From: Leonard Richardson Date: Sat, 21 May 2011 11:15:12 -0400 Subject: got rid of util.py altogether. --- bs4/__init__.py | 3 +-- bs4/util.py | 15 --------------- 2 files changed, 1 insertion(+), 17 deletions(-) delete mode 100644 bs4/util.py diff --git a/bs4/__init__.py b/bs4/__init__.py index e84e699..8baeec4 100644 --- a/bs4/__init__.py +++ b/bs4/__init__.py @@ -27,7 +27,6 @@ __all__ = ['BeautifulSoup'] import re -from util import buildSet from builder import builder_registry from dammit import UnicodeDammit from element import DEFAULT_OUTPUT_ENCODING, NavigableString, Tag @@ -145,7 +144,7 @@ class BeautifulSoup(Tag): if self.currentData: currentData = u''.join(self.currentData) if (currentData.translate(self.STRIP_ASCII_SPACES) == '' and - not buildSet([tag.name for tag in self.tagStack]).intersection( + not set([tag.name for tag in self.tagStack]).intersection( self.builder.preserve_whitespace_tags)): if '\n' in currentData: currentData = '\n' diff --git a/bs4/util.py b/bs4/util.py deleted file mode 100644 index 3cfeaf5..0000000 --- a/bs4/util.py +++ /dev/null @@ -1,15 +0,0 @@ -# Helper functions and mixin classes for Beautiful Soup - -import types -try: - set -except NameError: - from sets import Set as set - -def buildSet(args=None): - """Turns a list or a string into a set.""" - if isinstance(args, str): - return set([args]) - if args is None: - return set() - return set(args) -- cgit v1.2.3