Commit 077c9564 authored by Antoine Pitrou's avatar Antoine Pitrou

Issue #21722: The distutils "upload" command now exits with a non-zero return...

Issue #21722: The distutils "upload" command now exits with a non-zero return code when uploading fails.
Patch by Martin Dengler.
parent fa3b9cc7
...@@ -10,7 +10,7 @@ import urlparse ...@@ -10,7 +10,7 @@ import urlparse
import cStringIO as StringIO import cStringIO as StringIO
from hashlib import md5 from hashlib import md5
from distutils.errors import DistutilsOptionError from distutils.errors import DistutilsError, DistutilsOptionError
from distutils.core import PyPIRCCommand from distutils.core import PyPIRCCommand
from distutils.spawn import spawn from distutils.spawn import spawn
from distutils import log from distutils import log
...@@ -181,7 +181,7 @@ class upload(PyPIRCCommand): ...@@ -181,7 +181,7 @@ class upload(PyPIRCCommand):
self.announce(msg, log.INFO) self.announce(msg, log.INFO)
except socket.error, e: except socket.error, e:
self.announce(str(e), log.ERROR) self.announce(str(e), log.ERROR)
return raise
except HTTPError, e: except HTTPError, e:
status = e.code status = e.code
reason = e.msg reason = e.msg
...@@ -190,5 +190,6 @@ class upload(PyPIRCCommand): ...@@ -190,5 +190,6 @@ class upload(PyPIRCCommand):
self.announce('Server response (%s): %s' % (status, reason), self.announce('Server response (%s): %s' % (status, reason),
log.INFO) log.INFO)
else: else:
self.announce('Upload failed (%s): %s' % (status, reason), msg = 'Upload failed (%s): %s' % (status, reason)
log.ERROR) self.announce(msg, log.ERROR)
raise DistutilsError(msg)
...@@ -7,6 +7,7 @@ from test.test_support import run_unittest ...@@ -7,6 +7,7 @@ from test.test_support import run_unittest
from distutils.command import upload as upload_mod from distutils.command import upload as upload_mod
from distutils.command.upload import upload from distutils.command.upload import upload
from distutils.core import Distribution from distutils.core import Distribution
from distutils.errors import DistutilsError
from distutils.tests.test_config import PYPIRC, PyPIRCCommandTestCase from distutils.tests.test_config import PYPIRC, PyPIRCCommandTestCase
...@@ -41,16 +42,17 @@ username:me ...@@ -41,16 +42,17 @@ username:me
class FakeOpen(object): class FakeOpen(object):
def __init__(self, url): def __init__(self, url, msg=None, code=None):
self.url = url self.url = url
if not isinstance(url, str): if not isinstance(url, str):
self.req = url self.req = url
else: else:
self.req = None self.req = None
self.msg = 'OK' self.msg = msg or 'OK'
self.code = code or 200
def getcode(self): def getcode(self):
return 200 return self.code
class uploadTestCase(PyPIRCCommandTestCase): class uploadTestCase(PyPIRCCommandTestCase):
...@@ -60,13 +62,15 @@ class uploadTestCase(PyPIRCCommandTestCase): ...@@ -60,13 +62,15 @@ class uploadTestCase(PyPIRCCommandTestCase):
self.old_open = upload_mod.urlopen self.old_open = upload_mod.urlopen
upload_mod.urlopen = self._urlopen upload_mod.urlopen = self._urlopen
self.last_open = None self.last_open = None
self.next_msg = None
self.next_code = None
def tearDown(self): def tearDown(self):
upload_mod.urlopen = self.old_open upload_mod.urlopen = self.old_open
super(uploadTestCase, self).tearDown() super(uploadTestCase, self).tearDown()
def _urlopen(self, url): def _urlopen(self, url):
self.last_open = FakeOpen(url) self.last_open = FakeOpen(url, msg=self.next_msg, code=self.next_code)
return self.last_open return self.last_open
def test_finalize_options(self): def test_finalize_options(self):
...@@ -124,6 +128,11 @@ class uploadTestCase(PyPIRCCommandTestCase): ...@@ -124,6 +128,11 @@ class uploadTestCase(PyPIRCCommandTestCase):
auth = self.last_open.req.headers['Authorization'] auth = self.last_open.req.headers['Authorization']
self.assertNotIn('\n', auth) self.assertNotIn('\n', auth)
def test_upload_fails(self):
self.next_msg = "Not Found"
self.next_code = 404
self.assertRaises(DistutilsError, self.test_upload)
def test_suite(): def test_suite():
return unittest.makeSuite(uploadTestCase) return unittest.makeSuite(uploadTestCase)
......
...@@ -306,6 +306,7 @@ Vincent Delft ...@@ -306,6 +306,7 @@ Vincent Delft
Arnaud Delobelle Arnaud Delobelle
Konrad Delong Konrad Delong
Erik Demaine Erik Demaine
Martin Dengler
John Dennis John Dennis
L. Peter Deutsch L. Peter Deutsch
Roger Dev Roger Dev
......
...@@ -29,6 +29,9 @@ Core and Builtins ...@@ -29,6 +29,9 @@ Core and Builtins
Library Library
------- -------
- Issue #21722: The distutils "upload" command now exits with a non-zero
return code when uploading fails. Patch by Martin Dengler.
- Issue #21766: Prevent a security hole in CGIHTTPServer by URL unquoting paths - Issue #21766: Prevent a security hole in CGIHTTPServer by URL unquoting paths
before checking for a CGI script at that path. before checking for a CGI script at that path.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment