mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
#4338: Fix the distutils "setup.py upload" command.
The code still mixed bytes and strings. Reviewed by Martin von Loewis.
This commit is contained in:
parent
9d24ff027f
commit
836b670e89
2 changed files with 21 additions and 17 deletions
|
@ -7,11 +7,11 @@ from distutils.core import PyPIRCCommand
|
||||||
from distutils.spawn import spawn
|
from distutils.spawn import spawn
|
||||||
from distutils import log
|
from distutils import log
|
||||||
from hashlib import md5
|
from hashlib import md5
|
||||||
import os
|
import os, io
|
||||||
import socket
|
import socket
|
||||||
import platform
|
import platform
|
||||||
import configparser
|
import configparser
|
||||||
import http.client
|
import http.client as httpclient
|
||||||
import base64
|
import base64
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
|
|
||||||
|
@ -113,33 +113,35 @@ class upload(PyPIRCCommand):
|
||||||
open(filename+".asc").read())
|
open(filename+".asc").read())
|
||||||
|
|
||||||
# set up the authentication
|
# set up the authentication
|
||||||
auth = "Basic " + base64.encodestring(self.username + ":" + self.password).strip()
|
user_pass = (self.username + ":" + self.password).encode('ascii')
|
||||||
|
# The exact encoding of the authentication string is debated.
|
||||||
|
# Anyway PyPI only accepts ascii for both username or password.
|
||||||
|
auth = "Basic " + base64.encodestring(user_pass).strip().decode('ascii')
|
||||||
|
|
||||||
# Build up the MIME payload for the POST data
|
# Build up the MIME payload for the POST data
|
||||||
boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
|
boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
|
||||||
sep_boundary = '\n--' + boundary
|
sep_boundary = b'\n--' + boundary.encode('ascii')
|
||||||
end_boundary = sep_boundary + '--'
|
end_boundary = sep_boundary + b'--'
|
||||||
body = io.StringIO()
|
body = io.BytesIO()
|
||||||
for key, value in data.items():
|
for key, value in data.items():
|
||||||
|
title = '\nContent-Disposition: form-data; name="%s"' % key
|
||||||
# handle multiple entries for the same name
|
# handle multiple entries for the same name
|
||||||
if type(value) != type([]):
|
if type(value) != type([]):
|
||||||
value = [value]
|
value = [value]
|
||||||
for value in value:
|
for value in value:
|
||||||
if type(value) is tuple:
|
if type(value) is tuple:
|
||||||
fn = ';filename="%s"' % value[0]
|
title += '; filename="%s"' % value[0]
|
||||||
value = value[1]
|
value = value[1]
|
||||||
else:
|
else:
|
||||||
fn = ""
|
value = str(value).encode('utf-8')
|
||||||
value = str(value)
|
|
||||||
body.write(sep_boundary)
|
body.write(sep_boundary)
|
||||||
body.write('\nContent-Disposition: form-data; name="%s"'%key)
|
body.write(title.encode('utf-8'))
|
||||||
body.write(fn)
|
body.write(b"\n\n")
|
||||||
body.write("\n\n")
|
|
||||||
body.write(value)
|
body.write(value)
|
||||||
if value and value[-1] == '\r':
|
if value and value[-1:] == b'\r':
|
||||||
body.write('\n') # write an extra newline (lurve Macs)
|
body.write(b'\n') # write an extra newline (lurve Macs)
|
||||||
body.write(end_boundary)
|
body.write(end_boundary)
|
||||||
body.write("\n")
|
body.write(b"\n")
|
||||||
body = body.getvalue()
|
body = body.getvalue()
|
||||||
|
|
||||||
self.announce("Submitting %s to %s" % (filename, self.repository), log.INFO)
|
self.announce("Submitting %s to %s" % (filename, self.repository), log.INFO)
|
||||||
|
@ -152,9 +154,9 @@ class upload(PyPIRCCommand):
|
||||||
urllib.parse.urlparse(self.repository)
|
urllib.parse.urlparse(self.repository)
|
||||||
assert not params and not query and not fragments
|
assert not params and not query and not fragments
|
||||||
if schema == 'http':
|
if schema == 'http':
|
||||||
http = http.client.HTTPConnection(netloc)
|
http = httpclient.HTTPConnection(netloc)
|
||||||
elif schema == 'https':
|
elif schema == 'https':
|
||||||
http = http.client.HTTPSConnection(netloc)
|
http = httpclient.HTTPSConnection(netloc)
|
||||||
else:
|
else:
|
||||||
raise AssertionError("unsupported schema "+schema)
|
raise AssertionError("unsupported schema "+schema)
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,8 @@ Core and Builtins
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #4338: Fix distutils upload command.
|
||||||
|
|
||||||
- Issue #4354: Fix distutils register command.
|
- Issue #4354: Fix distutils register command.
|
||||||
|
|
||||||
- Issue #4116: Resolve member name conflict in ScrolledCanvas.__init__.
|
- Issue #4116: Resolve member name conflict in ScrolledCanvas.__init__.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue