Anthony Baxter's cleanup patch. Python project SF patch # 583190,

quoting:

  in non-strict mode, messages don't require a blank line at the end
  with a missing end-terminator. A single newline is sufficient now.

  Handle trailing whitespace at the end of a boundary. Had to switch
  from using string.split() to re.split()

  Handle whitespace on the end of a parameter list for Content-type.

  Handle whitespace on the end of a plain content-type header.

Specifically,

get_type(): Strip the content type string.

_get_params_preserve(): Strip the parameter names and values on both
sides.

_parsebody(): Lots of changes as described above, with some stylistic
changes by Barry (who hopefully didn't screw things up ;).
This commit is contained in:
Barry Warsaw 2002-07-18 23:09:09 +00:00
parent e21262ca9e
commit 7aeac9180e
2 changed files with 29 additions and 22 deletions

View file

@ -373,7 +373,7 @@ class Message:
value = self.get('content-type', missing)
if value is missing:
return failobj
return paramre.split(value)[0].lower()
return paramre.split(value)[0].lower().strip()
def get_main_type(self, failobj=None):
"""Return the message's main content type if present."""
@ -428,11 +428,11 @@ class Message:
for p in paramre.split(value):
try:
name, val = p.split('=', 1)
name = name.rstrip()
val = val.lstrip()
name = name.strip()
val = val.strip()
except ValueError:
# Must have been a bare attribute
name = p
name = p.strip()
val = ''
params.append((name, val))
params = Utils.decode_params(params)