Changeset 391 for python/trunk/Lib/distutils/command/upload.py
- Timestamp:
- Mar 19, 2014, 11:31:01 PM (11 years ago)
- Location:
- python/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
python/trunk
-
Property svn:mergeinfo
set to
/python/vendor/Python-2.7.6 merged eligible /python/vendor/current merged eligible
-
Property svn:mergeinfo
set to
-
python/trunk/Lib/distutils/command/upload.py
r2 r391 2 2 3 3 Implements the Distutils 'upload' subcommand (upload package to PyPI).""" 4 import os 5 import socket 6 import platform 7 from urllib2 import urlopen, Request, HTTPError 8 from base64 import standard_b64encode 9 import urlparse 10 import cStringIO as StringIO 11 from hashlib import md5 4 12 5 from distutils.errors import *13 from distutils.errors import DistutilsOptionError 6 14 from distutils.core import PyPIRCCommand 7 15 from distutils.spawn import spawn 8 16 from distutils import log 9 from hashlib import md510 import os11 import socket12 import platform13 import httplib14 from base64 import standard_b64encode15 import urlparse16 import cStringIO as StringIO17 from ConfigParser import ConfigParser18 19 17 20 18 class upload(PyPIRCCommand): … … 51 49 self.realm = config['realm'] 52 50 51 # getting the password from the distribution 52 # if previously set by the register command 53 if not self.password and self.distribution.password: 54 self.password = self.distribution.password 55 53 56 def run(self): 54 57 if not self.distribution.dist_files: … … 58 61 59 62 def upload_file(self, command, pyversion, filename): 63 # Makes sure the repository URL is compliant 64 schema, netloc, url, params, query, fragments = \ 65 urlparse.urlparse(self.repository) 66 if params or query or fragments: 67 raise AssertionError("Incompatible url %s" % self.repository) 68 69 if schema not in ('http', 'https'): 70 raise AssertionError("unsupported schema " + schema) 71 60 72 # Sign if requested 61 73 if self.sign: … … 68 80 # Fill in the data - send all the meta-data in case we need to 69 81 # register a new release 70 content = open(filename,'rb').read() 82 f = open(filename,'rb') 83 try: 84 content = f.read() 85 finally: 86 f.close() 71 87 meta = self.distribution.metadata 72 88 data = { … … 126 142 for key, value in data.items(): 127 143 # handle multiple entries for the same name 128 if type(value) != type([]):144 if not isinstance(value, list): 129 145 value = [value] 130 146 for value in value: 131 if type(value) is tuple:147 if isinstance(value, tuple): 132 148 fn = ';filename="%s"' % value[0] 133 149 value = value[1] … … 149 165 150 166 # build the Request 151 # We can't use urllib2 since we need to send the Basic 152 # auth right with the first request 153 schema, netloc, url, params, query, fragments = \ 154 urlparse.urlparse(self.repository) 155 assert not params and not query and not fragments 156 if schema == 'http': 157 http = httplib.HTTPConnection(netloc) 158 elif schema == 'https': 159 http = httplib.HTTPSConnection(netloc) 160 else: 161 raise AssertionError, "unsupported schema "+schema 167 headers = {'Content-type': 168 'multipart/form-data; boundary=%s' % boundary, 169 'Content-length': str(len(body)), 170 'Authorization': auth} 162 171 163 data = '' 164 loglevel = log.INFO 172 request = Request(self.repository, data=body, 173 headers=headers) 174 # send the data 165 175 try: 166 http.connect() 167 http.putrequest("POST", url) 168 http.putheader('Content-type', 169 'multipart/form-data; boundary=%s'%boundary) 170 http.putheader('Content-length', str(len(body))) 171 http.putheader('Authorization', auth) 172 http.endheaders() 173 http.send(body) 176 result = urlopen(request) 177 status = result.getcode() 178 reason = result.msg 179 if self.show_response: 180 msg = '\n'.join(('-' * 75, r.read(), '-' * 75)) 181 self.announce(msg, log.INFO) 174 182 except socket.error, e: 175 183 self.announce(str(e), log.ERROR) 176 184 return 185 except HTTPError, e: 186 status = e.code 187 reason = e.msg 177 188 178 r = http.getresponse() 179 if r.status == 200: 180 self.announce('Server response (%s): %s' % (r.status, r.reason), 189 if status == 200: 190 self.announce('Server response (%s): %s' % (status, reason), 181 191 log.INFO) 182 192 else: 183 self.announce('Upload failed (%s): %s' % ( r.status, r.reason),193 self.announce('Upload failed (%s): %s' % (status, reason), 184 194 log.ERROR) 185 if self.show_response:186 print '-'*75, r.read(), '-'*75
Note:
See TracChangeset
for help on using the changeset viewer.