summaryrefslogtreecommitdiff
path: root/bs4/util.py
diff options
context:
space:
mode:
authorLeonard Richardson <leonard.richardson@canonical.com>2011-03-06 19:41:48 -0500
committerLeonard Richardson <leonard.richardson@canonical.com>2011-03-06 19:41:48 -0500
commit85959841f88fb750b20bea48b4df904286e4fca6 (patch)
treee796cf9045d94be991f6611188c41607abf342a1 /bs4/util.py
parentb01f9312a13198d249060dac34ab12629285cdb2 (diff)
parent32050a613a3eff5f53c6395ea365159226351946 (diff)
A big patch from Aaron that brings in features from 3.0.8 and makes the code more PEP-8 compliant.
Diffstat (limited to 'bs4/util.py')
-rw-r--r--bs4/util.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/bs4/util.py b/bs4/util.py
new file mode 100644
index 0000000..8e33273
--- /dev/null
+++ b/bs4/util.py
@@ -0,0 +1,23 @@
+# Helper functions and mixin classes for Beautiful Soup
+
+import types
+try:
+ set
+except NameError:
+ from sets import Set as set
+
+
+def isList(l):
+ """Convenience method that works with all 2.x versions of Python
+ to determine whether or not something is listlike."""
+ return ((hasattr(l, '__iter__') and not isinstance(l, basestring))
+ or (type(l) in (types.ListType, types.TupleType)))
+
+
+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)