| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -32,10 +32,12 @@ | |||
| 32 | 32 | # ======= | |
| 33 | 33 | ||
| 34 | 34 | from io import StringIO, BytesIO, TextIOWrapper | |
| 35 | + from collections import Mapping | ||
| 35 | 36 | import sys | |
| 36 | 37 | import os | |
| 37 | 38 | import urllib.parse | |
| 38 | 39 | from email.parser import FeedParser | |
| 40 | + from email.message import Message | ||
| 39 | 41 | from warnings import warn | |
| 40 | 42 | import html | |
| 41 | 43 | import locale | |
@@ -472,18 +474,24 @@ def __init__(self, fp=None, headers=None, outerboundary=b'', | |||
| 472 | 474 | self.qs_on_post = environ['QUERY_STRING'] | |
| 473 | 475 | if 'CONTENT_LENGTH' in environ: | |
| 474 | 476 | headers['content-length'] = environ['CONTENT_LENGTH'] | |
| 477 | + else: | ||
| 478 | + if not (isinstance(headers, (Mapping, Message))): | ||
| 479 | + raise TypeError("headers must be mapping or an instance of " | ||
| 480 | + "email.message.Message") | ||
| 481 | + self.headers = headers | ||
| 475 | 482 | if fp is None: | |
| 476 | 483 | self.fp = sys.stdin.buffer | |
| 477 | 484 | # self.fp.read() must return bytes | |
| 478 | 485 | elif isinstance(fp, TextIOWrapper): | |
| 479 | 486 | self.fp = fp.buffer | |
| 480 | 487 | else: | |
| 488 | + if not (hasattr(fp, 'read') and hasattr(fp, 'readline')): | ||
| 489 | + raise TypeError("fp must be file pointer") | ||
| 481 | 490 | self.fp = fp | |
| 482 | 491 | ||
| 483 | 492 | self.encoding = encoding | |
| 484 | 493 | self.errors = errors | |
| 485 | 494 | ||
| 486 | - self.headers = headers | ||
| 487 | 495 | if not isinstance(outerboundary, bytes): | |
| 488 | 496 | raise TypeError('outerboundary must be bytes, not %s' | |
| 489 | 497 | % type(outerboundary).__name__) | |
@@ -642,7 +650,9 @@ def __len__(self): | |||
| 642 | 650 | """Dictionary style len(x) support.""" | |
| 643 | 651 | return len(self.keys()) | |
| 644 | 652 | ||
| 645 | - def __nonzero__(self): | ||
| 653 | + def __bool__(self): | ||
| 654 | + if self.list is None: | ||
| 655 | + raise TypeError("Cannot be converted to bool.") | ||
| 646 | 656 | return bool(self.list) | |
| 647 | 657 | ||
| 648 | 658 | def read_urlencoded(self): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -137,6 +137,13 @@ def test_fieldstorage_properties(self): | |||
| 137 | 137 | fs.list.append(namedtuple('MockFieldStorage', 'name')('fieldvalue')) | |
| 138 | 138 | self.assertTrue(fs) | |
| 139 | 139 | ||
| 140 | + def test_fieldstorage_invalid(self): | ||
| 141 | + self.assertRaises(TypeError, cgi.FieldStorage, "not-a-file-obj", | ||
| 142 | + environ={"REQUEST_METHOD":"PUT"}) | ||
| 143 | + self.assertRaises(TypeError, cgi.FieldStorage, "foo", "bar") | ||
| 144 | + fs = cgi.FieldStorage(headers={'content-type':'text/plain'}) | ||
| 145 | + self.assertRaises(TypeError, bool, fs) | ||
| 146 | + | ||
| 140 | 147 | def test_escape(self): | |
| 141 | 148 | # cgi.escape() is deprecated. | |
| 142 | 149 | with warnings.catch_warnings(): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,7 +25,14 @@ Core and Builtins | |||
| 25 | 25 | Library | |
| 26 | 26 | ------- | |
| 27 | 27 | ||
| 28 | + <<<<<<< local | ||
| 28 | 29 | - Issue #20152: Ported Python/import.c over to Argument Clinic. | |
| 30 | + ======= | ||
| 31 | + - Issue #19097: Raise the correct Exception when cgi.FieldStorage is given an | ||
| 32 | + Invalid fileobj. | ||
| 33 | + | ||
| 34 | + - Issue #20217: Fix build in SCHED_SPORADIC is defined. | ||
| 35 | + >>>>>>> other | ||
| 29 | 36 | ||
| 30 | 37 | - Issue #13107: argparse and optparse no longer raises an exception when output | |
| 31 | 38 | a help on environment with too small COLUMNS. Based on patch by | |
| Back | FazBrowse Home | New Git URL |
0 commit comments