A few issues about this commit:
* It should have an entry in news.txt, the docstring needs updating, and
also in docs/reference.txt.
* While I think it's reasonable to default POST requests to be a form
request, I don't think this is reasonable for PUT requests. I.e.,
lacking a Content-Type header, I don't think a PUT should be treated
like a form submission.
[EMAIL PROTECTED] wrote:
> Author: pjenvey
> Date: Wed Aug 27 13:50:06 2008
> New Revision: 7504
>
> Modified:
> Paste/WebOb/trunk/tests/test_request.py
> Paste/WebOb/trunk/tests/test_request.txt
> Paste/WebOb/trunk/webob/__init__.py
>
> Log:
> support request.POST in PUT form requests
>
> Modified: Paste/WebOb/trunk/tests/test_request.py
> ==============================================================================
> --- Paste/WebOb/trunk/tests/test_request.py (original)
> +++ Paste/WebOb/trunk/tests/test_request.py Wed Aug 27 13:50:06 2008
> @@ -34,7 +34,7 @@
> print res
> assert 'Hello' in res
> assert "get is MultiDict([])" in res
> - assert "post is <NoVars: Not a POST request>" in res
> + assert "post is <NoVars: Not a POST or form request>" in res
>
> res = app.get('/?name=george')
> res.mustcontain("get is MultiDict([('name', 'george')])")
>
> Modified: Paste/WebOb/trunk/tests/test_request.txt
> ==============================================================================
> --- Paste/WebOb/trunk/tests/test_request.txt (original)
> +++ Paste/WebOb/trunk/tests/test_request.txt Wed Aug 27 13:50:06 2008
> @@ -101,18 +101,34 @@
> >>> req.POST
> UnicodeMultiDict([('var1', u'value1'), ('var2', u'value2'), ('rep',
> u'1'), ('rep', u'2')])
>
> -Note that the variables are there for GET requests and non-form POST
> -requests, but they are empty and read-only:
> +The ``POST`` and ``GET`` nomenclature for request variables is
> +historical -- ``request.GET`` can be used in non GET requests to
> +access query parameters, and ``request.POST`` can be used in PUT form
> +requests.
> +
> + >>> body = 'var1=value1&var2=value2&rep=1&rep=2'
> + >>> req = Request.blank('/?foo=bar')
> + >>> req.method = 'PUT'
> + >>> req.body_file = StringIO(body)
> + >>> req.environ['CONTENT_LENGTH'] = str(len(body))
> + >>> req.environ['CONTENT_TYPE'] = 'application/x-www-form-urlencoded'
> + >>> req.POST
> + MultiDict([('var1', 'value1'), ('var2', 'value2'), ('rep', '1'), ('rep',
> '2')])
> + >>> req.GET
> + MultiDict([('foo', 'bar')])
> +
> +Note that the variables are there for GET requests and non-form requests,
> +but they are empty and read-only:
>
> >>> req = Request.blank('/')
> >>> req.str_POST
> - <NoVars: Not a POST request>
> + <NoVars: Not a POST or form request>
> >>> req.str_POST.items()
> []
> >>> req.str_POST['x'] = 'y'
> Traceback (most recent call last):
> ...
> - KeyError: 'Cannot add variables: Not a POST request'
> + KeyError: 'Cannot add variables: Not a POST or form request'
> >>> req.method = 'POST'
> >>> req.str_POST
> MultiDict([])
>
> Modified: Paste/WebOb/trunk/webob/__init__.py
> ==============================================================================
> --- Paste/WebOb/trunk/webob/__init__.py (original)
> +++ Paste/WebOb/trunk/webob/__init__.py Wed Aug 27 13:50:06 2008
> @@ -863,8 +863,8 @@
> object in that case).
> """
> env = self.environ
> - if self.method != 'POST':
> - return NoVars('Not a POST request')
> + if self.method not in ('POST', 'PUT'):
> + return NoVars('Not a POST or form request')
> if 'webob._parsed_post_vars' in env:
> vars, body_file = env['webob._parsed_post_vars']
> if body_file is self.body_file:
>
_______________________________________________
Paste-users mailing list
[email protected]
http://webwareforpython.org/cgi-bin/mailman/listinfo/paste-users