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

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

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 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/opcode.py ('k') | Lib/packaging/command/upload_docs.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 """Register a release with a project index.""" 1 """Register a release with a project index."""
2 2
3 # Contributed by Richard Jones 3 # Contributed by Richard Jones
4 4
5 import io 5 import io
6 import getpass 6 import getpass
7 import urllib.error 7 import urllib.error
8 import urllib.parse 8 import urllib.parse
9 import urllib.request 9 import urllib.request
10 10
11 from packaging import logger 11 from packaging import logger
12 from packaging.util import (read_pypirc, generate_pypirc, DEFAULT_REPOSITORY, 12 from packaging.util import (read_pypirc, generate_pypirc, DEFAULT_REPOSITORY,
13 DEFAULT_REALM, get_pypirc_path, encode_multipart) 13 DEFAULT_REALM, get_pypirc_path)
14 from packaging.command.cmd import Command 14 from packaging.command.cmd import Command
15 15
16 class register(Command): 16 class register(Command):
17 17
18 description = "register a release with PyPI" 18 description = "register a release with PyPI"
19 user_options = [ 19 user_options = [
20 ('repository=', 'r', 20 ('repository=', 'r',
21 "repository URL [default: %s]" % DEFAULT_REPOSITORY), 21 "repository URL [default: %s]" % DEFAULT_REPOSITORY),
22 ('show-response', None, 22 ('show-response', None,
23 "display full response text from server"), 23 "display full response text from server"),
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 data[':action'] = action 224 data[':action'] = action
225 return data 225 return data
226 226
227 # XXX to be refactored with upload.upload_file 227 # XXX to be refactored with upload.upload_file
228 def post_to_server(self, data, auth=None): 228 def post_to_server(self, data, auth=None):
229 ''' Post a query to the server, and return a string response. 229 ''' Post a query to the server, and return a string response.
230 ''' 230 '''
231 if 'name' in data: 231 if 'name' in data:
232 logger.info('Registering %s to %s', data['name'], self.repository) 232 logger.info('Registering %s to %s', data['name'], self.repository)
233 # Build up the MIME payload for the urllib2 POST data 233 # Build up the MIME payload for the urllib2 POST data
234 content_type, body = encode_multipart(data.items(), []) 234 boundary = '--------------GHSKFJDLGDS7543FJKLFHRE75642756743254'
235 sep_boundary = '\n--' + boundary
236 end_boundary = sep_boundary + '--'
237 body = io.StringIO()
238 for key, value in data.items():
239 # handle multiple entries for the same name
240 if not isinstance(value, (tuple, list)):
241 value = [value]
242
243 for value in value:
244 body.write(sep_boundary)
245 body.write('\nContent-Disposition: form-data; name="%s"'%key)
246 body.write("\n\n")
247 body.write(value)
248 if value and value[-1] == '\r':
249 body.write('\n') # write an extra newline (lurve Macs)
250 body.write(end_boundary)
251 body.write("\n")
252 body = body.getvalue()
235 253
236 # build the Request 254 # build the Request
237 headers = { 255 headers = {
238 'Content-type': content_type, 256 'Content-type': 'multipart/form-data; boundary=%s; charset=utf-8'%bo undary,
239 'Content-length': str(len(body)) 257 'Content-length': str(len(body))
240 } 258 }
241 req = urllib.request.Request(self.repository, body, headers) 259 req = urllib.request.Request(self.repository, body, headers)
242 260
243 # handle HTTP and include the Basic Auth handler 261 # handle HTTP and include the Basic Auth handler
244 opener = urllib.request.build_opener( 262 opener = urllib.request.build_opener(
245 urllib.request.HTTPBasicAuthHandler(password_mgr=auth) 263 urllib.request.HTTPBasicAuthHandler(password_mgr=auth)
246 ) 264 )
247 data = '' 265 data = ''
248 try: 266 try:
249 result = opener.open(req) 267 result = opener.open(req)
250 except urllib.error.HTTPError as e: 268 except urllib.error.HTTPError as e:
251 if self.show_response: 269 if self.show_response:
252 data = e.fp.read() 270 data = e.fp.read()
253 result = e.code, e.msg 271 result = e.code, e.msg
254 except urllib.error.URLError as e: 272 except urllib.error.URLError as e:
255 result = 500, str(e) 273 result = 500, str(e)
256 else: 274 else:
257 if self.show_response: 275 if self.show_response:
258 data = result.read() 276 data = result.read()
259 result = 200, 'OK' 277 result = 200, 'OK'
260 if self.show_response: 278 if self.show_response:
261 dashes = '-' * 75 279 dashes = '-' * 75
262 logger.info('%s%s%s', dashes, data, dashes) 280 logger.info('%s%s%s', dashes, data, dashes)
263 281
264 return result 282 return result
OLDNEW
« no previous file with comments | « Lib/opcode.py ('k') | Lib/packaging/command/upload_docs.py » ('j') | no next file with comments »

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