summaryrefslogtreecommitdiff
path: root/beautifulsoup/util.py
diff options
context:
space:
mode:
authorLeonard Richardson <leonard.richardson@canonical.com>2011-01-28 13:34:40 -0500
committerLeonard Richardson <leonard.richardson@canonical.com>2011-01-28 13:34:40 -0500
commit58a9d28ced3c133dc945266024e629335af16196 (patch)
tree33a12e789fc659022d9fca2eb84c6135b81d1c23 /beautifulsoup/util.py
parent692fe5201d5dec15a3598578a6f403e67802de0d (diff)
parent5d4b8cc6d288a705cf87c2f2c26036b94d825aa9 (diff)
Removed buildout and made tests work using 'unit2 discover'.
Diffstat (limited to 'beautifulsoup/util.py')
-rw-r--r--beautifulsoup/util.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/beautifulsoup/util.py b/beautifulsoup/util.py
new file mode 100644
index 0000000..693a7e2
--- /dev/null
+++ b/beautifulsoup/util.py
@@ -0,0 +1,29 @@
+# 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 isString(l))
+ or (type(l) in (types.ListType, types.TupleType)))
+
+def isString(s):
+ """Convenience method that works with all 2.x versions of Python
+ to determine whether or not something is stringlike."""
+ try:
+ return isinstance(s, unicode) or isinstance(s, basestring)
+ except NameError:
+ return isinstance(s, str)
+
+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)