human
Complete this python program:
def csviter(obj, delimiter=None, headers=None, encoding=None):
assistant
#Here is the Python code you requested.

    """Returns an iterator of dictionaries from the given csv object
    obj can be:
    - a Response object
    - a unicode string
    - a string encoded as utf-8
    delimiter is the character used to separate field on the given obj.
    headers is an iterable that when provided offers the keys
    for the returned dictionaries, if not the first row is used.
    """
    encoding = (obj.encoding if isinstance(obj, TextResponse) else (encoding or 'utf-8'))
    def _getrow(csv_r):
        return [str_to_unicode(field, encoding) for field in csv_r.next()]
    lines = StringIO(body_or_str(obj, unicode=False))
    if delimiter:
        csv_r = csv.reader(lines, delimiter=delimiter)
    else:
        csv_r = csv.reader(lines)
    if (not headers):
        headers = _getrow(csv_r)
    while True:
        row = _getrow(csv_r)
        if (len(row) != len(headers)):
            log.msg(('ignoring    row    %d    (length:    %d,    should    be:    %d)' % (csv_r.line_num, len(row), len(headers))), log.WARNING)
            continue
        else:
            (yield dict(zip(headers, row)))