Skip to content

Commit d6d5e28

Browse files
committed
List does't not have attribute lower() error on requestdict, fixes #9
1 parent 68bf1f3 commit d6d5e28

File tree

10 files changed

+127
-25
lines changed

10 files changed

+127
-25
lines changed

app/ch12-forms/final/pypi_org/infrastructure/request_dict.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import flask
2+
from werkzeug.datastructures import MultiDict
23

34

45
class RequestDictionary(dict):
@@ -13,10 +14,21 @@ def __getattr__(self, key):
1314
def create(default_val=None, **route_args) -> RequestDictionary:
1415
request = flask.request
1516

17+
# Adding this retro actively. Some folks are experiencing issues where they
18+
# are getting a list rather than plain dict. I think it's from multiple
19+
# entries in the multidict. This should fix it.
20+
args = request.args
21+
if isinstance(request.args, MultiDict):
22+
args = request.args.to_dict()
23+
24+
form = request.form
25+
if isinstance(request.args, MultiDict):
26+
form = request.form.to_dict()
27+
1628
data = {
17-
**request.args, # The key/value pairs in the URL query string
29+
**args, # The key/value pairs in the URL query string
1830
**request.headers, # Header values
19-
**request.form, # The key/value pairs in the body, from a HTML post form
31+
**form, # The key/value pairs in the body, from a HTML post form
2032
**route_args # And additional arguments the method access, if they want them merged.
2133
}
2234

app/ch13-validation/final/pypi_org/bin/load_data.py

+1-7
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
sys.path.insert(0, os.path.abspath(os.path.join(
1111
os.path.dirname(__file__), "..", "..")))
1212

13+
from pypi_org.bin.load_data import try_int
1314
import pypi_org.data.db_session as db_session
1415
from pypi_org.data.languages import ProgrammingLanguage
1516
from pypi_org.data.licenses import License
@@ -339,13 +340,6 @@ def make_version_num(version_text):
339340
return major, minor, build
340341

341342

342-
def try_int(text) -> int:
343-
try:
344-
return int(text)
345-
except:
346-
return 0
347-
348-
349343
def init_db():
350344
top_folder = os.path.dirname(__file__)
351345
rel_file = os.path.join('..', 'db', 'pypi.sqlite')

app/ch13-validation/final/pypi_org/infrastructure/request_dict.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import flask
2+
from werkzeug.datastructures import MultiDict
23

34

45
class RequestDictionary(dict):
@@ -13,10 +14,21 @@ def __getattr__(self, key):
1314
def create(default_val=None, **route_args) -> RequestDictionary:
1415
request = flask.request
1516

17+
# Adding this retro actively. Some folks are experiencing issues where they
18+
# are getting a list rather than plain dict. I think it's from multiple
19+
# entries in the multidict. This should fix it.
20+
args = request.args
21+
if isinstance(request.args, MultiDict):
22+
args = request.args.to_dict()
23+
24+
form = request.form
25+
if isinstance(request.args, MultiDict):
26+
form = request.form.to_dict()
27+
1628
data = {
17-
**request.args, # The key/value pairs in the URL query string
29+
**args, # The key/value pairs in the URL query string
1830
**request.headers, # Header values
19-
**request.form, # The key/value pairs in the body, from a HTML post form
31+
**form, # The key/value pairs in the body, from a HTML post form
2032
**route_args # And additional arguments the method access, if they want them merged.
2133
}
2234

app/ch13-validation/starter/pypi_org/infrastructure/request_dict.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import flask
2+
from werkzeug.datastructures import MultiDict
23

34

45
class RequestDictionary(dict):
@@ -13,10 +14,21 @@ def __getattr__(self, key):
1314
def create(default_val=None, **route_args) -> RequestDictionary:
1415
request = flask.request
1516

