diff options
author | Leonard Richardson <leonard.richardson@canonical.com> | 2011-01-28 12:27:24 -0500 |
---|---|---|
committer | Leonard Richardson <leonard.richardson@canonical.com> | 2011-01-28 12:27:24 -0500 |
commit | 44817035926a23177713eb67971fb5c8b6d2aa8b (patch) | |
tree | eb9ed5d5bbb7ab32c29f9d6b1e3055c528c347d3 /beautifulsoup/util.py | |
parent | 7bbefa1fcc9a6006953eb0a79049ece9f05985de (diff) |
Moved the code back into a beautifulsoup/ directory.
Diffstat (limited to 'beautifulsoup/util.py')
-rw-r--r-- | beautifulsoup/util.py | 29 |
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) |