Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ jobs:
env: pypy3
name: ${{ matrix.env }} on Python ${{ matrix.python }}
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python }}
- run: pip install tox
Expand Down
3 changes: 1 addition & 2 deletions docs/do-it-yourself-framework.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,7 @@ fields::
'name="name"><input type="submit"></form>']

The ``parse_formvars`` function just takes the WSGI environment and
calls the `cgi <http://python.org/doc/current/lib/module-cgi.html>`_
module (the ``FieldStorage`` class) and turns that into a MultiDict.
turns that into a MultiDict which may contain ``FieldStorage`` instances.

Now For a Framework
===================
Expand Down
11 changes: 8 additions & 3 deletions paste/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
# (c) 2005 Ian Bicking and contributors; written for Paste (http://pythonpaste.org)
# Licensed under the MIT license: http://www.opensource.org/licenses/mit-license.php

import warnings

try:
import pkg_resources
pkg_resources.declare_namespace(__name__)
except ImportError:
with warnings.catch_warnings():
warnings.simplefilter("ignore", category=DeprecationWarning)
import pkg_resources
pkg_resources.declare_namespace(__name__)
except (AttributeError, ImportError):
# don't prevent use of paste if pkg_resources isn't installed
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
Expand Down
37 changes: 11 additions & 26 deletions paste/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
* resolve_relative_url(url, environ)

"""
import cgi
from collections.abc import MutableMapping as DictMixin
from urllib import parse as urlparse
from urllib.parse import quote, parse_qsl
from http.cookies import SimpleCookie, CookieError

from paste.util.field_storage import FieldStorage
from paste.util.multidict import MultiDict

__all__ = ['get_cookies', 'get_cookie_dict', 'parse_querystring',
Expand Down Expand Up @@ -151,27 +151,26 @@ def parse_formvars(environ, include_get_vars=True, encoding=None, errors=None):
# fake_out_cgi requests
formvars = MultiDict()
ct = environ.get('CONTENT_TYPE', '').partition(';')[0].lower()
use_cgi = ct in ('', 'application/x-www-form-urlencoded',
'multipart/form-data')
# FieldStorage assumes a default CONTENT_LENGTH of -1, but a
# default of 0 is better:
use_cgi = ct in (
'', 'application/x-www-form-urlencoded', 'multipart/form-data')
# FieldStorage assumes a default CONTENT_LENGTH of -1,
# but a default of 0 is better:
if not environ.get('CONTENT_LENGTH'):
environ['CONTENT_LENGTH'] = '0'
if use_cgi:
# Prevent FieldStorage from parsing QUERY_STRING during GET/HEAD
# requests
old_query_string = environ.get('QUERY_STRING','')
# Prevent FieldStorage from parsing QUERY_STRING
# during GET/HEAD # requests
old_query_string = environ.get('QUERY_STRING', '')
environ['QUERY_STRING'] = ''
inp = environ['wsgi.input']
kwparms = {}
if encoding:
kwparms['encoding'] = encoding
if errors:
kwparms['errors'] = errors
fs = cgi.FieldStorage(fp=inp,
environ=environ,
keep_blank_values=True,
**kwparms)
fs = FieldStorage(
fp=inp, environ=environ, keep_blank_values=True,
**kwparms)
environ['QUERY_STRING'] = old_query_string
if isinstance(fs.value, list):
for name in fs.keys():
Expand Down Expand Up @@ -384,20 +383,6 @@ def keys(self):
def __contains__(self, item):
return self._trans_name(item) in self.environ

def _cgi_FieldStorage__repr__patch(self):
""" monkey patch for FieldStorage.__repr__

Unbelievely, the default __repr__ on FieldStorage reads
the entire file content instead of being sane about it.
This is a simple replacement that doesn't do that
"""
if self.file:
return "FieldStorage(%r, %r)" % (
self.name, self.filename)
return "FieldStorage(%r, %r, %r)" % (
self.name, self.filename, self.value)

cgi.FieldStorage.__repr__ = _cgi_FieldStorage__repr__patch

if __name__ == '__main__':
import doctest
Expand Down
Loading