blob: 59788656af9c3c626e1e27f64e14b2eb85b9836e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# 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)
|