17+
# Adding this retro actively. Some folks are experiencing issues where they
18+
# are getting a list rather than plain dict. I think it's from multiple
19+
# entries in the multidict. This should fix it.
20+
args = request.args
21+
if isinstance(request.args, MultiDict):
22+
args = request.args.to_dict()
23+
24+
form = request.form
25+
if isinstance(request.args, MultiDict):
26+
form = request.form.to_dict()
27+
1628
data = {
17-
**request.args, # The key/value pairs in the URL query string
29+
**args, # The key/value pairs in the URL query string
1830
**request.headers, # Header values
19-
**request.form, # The key/value pairs in the body, from a HTML post form
31+
**form, # The key/value pairs in the body, from a HTML post form
2032
**route_args # And additional arguments the method access, if they want them merged.
2133
}
2234

app/ch14_testing/final/pypi_org/infrastructure/request_dict.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import flask
2+
from werkzeug.datastructures import MultiDict
23

34

45
class RequestDictionary(dict):
@@ -13,10 +14,21 @@ def __getattr__(self, key):
1314
def create(default_val=None, **route_args) -> RequestDictionary:
1415
request = flask.request
1516

17+
# Adding this retro actively. Some folks are experiencing issues where they
18+
# are getting a list rather than plain dict. I think it's from multiple
19+
# entries in the multidict. This should fix it.
20+
args = request.args
21+
if isinstance(request.args, MultiDict):
22+
args = request.args.to_dict()
23+
24+
form = request.form
25+
if isinstance(request.args, MultiDict):
26+
form = request.form.to_dict()
27+
1628
data = {
17-
**request.args, # The key/value pairs in the URL query string
29+
**args, # The key/value pairs in the URL query string
1830
**request.headers, # Header values
19-
**request.form, # The key/value pairs in the body, from a HTML post form
31+
**form, # The key/value pairs in the body, from a HTML post form
2032
**route_args # And additional arguments the method access, if they want them merged.
2133
}
2234

app/ch14_testing/starter/pypi_org/infrastructure/request_dict.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import flask
2+
from werkzeug.datastructures import MultiDict
23

34

45
class RequestDictionary(dict):
@@ -13,10 +14,21 @@ def __getattr__(self, key):
1314
def create(default_val=None, **route_args) -> RequestDictionary:
1415
request = flask.request
1516

17+
# Adding this retro actively. Some folks are experiencing issues where they
18+
# are getting a list rather than plain dict. I think it's from multiple
19+
# entries in the multidict. This should fix it.
20+
args = request.args
21+
if isinstance(request.args, MultiDict):
22+
args = request.args.to_dict()
23+
24+
form = request.form
25+
if isinstance(request.args, MultiDict):
26+
form = request.form.to_dict()
27+
1628
data = {
17-
**request.args, # The key/value pairs in the URL query string
29+
**args, # The key/value pairs in the URL query string
1830
**request.headers, # Header values
19-
**request.form, # The key/value pairs in the body, from a HTML post form
31+
**form, # The key/value pairs in the body, from a HTML post form
2032
**route_args # And additional arguments the method access, if they want them merged.
2133
}
2234

app/ch15_deploy/final/pypi_org/infrastructure/request_dict.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import flask
2+
from werkzeug.datastructures import MultiDict
23

34

45
class RequestDictionary(dict):
@@ -13,10 +14,21 @@ def __getattr__(self, key):
1314
def create(default_val=None, **route_args) -> RequestDictionary:
1415
request = flask.request
1516

17+
# Adding this retro actively. Some folks are experiencing issues where they
18+
# are getting a list rather than plain dict. I think it's from multiple
19+
# entries in the multidict. This should fix it.
20+
args = request.args
21+
if isinstance(request.args, MultiDict):
22+
args = request.args.to_dict()
23+
24+
form = request.form
25+
if isinstance(request.args, MultiDict):
26+
form = request.form.to_dict()
27+
1628
data = {
17-
**request.args, # The key/value pairs in the URL query string
29+
**args, # The key/value pairs in the URL query string
1830
**request.headers, # Header values
19-
**request.form, # The key/value pairs in the body, from a HTML post form
31+
**form, # The key/value pairs in the body, from a HTML post form
2032
**route_args # And additional arguments the method access, if they want them merged.
2133
}
2234

