Beispiel #1
0
 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 = ''
Beispiel #2
0
def test_extract_filename_without_filename():
    assert extract_filename({}) == ''
Beispiel #3
0
def test_extract_filename_star_without_quotes():
    assert extract_filename({b'filename*':
                             "foo-ä-€.html".encode()}) == "foo-ä-€.html"
Beispiel #4
0
def test_extract_filename_star_without_quotes_but_filename():
    assert extract_filename({
        b'filename*': "foo-ä-€.html".encode(),
        b'filename': b"baz.quux"
    }) == "baz.quux"
Beispiel #5
0
def test_extract_filename_star_no_encoding():
    assert extract_filename({b'filename*':
                             "''foo-ä-€.html".encode()}) == "foo-ä-€.html"
Beispiel #6
0
def test_extract_filename_star_no_encoding_but_filename():
    assert extract_filename({
        b'filename*': "''foo-ä-€.html".encode(),
        b'filename': b"baz.quux"
    }) == "baz.quux"
Beispiel #7
0
def test_extract_filename_star_latin1_with_accent():
    assert extract_filename(
        {b'filename*':
         "iso-8859-1''foo-ä.html".encode('latin1')}) == 'foo-ä.html'
Beispiel #8
0
def test_extract_filename_star_utf8_with_accent():
    assert extract_filename({b'filename*':
                             "UTF-8''foo-ä-€.html".encode()}) == 'foo-ä-€.html'
Beispiel #9
0
def test_extract_filename():
    assert extract_filename({b'filename': b'foo.bar'}) == 'foo.bar'
Beispiel #10
0
def test_extract_filename_star_wrong_encoding():
    assert extract_filename({b'filename*': b"unknow''foo.bar"}) == 'foo.bar'
Beispiel #11
0
def test_extract_filename_and_star_wrong_encoding():
    assert extract_filename({
        b'filename*': b"unknown''foo.bar",
        b'filename': b"baz.quux"
    }) == 'baz.quux'
Beispiel #12
0
def test_extract_filename_and_star():
    assert extract_filename({
        b'filename*': b"utf-8''foo.bar",
        b'filename': b"baz.quux"
    }) == 'foo.bar'
Beispiel #13
0
def test_extract_filename_star():
    assert extract_filename({b'filename*': b"utf-8''foo.bar"}) == 'foo.bar'