Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(12)

Side by Side Diff: Lib/packaging/command/upload.py

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 10 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Lib/packaging/command/upload_docs.py ('k') | Lib/packaging/database.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """Upload a distribution to a project index.""" 1 """Upload a distribution to a project index."""
2 2
3 import os 3 import os
4 import socket 4 import socket
5 import logging 5 import logging
6 import platform 6 import platform
7 import urllib.parse 7 import urllib.parse
8 from io import BytesIO 8 from io import BytesIO
9 from base64 import standard_b64encode 9 from base64 import standard_b64encode
10 from hashlib import md5 10 from hashlib import md5
11 from urllib.error import HTTPError 11 from urllib.error import HTTPError
12 from urllib.request import urlopen, Request 12 from urllib.request import urlopen, Request
13 13
14 from packaging import logger 14 from packaging import logger
15 from packaging.errors import PackagingOptionError 15 from packaging.errors import PackagingOptionError
16 from packaging.util import (spawn, read_pypirc, DEFAULT_REPOSITORY, 16 from packaging.util import (spawn, read_pypirc, DEFAULT_REPOSITORY,
17 DEFAULT_REALM, encode_multipart) 17 DEFAULT_REALM)
18 from packaging.command.cmd import Command 18 from packaging.command.cmd import Command
19 19
20 20
21 class upload(Command): 21 class upload(Command):
22 22
23 description = "upload distribution to PyPI" 23 description = "upload distribution to PyPI"
24 24
25 user_options = [ 25 user_options = [
26 ('repository=', 'r', 26 ('repository=', 'r',
27 "repository URL [default: %s]" % DEFAULT_REPOSITORY), 27 "repository URL [default: %s]" % DEFAULT_REPOSITORY),
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 data['gpg_signature'] = [ 124 data['gpg_signature'] = [
125 (os.path.basename(filename) + ".asc", sig)] 125 (os.path.basename(filename) + ".asc", sig)]
126 126
127 # set up the authentication 127 # set up the authentication
128 # The exact encoding of the authentication string is debated. 128 # The exact encoding of the authentication string is debated.
129 # Anyway PyPI only accepts ascii for both username or password. 129 # Anyway PyPI only accepts ascii for both username or password.
130 user_pass = (self.username + ":" + self.password).encode('ascii') 130 user_pass = (self.username + ":" + self.password).encode('ascii')
131 auth = b"Basic " + standard_b64encode(user_pass) 131 auth = b"Basic " + standard_b64encode(user_pass)
132 132
133 # Build up the MIME payload for the POST data 133 # Build up the MIME payload for the POST data
134 files = [] 134 boundary = b'--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
135 for key in ('content', 'gpg_signature'): 135 sep_boundary = b'\n--' + boundary
136 if key in data: 136 end_boundary = sep_boundary + b'--'
137 filename_, value = data.pop(key) 137 body = BytesIO()
138 files.append((key, filename_, value))
139 138
140 content_type, body = encode_multipart(data.items(), files) 139 file_fields = ('content', 'gpg_signature')
140
141 for key, value in data.items():
142 # handle multiple entries for the same name
143 if not isinstance(value, tuple):
144 value = [value]
145
146 content_dispo = '\nContent-Disposition: form-data; name="%s"' % key
147
148 if key in file_fields:
149 filename_, content = value
150 filename_ = ';filename="%s"' % filename_
151 body.write(sep_boundary)
152 body.write(content_dispo.encode('utf-8'))
153 body.write(filename_.encode('utf-8'))
154 body.write(b"\n\n")
155 body.write(content)
156 else:
157 for value in value:
158 value = str(value).encode('utf-8')
159 body.write(sep_boundary)
160 body.write(content_dispo.encode('utf-8'))
161 body.write(b"\n\n")
162 body.write(value)
163 if value and value.endswith(b'\r'):
164 # write an extra newline (lurve Macs)
165 body.write(b'\n')
166
167 body.write(end_boundary)
168 body.write(b"\n")
169 body = body.getvalue()
141 170
142 logger.info("Submitting %s to %s", filename, self.repository) 171 logger.info("Submitting %s to %s", filename, self.repository)
143 172
144 # build the Request 173 # build the Request
145 headers = {'Content-type': content_type, 174 headers = {'Content-type':
175 'multipart/form-data; boundary=%s' %
176 boundary.decode('ascii'),
146 'Content-length': str(len(body)), 177 'Content-length': str(len(body)),
147 'Authorization': auth} 178 'Authorization': auth}
148 179
149 request = Request(self.repository, body, headers) 180 request = Request(self.repository, data=body,
181 headers=headers)
150 # send the data 182 # send the data
151 try: 183 try:
152 result = urlopen(request) 184 result = urlopen(request)
153 status = result.code 185 status = result.code
154 reason = result.msg 186 reason = result.msg
155 except socket.error as e: 187 except socket.error as e:
156 logger.error(e) 188 logger.error(e)
157 return 189 return
158 except HTTPError as e: 190 except HTTPError as e:
159 status = e.code 191 status = e.code
160 reason = e.msg 192 reason = e.msg
161 193
162 if status == 200: 194 if status == 200:
163 logger.info('Server response (%s): %s', status, reason) 195 logger.info('Server response (%s): %s', status, reason)
164 else: 196 else:
165 logger.error('Upload failed (%s): %s', status, reason) 197 logger.error('Upload failed (%s): %s', status, reason)
166 198
167 if self.show_response and logger.isEnabledFor(logging.INFO): 199 if self.show_response and logger.isEnabledFor(logging.INFO):
168 sep = '-' * 75 200 sep = '-' * 75
169 logger.info('%s\n%s\n%s', sep, result.read().decode(), sep) 201 logger.info('%s\n%s\n%s', sep, result.read().decode(), sep)
OLDNEW
« no previous file with comments | « Lib/packaging/command/upload_docs.py ('k') | Lib/packaging/database.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+