def on_headers_complete(self): disposition_type, params = parse_content_disposition( self._current_headers.get(b'Content-Disposition')) if not disposition_type: return self._current_params = params if b'Content-Type' in self._current_headers: self._current = BytesIO() self._current.filename = extract_filename(params) self._current.content_type = self._current_headers[b'Content-Type'] self._current.params = params else: self._current = ''
def test_extract_filename_without_filename(): assert extract_filename({}) == ''
def test_extract_filename_star_without_quotes(): assert extract_filename({b'filename*': "foo-ä-€.html".encode()}) == "foo-ä-€.html"
def test_extract_filename_star_without_quotes_but_filename(): assert extract_filename({ b'filename*': "foo-ä-€.html".encode(), b'filename': b"baz.quux" }) == "baz.quux"
def test_extract_filename_star_no_encoding(): assert extract_filename({b'filename*': "''foo-ä-€.html".encode()}) == "foo-ä-€.html"
def test_extract_filename_star_no_encoding_but_filename(): assert extract_filename({ b'filename*': "''foo-ä-€.html".encode(), b'filename': b"baz.quux" }) == "baz.quux"
def test_extract_filename_star_latin1_with_accent(): assert extract_filename( {b'filename*': "iso-8859-1''foo-ä.html".encode('latin1')}) == 'foo-ä.html'
def test_extract_filename_star_utf8_with_accent(): assert extract_filename({b'filename*': "UTF-8''foo-ä-€.html".encode()}) == 'foo-ä-€.html'
def test_extract_filename(): assert extract_filename({b'filename': b'foo.bar'}) == 'foo.bar'
def test_extract_filename_star_wrong_encoding(): assert extract_filename({b'filename*': b"unknow''foo.bar"}) == 'foo.bar'
def test_extract_filename_and_star_wrong_encoding(): assert extract_filename({ b'filename*': b"unknown''foo.bar", b'filename': b"baz.quux" }) == 'baz.quux'
def test_extract_filename_and_star(): assert extract_filename({ b'filename*': b"utf-8''foo.bar", b'filename': b"baz.quux" }) == 'foo.bar'
def test_extract_filename_star(): assert extract_filename({b'filename*': b"utf-8''foo.bar"}) == 'foo.bar'