summaryrefslogtreecommitdiffstats
path: root/Lib/distutils/command
diff options
context:
space:
mode:
authorTarek Ziadé <ziade.tarek@gmail.com>2009-06-15 23:30:13 (GMT)
committerTarek Ziadé <ziade.tarek@gmail.com>2009-06-15 23:30:13 (GMT)
commita1cc040828ff2c46a0c8560bddc7d21d3b9e78ef (patch)
tree6af896220532ffaf32d250c21d38fcbf16c9d9da /Lib/distutils/command
parentd7c5cee2d59e5f118383804839b1f18d7302a32a (diff)
downloadcpython-a1cc040828ff2c46a0c8560bddc7d21d3b9e78ef.zip
cpython-a1cc040828ff2c46a0c8560bddc7d21d3b9e78ef.tar.gz
cpython-a1cc040828ff2c46a0c8560bddc7d21d3b9e78ef.tar.bz2
Issue #6286: distutils upload command now uses urllib2
Diffstat (limited to 'Lib/distutils/command')
-rw-r--r--Lib/distutils/command/upload.py56
1 files changed, 28 insertions, 28 deletions
diff --git a/Lib/distutils/command/upload.py b/Lib/distutils/command/upload.py
index d306681..8114feb 100644
--- a/Lib/distutils/command/upload.py
+++ b/Lib/distutils/command/upload.py
@@ -5,7 +5,7 @@ import sys
import os
import socket
import platform
-import httplib
+from urllib2 import urlopen, Request, HTTPError
import base64
import urlparse
import cStringIO as StringIO
@@ -62,6 +62,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.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]
@@ -153,39 +162,30 @@ class upload(PyPIRCCommand):
self.announce("Submitting %s to %s" % (filename, self.repository), log.INFO)
# build the Request
- # We can't use urllib2 since we need to send the Basic
- # auth right with the first request
- schema, netloc, url, params, query, fragments = \
- urlparse.urlparse(self.repository)
- assert not params and not query and not fragments
- if schema == 'http':
- http = httplib.HTTPConnection(netloc)
- elif schema == 'https':
- http = httplib.HTTPSConnection(netloc)
- else:
- raise AssertionError, "unsupported schema "+schema
-
- data = ''
- loglevel = log.INFO
+ headers = {'Content-type':
+ 'multipart/form-data; boundary=%s' % boundary,
+ 'Content-length': str(len(body)),
+ 'Authorization': auth}
+
+ 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 socket.error, e:
self.announce(str(e), log.ERROR)
return
+ except HTTPError, 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:
- self.announce('-'*75, r.read(), '-'*75)
+ self.announce('-'*75, result.read(), '-'*75)