mirror of
https://github.com/python/cpython.git
synced 2025-08-03 00:23:06 +00:00
Factor out code used by packaging commands for HTTP requests (#12169).
We now have one function to prepare multipart POST requests, and we use CRLF, as recommended by the HTTP spec (#10150). Initial patch by John Edmonds.
This commit is contained in:
parent
f8bebf8566
commit
ce5fe83878
9 changed files with 96 additions and 138 deletions
|
@ -9,8 +9,7 @@ except ImportError:
|
|||
_ssl = None
|
||||
|
||||
from packaging.command import upload_docs as upload_docs_mod
|
||||
from packaging.command.upload_docs import (upload_docs, zip_dir,
|
||||
encode_multipart)
|
||||
from packaging.command.upload_docs import upload_docs, zip_dir
|
||||
from packaging.dist import Distribution
|
||||
from packaging.errors import PackagingFileError, PackagingOptionError
|
||||
|
||||
|
@ -23,23 +22,6 @@ except ImportError:
|
|||
PyPIServerTestCase = object
|
||||
|
||||
|
||||
EXPECTED_MULTIPART_OUTPUT = [
|
||||
b'---x',
|
||||
b'Content-Disposition: form-data; name="username"',
|
||||
b'',
|
||||
b'wok',
|
||||
b'---x',
|
||||
b'Content-Disposition: form-data; name="password"',
|
||||
b'',
|
||||
b'secret',
|
||||
b'---x',
|
||||
b'Content-Disposition: form-data; name="picture"; filename="wok.png"',
|
||||
b'',
|
||||
b'PNG89',
|
||||
b'---x--',
|
||||
b'',
|
||||
]
|
||||
|
||||
PYPIRC = """\
|
||||
[distutils]
|
||||
index-servers = server1
|
||||
|
@ -108,13 +90,6 @@ class UploadDocsTestCase(support.TempdirManager,
|
|||
zip_f = zipfile.ZipFile(compressed)
|
||||
self.assertEqual(zip_f.namelist(), ['index.html', 'docs/index.html'])
|
||||
|
||||
def test_encode_multipart(self):
|
||||
fields = [('username', 'wok'), ('password', 'secret')]
|
||||
files = [('picture', 'wok.png', b'PNG89')]
|
||||
content_type, body = encode_multipart(fields, files, b'-x')
|
||||
self.assertEqual(b'multipart/form-data; boundary=-x', content_type)
|
||||
self.assertEqual(EXPECTED_MULTIPART_OUTPUT, body.split(b'\r\n'))
|
||||
|
||||
def prepare_command(self):
|
||||
self.cmd.upload_dir = self.prepare_sample_dir()
|
||||
self.cmd.ensure_finalized()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue