diff options
author | Senthil Kumaran <senthil@uthcode.com> | 2014-01-12 06:22:21 (GMT) |
---|---|---|
committer | Senthil Kumaran <senthil@uthcode.com> | 2014-01-12 06:22:21 (GMT) |
commit | d87346c0ced1f39b60de4688d6d73355d36f2b97 (patch) | |
tree | 6c56d2b0f2ec62ef790a6cb48a294d3c7d546cdd /Lib/cgi.py | |
parent | 932c3458df7332658de80835a78a781ab60fdb1e (diff) | |
parent | b4cbb92fbe6290c3574e73288de9e9cbb60b7688 (diff) | |
download | cpython-d87346c0ced1f39b60de4688d6d73355d36f2b97.zip cpython-d87346c0ced1f39b60de4688d6d73355d36f2b97.tar.gz cpython-d87346c0ced1f39b60de4688d6d73355d36f2b97.tar.bz2 |
merge from 3.3
Issue #19092 - Raise a correct exception when cgi.FieldStorage is given an
invalid file-obj. Also use __bool__ to determine the bool of the FieldStorage
object.
Diffstat (limited to 'Lib/cgi.py')
-rwxr-xr-x | Lib/cgi.py | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -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__) @@ -642,7 +650,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): |