'Create a dict from a cgi.FieldStorage instance'

@classmethod
def from_fieldstorage(cls, fs):

    obj = cls()
    for field in (fs.list or ()):
        charset = field.type_options.get('charset', 'utf8')
        transfer_encoding = field.headers.get('Content-Transfer-Encoding', None)
        supported_tranfer_encoding = {'base64': binascii.a2b_base64, 'quoted-printable': binascii.a2b_qp}
        if PY3:
            if (charset == 'utf8'):
                decode = (lambda b: b)
            else:
                decode = (lambda b: b.encode('utf8').decode(charset))
        else:
            decode = (lambda b: b.decode(charset))
        if field.filename:
            field.filename = decode(field.filename)
            obj.add(field.name, field)
        else:
            value = field.value
            if (transfer_encoding in supported_tranfer_encoding):
                if PY3:
                    value = value.encode('utf8')
                value = supported_tranfer_encoding[transfer_encoding](value)
                if PY3:
                    value = value.decode('utf8')
            obj.add(field.name, decode(value))
    return obj
