diff options
author | Leonard Richardson <leonard.richardson@canonical.com> | 2009-04-10 11:22:53 -0400 |
---|---|---|
committer | Leonard Richardson <leonard.richardson@canonical.com> | 2009-04-10 11:22:53 -0400 |
commit | e2cdc424ee48a38a6217f3eb0ca6adf513694a84 (patch) | |
tree | 58b8fd1855e139909dba2e0d16d7d369281ba4d2 /src/beautifulsoup/util.py | |
parent | bb77aa085be6c116d0e74b6beaab42b69f691ea4 (diff) |
First attempt at an import.
Diffstat (limited to 'src/beautifulsoup/util.py')
-rw-r--r-- | src/beautifulsoup/util.py | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/beautifulsoup/util.py b/src/beautifulsoup/util.py new file mode 100644 index 0000000..693a7e2 --- /dev/null +++ b/src/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) |