Example #1
0
def iterable(body):
    """Convert the given body to an iterable object."""
    if isinstance(body, types.FileType):
        body = cptools.fileGenerator(body)
    elif isinstance(body, types.GeneratorType):
        body = flattener(body)
    elif isinstance(body, basestring):
        # strings get wrapped in a list because iterating over a single
        # item list is much faster than iterating over every character
        # in a long string.
        body = [body]
    elif body is None:
        body = [""]
    return body
Example #2
0
 def __set__(self, obj, value):
     # Convert the given value to an iterable object.
     if isinstance(value, types.FileType):
         value = cptools.fileGenerator(value)
     elif isinstance(value, types.GeneratorType):
         value = flattener(value)
     elif isinstance(value, basestring):
         # strings get wrapped in a list because iterating over a single
         # item list is much faster than iterating over every character
         # in a long string.
         value = [value]
     elif value is None:
         value = []
     obj._body = value