rfc6266: Simplify ContentDisposition.

This commit is contained in:
Florian Bruhin 2015-08-02 19:48:31 +02:00
parent 25d1064aee
commit 2c7dd5c60c

View File

@ -230,7 +230,7 @@ class InvalidISO8859Error(Error):
"""Exception raised when a byte is invalid in ISO-8859-1.""" """Exception raised when a byte is invalid in ISO-8859-1."""
class ContentDisposition: class _ContentDisposition:
"""Records various indications and hints about content disposition. """Records various indications and hints about content disposition.
@ -239,19 +239,10 @@ class ContentDisposition:
in the download case. in the download case.
""" """
def __init__(self, disposition='inline', assocs=None): def __init__(self, disposition, assocs):
"""Used internally after parsing the header. """Used internally after parsing the header."""
assert len(disposition) == 1
Instances should generally be created from a factory
function, such as parse_headers and its variants.
"""
if len(disposition) != 1:
self.disposition = 'inline'
else:
self.disposition = disposition[0] self.disposition = disposition[0]
if assocs is None:
self.assocs = {}
else:
self.assocs = dict(assocs) # So we can change values self.assocs = dict(assocs) # So we can change values
if 'filename*' in self.assocs: if 'filename*' in self.assocs:
param = self.assocs['filename*'] param = self.assocs['filename*']
@ -296,7 +287,7 @@ def normalize_ws(text):
def parse_headers(content_disposition): def parse_headers(content_disposition):
"""Build a ContentDisposition from header values.""" """Build a _ContentDisposition from header values."""
# https://bitbucket.org/logilab/pylint/issue/492/ # https://bitbucket.org/logilab/pylint/issue/492/
# pylint: disable=no-member # pylint: disable=no-member
@ -315,7 +306,7 @@ def parse_headers(content_disposition):
# case, rather than normalising everything. # case, rather than normalising everything.
content_disposition = normalize_ws(content_disposition) content_disposition = normalize_ws(content_disposition)
parsed = peg.parse(content_disposition, ContentDispositionValue) parsed = peg.parse(content_disposition, ContentDispositionValue)
return ContentDisposition(disposition=parsed.dtype, assocs=parsed.params) return _ContentDisposition(disposition=parsed.dtype, assocs=parsed.params)
def parse_ext_value(val): def parse_ext_value(val):