summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/email/message.py18
-rw-r--r--Lib/zipfile.py7
2 files changed, 17 insertions, 8 deletions
diff --git a/Lib/email/message.py b/Lib/email/message.py
index ff262c7..471d46b 100644
--- a/Lib/email/message.py
+++ b/Lib/email/message.py
@@ -20,18 +20,22 @@ from email.charset import Charset
SEMISPACE = '; '
-# Regular expression used to split header parameters. BAW: this may be too
-# simple. It isn't strictly RFC 2045 (section 5.1) compliant, but it catches
-# most headers found in the wild. We may eventually need a full fledged
-# parser eventually.
-paramre = re.compile(r'\s*;\s*')
# Regular expression that matches `special' characters in parameters, the
# existance of which force quoting of the parameter value.
tspecials = re.compile(r'[ \(\)<>@,;:\\"/\[\]\?=]')
-
# Helper functions
+def _splitparam(param):
+ # Split header parameters. BAW: this may be too simple. It isn't
+ # strictly RFC 2045 (section 5.1) compliant, but it catches most headers
+ # found in the wild. We may eventually need a full fledged parser
+ # eventually.
+ a, sep, b = param.partition(';')
+ if not sep:
+ return a.strip(), None
+ return a.strip(), b.strip()
+
def _formatparam(param, value=None, quote=True):
"""Convenience function to format and return a key=value pair.
@@ -443,7 +447,7 @@ class Message:
if value is missing:
# This should have no parameters
return self.get_default_type()
- ctype = paramre.split(value)[0].lower().strip()
+ ctype = _splitparam(value)[0].lower()
# RFC 2045, section 5.2 says if its invalid, use text/plain
if ctype.count('/') != 1:
return 'text/plain'
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index e4bc019..9e96e93 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -813,9 +813,14 @@ class ZipFile:
def testzip(self):
"""Read all the files and check the CRC."""
+ chunk_size = 2 ** 20
for zinfo in self.filelist:
try:
- self.read(zinfo.filename) # Check CRC-32
+ # Read by chunks, to avoid an OverflowError or a
+ # MemoryError with very large embedded files.
+ f = self.open(zinfo.filename, "r")
+ while f.read(chunk_size): # Check CRC-32
+ pass
except BadZipfile:
return zinfo.filename