app/ch15_deploy/starter/pypi_org/infrastructure/request_dict.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import flask
2+
from werkzeug.datastructures import MultiDict
23

34

45
class RequestDictionary(dict):
@@ -13,10 +14,21 @@ def __getattr__(self, key):
1314
def create(default_val=None, **route_args) -> RequestDictionary:
1415
request = flask.request
1516

17+
# Adding this retro actively. Some folks are experiencing issues where they
18+
# are getting a list rather than plain dict. I think it's from multiple
19+
# entries in the multidict. This should fix it.
20+
args = request.args
21+
if isinstance(request.args, MultiDict):
22+
args = request.args.to_dict()
23+
24+
form = request.form
25+
if isinstance(request.args, MultiDict):
26+
form = request.form.to_dict()
27+
1628
data = {
17-
**request.args, # The key/value pairs in the URL query string
29+
**args, # The key/value pairs in the URL query string
1830
**request.headers, # Header values
19-
**request.form, # The key/value pairs in the body, from a HTML post form
31+
**form, # The key/value pairs in the body, from a HTML post form
2032
**route_args # And additional arguments the method access, if they want them merged.
2133
}
2234

app/ch16_mongodb/final/pypi_org/infrastructure/request_dict.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import flask
2+
from werkzeug.datastructures import MultiDict
23

34

45
class RequestDictionary(dict):
@@ -13,10 +14,21 @@ def __getattr__(self, key):
1314
def create(default_val=None, **route_args) -> RequestDictionary:
1415
request = flask.request
1516

17+
# Adding this retro actively. Some folks are experiencing issues where they
18+
# are getting a list rather than plain dict. I think it's from multiple
19+
# entries in the multidict. This should fix it.
20+
args = request.args
21+
if isinstance(request.args, MultiDict):
22+
args = request.args.to_dict()
23+
24+
form = request.form
25+
if isinstance(request.args, MultiDict):
26+
form = request.form.to_dict()
27+
1628
data = {
17-
**request.args, # The key/value pairs in the URL query string
29+
**args, # The key/value pairs in the URL query string
1830
**request.headers, # Header values
19-
**request.form, # The key/value pairs in the body, from a HTML post form
31+
**form, # The key/value pairs in the body, from a HTML post form
2032
**route_args # And additional arguments the method access, if they want them merged.
2133
}
2234

app/ch16_mongodb/starter/pypi_org/infrastructure/request_dict.py

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import flask
2+
from werkzeug.datastructures import MultiDict
23

34

45
class RequestDictionary(dict):
@@ -13,10 +14,21 @@ def __getattr__(self, key):
1314
def create(default_val=None, **route_args) -> RequestDictionary:
1415
request = flask.request
1516

17+
# Adding this retro actively. Some folks are experiencing issues where they
18+
# are getting a list rather than plain dict. I think it's from multiple
19+
# entries in the multidict. This should fix it.
20+
args = request.args
21+
if isinstance(request.args, MultiDict):
22+
args = request.args.to_dict()
23+
24+
form = request.form
25+
if isinstance(request.args, MultiDict):
26+
form = request.form.to_dict()
27+
1628
data = {
17-
**request.args, # The key/value pairs in the URL query string
29+
**args, # The key/value pairs in the URL query string
1830
**request.headers, # Header values
19-
**request.form, # The key/value pairs in the body, from a HTML post form
31+
**form, # The key/value pairs in the body, from a HTML post form
2032
**route_args # And additional arguments the method access, if they want them merged.
2133
}
2234

0 commit comments

Comments
 (0)