Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
55c9e036
Commit
55c9e036
authored
Jan 12, 2014
by
Georg Brandl
Browse files
Options
Browse Files
Download
Plain Diff
merge heads
parents
6392ad98
b4cbb92f
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
22 additions
and
2 deletions
+22
-2
Lib/cgi.py
Lib/cgi.py
+12
-2
Lib/test/test_cgi.py
Lib/test/test_cgi.py
+7
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/cgi.py
View file @
55c9e036
...
...
@@ -32,10 +32,12 @@ __version__ = "2.6"
# =======
from
io
import
StringIO
,
BytesIO
,
TextIOWrapper
from
collections
import
Mapping
import
sys
import
os
import
urllib.parse
from
email.parser
import
FeedParser
from
email.message
import
Message
from
warnings
import
warn
import
html
import
locale
...
...
@@ -472,18 +474,24 @@ class FieldStorage:
self
.
qs_on_post
=
environ
[
'QUERY_STRING'
]
if
'CONTENT_LENGTH'
in
environ
:
headers
[
'content-length'
]
=
environ
[
'CONTENT_LENGTH'
]
else
:
if
not
(
isinstance
(
headers
,
(
Mapping
,
Message
))):
raise
TypeError
(
"headers must be mapping or an instance of "
"email.message.Message"
)
self
.
headers
=
headers
if
fp
is
None
:
self
.
fp
=
sys
.
stdin
.
buffer
# self.fp.read() must return bytes
elif
isinstance
(
fp
,
TextIOWrapper
):
self
.
fp
=
fp
.
buffer
else
:
if
not
(
hasattr
(
fp
,
'read'
)
and
hasattr
(
fp
,
'readline'
)):
raise
TypeError
(
"fp must be file pointer"
)
self
.
fp
=
fp
self
.
encoding
=
encoding
self
.
errors
=
errors
self
.
headers
=
headers
if
not
isinstance
(
outerboundary
,
bytes
):
raise
TypeError
(
'outerboundary must be bytes, not %s'
%
type
(
outerboundary
).
__name__
)
...
...
@@ -636,7 +644,9 @@ class FieldStorage:
"""Dictionary style len(x) support."""
return
len
(
self
.
keys
())
def
__nonzero__
(
self
):
def
__bool__
(
self
):
if
self
.
list
is
None
:
raise
TypeError
(
"Cannot be converted to bool."
)
return
bool
(
self
.
list
)
def
read_urlencoded
(
self
):
...
...
Lib/test/test_cgi.py
View file @
55c9e036
...
...
@@ -137,6 +137,13 @@ class CgiTests(unittest.TestCase):
fs
.
list
.
append
(
namedtuple
(
'MockFieldStorage'
,
'name'
)(
'fieldvalue'
))
self
.
assertTrue
(
fs
)
def
test_fieldstorage_invalid
(
self
):
self
.
assertRaises
(
TypeError
,
cgi
.
FieldStorage
,
"not-a-file-obj"
,
environ
=
{
"REQUEST_METHOD"
:
"PUT"
})
self
.
assertRaises
(
TypeError
,
cgi
.
FieldStorage
,
"foo"
,
"bar"
)
fs
=
cgi
.
FieldStorage
(
headers
=
{
'content-type'
:
'text/plain'
})
self
.
assertRaises
(
TypeError
,
bool
,
fs
)
def
test_escape
(
self
):
# cgi.escape() is deprecated.
with
warnings
.
catch_warnings
():
...
...
Misc/NEWS
View file @
55c9e036
...
...
@@ -43,6 +43,9 @@ Core and Builtins
Library
-------
- Issue #19097: Raise the correct Exception when cgi.FieldStorage is given an
Invalid fileobj.
- Issue #20217: Fix build in SCHED_SPORADIC is defined.
- Issue #13107: argparse and optparse no longer raises an exception when output
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment