Parse form data from an request and return a (forms, files) tuple.

    Both tuple values are dictionaries with the form-field name as a key
    (unicode) and lists as values (multiple values per key are possible).
    The forms-dictionary contains form-field values as unicode strings.
    The files-dictionary contains :class:`MultipartPart` instances, either
    because the form-field was a file-upload or the value is to big to fit
    into memory limits.

    :parameter request: Request object (WSGI environ wrapper).
    :parameter stream: Optional callable accepting one parameter only, the
        instance of :class:`FormDecoder` being parsed. If provided, the
        callable is invoked when data or partial data has been successfully
        parsed.

def parse_form_data(request, stream=None, **kw):
    '''Parse form data from an request and return a (forms, files) tuple.

    Both tuple values are dictionaries with the form-field name as a key
    (unicode) and lists as values (multiple values per key are possible).
    The forms-dictionary contains form-field values as unicode strings.
    The files-dictionary contains :class:`MultipartPart` instances, either
    because the form-field was a file-upload or the value is to big to fit
    into memory limits.

    :parameter request: Request object (WSGI environ wrapper).
    :parameter stream: Optional callable accepting one parameter only, the
        instance of :class:`FormDecoder` being parsed. If provided, the
        callable is invoked when data or partial data has been successfully
        parsed.
    '''
    if request.method not in ENCODE_BODY_METHODS:
        raise HttpException(status=422)

    content_type = request.get('CONTENT_TYPE')
    if content_type:
        content_type, options = parse_options_header(content_type)
        options.update(kw)
    else:
        options = kw

    if content_type == 'multipart/form-data':
        decoder = MultipartDecoder(request, options, stream)
    elif content_type in FORM_ENCODED_TYPES:
        decoder = UrlEncodedDecoder(request, options, stream)
    elif content_type in JSON_CONTENT_TYPES:
        decoder = JsonDecoder(request, options, stream)
    else:
        decoder = BytesDecoder(request, options, stream)

    return decoder.parse()