mirror of
https://github.com/python/cpython.git
synced 2025-09-12 11:46:52 +00:00
Merge with 3.3 for Issue #19544 and Issue #6286. Merge is untested. I was unable to test due to bab0cbf86835.
This commit is contained in:
commit
0048ae0cc6
3 changed files with 61 additions and 70 deletions
|
@ -10,10 +10,9 @@ import sys
|
|||
import os, io
|
||||
import socket
|
||||
import platform
|
||||
import configparser
|
||||
import http.client as httpclient
|
||||
from base64 import standard_b64encode
|
||||
import urllib.parse
|
||||
from urllib.request import urlopen, Request, HTTPError
|
||||
from urllib.parse import urlparse
|
||||
|
||||
# this keeps compatibility for 2.3 and 2.4
|
||||
if sys.version < "2.5":
|
||||
|
@ -66,6 +65,15 @@ class upload(PyPIRCCommand):
|
|||
self.upload_file(command, pyversion, filename)
|
||||
|
||||
def upload_file(self, command, pyversion, filename):
|
||||
# Makes sure the repository URL is compliant
|
||||
schema, netloc, url, params, query, fragments = \
|
||||
urlparse(self.repository)
|
||||
if params or query or fragments:
|
||||
raise AssertionError("Incompatible url %s" % self.repository)
|
||||
|
||||
if schema not in ('http', 'https'):
|
||||
raise AssertionError("unsupported schema " + schema)
|
||||
|
||||
# Sign if requested
|
||||
if self.sign:
|
||||
gpg_args = ["gpg", "--detach-sign", "-a", filename]
|
||||
|
@ -162,41 +170,31 @@ class upload(PyPIRCCommand):
|
|||
self.announce("Submitting %s to %s" % (filename, self.repository), log.INFO)
|
||||
|
||||
# build the Request
|
||||
# We can't use urllib since we need to send the Basic
|
||||
# auth right with the first request
|
||||
# TODO(jhylton): Can we fix urllib?
|
||||
schema, netloc, url, params, query, fragments = \
|
||||
urllib.parse.urlparse(self.repository)
|
||||
assert not params and not query and not fragments
|
||||
if schema == 'http':
|
||||
http = httpclient.HTTPConnection(netloc)
|
||||
elif schema == 'https':
|
||||
http = httpclient.HTTPSConnection(netloc)
|
||||
else:
|
||||
raise AssertionError("unsupported schema "+schema)
|
||||
headers = {'Content-type':
|
||||
'multipart/form-data; boundary=%s' % boundary,
|
||||
'Content-length': str(len(body)),
|
||||
'Authorization': auth}
|
||||
|
||||
data = ''
|
||||
loglevel = log.INFO
|
||||
request = Request(self.repository, data=body,
|
||||
headers=headers)
|
||||
# send the data
|
||||
try:
|
||||
http.connect()
|
||||
http.putrequest("POST", url)
|
||||
http.putheader('Content-type',
|
||||
'multipart/form-data; boundary=%s'%boundary)
|
||||
http.putheader('Content-length', str(len(body)))
|
||||
http.putheader('Authorization', auth)
|
||||
http.endheaders()
|
||||
http.send(body)
|
||||
result = urlopen(request)
|
||||
status = result.getcode()
|
||||
reason = result.msg
|
||||
except OSError as e:
|
||||
self.announce(str(e), log.ERROR)
|
||||
return
|
||||
except HTTPError as e:
|
||||
status = e.code
|
||||
reason = e.msg
|
||||
|
||||
r = http.getresponse()
|
||||
if r.status == 200:
|
||||
self.announce('Server response (%s): %s' % (r.status, r.reason),
|
||||
if status == 200:
|
||||
self.announce('Server response (%s): %s' % (status, reason),
|
||||
log.INFO)
|
||||
else:
|
||||
self.announce('Upload failed (%s): %s' % (r.status, r.reason),
|
||||
self.announce('Upload failed (%s): %s' % (status, reason),
|
||||
log.ERROR)
|
||||
if self.show_response:
|
||||
msg = '\n'.join(('-' * 75, r.read(), '-' * 75))
|
||||
msg = '\n'.join(('-' * 75, result.read(), '-' * 75))
|
||||
self.announce(msg, log.INFO)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue