Commit dc0f5cdc authored by Éric Araujo's avatar Éric Araujo

Brange merge

parents 3dc89e87 ac6f1c36
...@@ -25,5 +25,5 @@ Hardcore cypherpunks will probably find the cryptographic modules written by ...@@ -25,5 +25,5 @@ Hardcore cypherpunks will probably find the cryptographic modules written by
A.M. Kuchling of further interest; the package contains modules for various A.M. Kuchling of further interest; the package contains modules for various
encryption algorithms, most notably AES. These modules are not distributed with encryption algorithms, most notably AES. These modules are not distributed with
Python but available separately. See the URL Python but available separately. See the URL
http://www.amk.ca/python/code/crypto.html for more information. http://www.pycrypto.org for more information.
...@@ -385,7 +385,7 @@ PEP 3333: Python Web Server Gateway Interface v1.0.1 ...@@ -385,7 +385,7 @@ PEP 3333: Python Web Server Gateway Interface v1.0.1
===================================================== =====================================================
This informational PEP clarifies how bytes/text issues are to be handled by the This informational PEP clarifies how bytes/text issues are to be handled by the
WGSI protocol. The challenge is that string handling in Python 3 is most WSGI protocol. The challenge is that string handling in Python 3 is most
conveniently handled with the :class:`str` type even though the HTTP protocol conveniently handled with the :class:`str` type even though the HTTP protocol
is itself bytes oriented. is itself bytes oriented.
......
...@@ -267,9 +267,15 @@ class Process(object): ...@@ -267,9 +267,15 @@ class Process(object):
sys.stdin = open(os.devnull) sys.stdin = open(os.devnull)
except (OSError, ValueError): except (OSError, ValueError):
pass pass
old_process = _current_process
_current_process = self _current_process = self
util._finalizer_registry.clear() try:
util._run_after_forkers() util._finalizer_registry.clear()
util._run_after_forkers()
finally:
# delay finalization of the old process object until after
# _run_after_forkers() is executed
del old_process
util.info('child process calling self.run()') util.info('child process calling self.run()')
try: try:
self.run() self.run()
......
...@@ -37,7 +37,7 @@ import tempfile ...@@ -37,7 +37,7 @@ import tempfile
from packaging import logger from packaging import logger
from packaging.dist import Distribution from packaging.dist import Distribution
from packaging.tests import unittest from packaging.tests import unittest
from test.support import requires_zlib from test.support import requires_zlib, unlink
__all__ = ['LoggingCatcher', 'TempdirManager', 'EnvironRestorer', __all__ = ['LoggingCatcher', 'TempdirManager', 'EnvironRestorer',
'DummyCommand', 'unittest', 'create_distribution', 'DummyCommand', 'unittest', 'create_distribution',
...@@ -121,21 +121,17 @@ class TempdirManager: ...@@ -121,21 +121,17 @@ class TempdirManager:
def setUp(self): def setUp(self):
super(TempdirManager, self).setUp() super(TempdirManager, self).setUp()
self._olddir = os.getcwd()
self._basetempdir = tempfile.mkdtemp() self._basetempdir = tempfile.mkdtemp()
self._files = [] self._files = []
def tearDown(self): def tearDown(self):
shutil.rmtree(self._basetempdir, os.name in ('nt', 'cygwin'))
for handle, name in self._files: for handle, name in self._files:
handle.close() handle.close()
if os.path.exists(name): unlink(name)
try:
os.remove(name)
except OSError as exc:
if exc.errno != errno.ENOENT:
raise
os.chdir(self._olddir)
shutil.rmtree(self._basetempdir)
super(TempdirManager, self).tearDown() super(TempdirManager, self).tearDown()
def mktempfile(self): def mktempfile(self):
......
...@@ -8,13 +8,10 @@ from packaging.dist import Distribution ...@@ -8,13 +8,10 @@ from packaging.dist import Distribution
from packaging.errors import UnknownFileError, CompileError from packaging.errors import UnknownFileError, CompileError
from packaging.command.build_ext import build_ext from packaging.command.build_ext import build_ext
from packaging.compiler.extension import Extension from packaging.compiler.extension import Extension
from test.script_helper import assert_python_ok
from packaging.tests import support, unittest, verbose, unload from packaging.tests import support, unittest, verbose, unload
# http://bugs.python.org/issue4373
# Don't load the xx module more than once.
ALREADY_TESTED = False
def _get_source_filename(): def _get_source_filename():
srcdir = sysconfig.get_config_var('srcdir') srcdir = sysconfig.get_config_var('srcdir')
...@@ -29,7 +26,6 @@ class BuildExtTestCase(support.TempdirManager, ...@@ -29,7 +26,6 @@ class BuildExtTestCase(support.TempdirManager,
# Note that we're making changes to sys.path # Note that we're making changes to sys.path
super(BuildExtTestCase, self).setUp() super(BuildExtTestCase, self).setUp()
self.tmp_dir = self.mkdtemp() self.tmp_dir = self.mkdtemp()
sys.path.append(self.tmp_dir)
filename = _get_source_filename() filename = _get_source_filename()
if os.path.exists(filename): if os.path.exists(filename):
shutil.copy(filename, self.tmp_dir) shutil.copy(filename, self.tmp_dir)
...@@ -39,8 +35,6 @@ class BuildExtTestCase(support.TempdirManager, ...@@ -39,8 +35,6 @@ class BuildExtTestCase(support.TempdirManager,
def tearDown(self): def tearDown(self):
# Get everything back to normal # Get everything back to normal
unload('xx')
sys.path.remove(self.tmp_dir)
if sys.version > "2.6": if sys.version > "2.6":
site.USER_BASE = self.old_user_base site.USER_BASE = self.old_user_base
build_ext.USER_BASE = self.old_user_base build_ext.USER_BASE = self.old_user_base
...@@ -67,7 +61,6 @@ class BuildExtTestCase(support.TempdirManager, ...@@ -67,7 +61,6 @@ class BuildExtTestCase(support.TempdirManager,
cmd.library_dirs = value.split(os.pathsep) cmd.library_dirs = value.split(os.pathsep)
def test_build_ext(self): def test_build_ext(self):
global ALREADY_TESTED
xx_c = os.path.join(self.tmp_dir, 'xxmodule.c') xx_c = os.path.join(self.tmp_dir, 'xxmodule.c')
if not os.path.exists(xx_c): if not os.path.exists(xx_c):
# skipping if we cannot find it # skipping if we cannot find it
...@@ -95,23 +88,24 @@ class BuildExtTestCase(support.TempdirManager, ...@@ -95,23 +88,24 @@ class BuildExtTestCase(support.TempdirManager,
finally: finally:
sys.stdout = old_stdout sys.stdout = old_stdout
if ALREADY_TESTED: code = """if 1:
return import sys
else: sys.path.insert(0, %r)
ALREADY_TESTED = True
import xx import xx
for attr in ('error', 'foo', 'new', 'roj'): for attr in ('error', 'foo', 'new', 'roj'):
self.assertTrue(hasattr(xx, attr)) assert hasattr(xx, attr)
self.assertEqual(xx.foo(2, 5), 7) assert xx.foo(2, 5) == 7
self.assertEqual(xx.foo(13, 15), 28) assert xx.foo(13, 15) == 28
self.assertEqual(xx.new().demo(), None) assert xx.new().demo() is None
doc = 'This is a template module just for instruction.' doc = 'This is a template module just for instruction.'
self.assertEqual(xx.__doc__, doc) assert xx.__doc__ == doc
self.assertTrue(isinstance(xx.Null(), xx.Null)) assert isinstance(xx.Null(), xx.Null)
self.assertTrue(isinstance(xx.Str(), xx.Str)) assert isinstance(xx.Str(), xx.Str)"""
code = code % self.tmp_dir
assert_python_ok('-c', code)
def test_solaris_enable_shared(self): def test_solaris_enable_shared(self):
dist = Distribution({'name': 'xx'}) dist = Distribution({'name': 'xx'})
......
...@@ -318,6 +318,9 @@ class MockHTTPClass: ...@@ -318,6 +318,9 @@ class MockHTTPClass:
def getresponse(self): def getresponse(self):
return MockHTTPResponse(MockFile(), {}, 200, "OK") return MockHTTPResponse(MockFile(), {}, 200, "OK")
def close(self):
pass
class MockHandler: class MockHandler:
# useful for testing handler machinery # useful for testing handler machinery
# see add_ordered_mock_handlers() docstring # see add_ordered_mock_handlers() docstring
......
...@@ -234,6 +234,7 @@ class TimeoutTest(unittest.TestCase): ...@@ -234,6 +234,7 @@ class TimeoutTest(unittest.TestCase):
url = "http://www.python.org" url = "http://www.python.org"
with support.transient_internet(url, timeout=None): with support.transient_internet(url, timeout=None):
u = _urlopen_with_retry(url) u = _urlopen_with_retry(url)
self.addCleanup(u.close)
self.assertTrue(u.fp.raw._sock.gettimeout() is None) self.assertTrue(u.fp.raw._sock.gettimeout() is None)
def test_http_default_timeout(self): def test_http_default_timeout(self):
...@@ -243,6 +244,7 @@ class TimeoutTest(unittest.TestCase): ...@@ -243,6 +244,7 @@ class TimeoutTest(unittest.TestCase):
socket.setdefaulttimeout(60) socket.setdefaulttimeout(60)
try: try:
u = _urlopen_with_retry(url) u = _urlopen_with_retry(url)
self.addCleanup(u.close)
finally: finally:
socket.setdefaulttimeout(None) socket.setdefaulttimeout(None)
self.assertEqual(u.fp.raw._sock.gettimeout(), 60) self.assertEqual(u.fp.raw._sock.gettimeout(), 60)
...@@ -254,6 +256,7 @@ class TimeoutTest(unittest.TestCase): ...@@ -254,6 +256,7 @@ class TimeoutTest(unittest.TestCase):
socket.setdefaulttimeout(60) socket.setdefaulttimeout(60)
try: try:
u = _urlopen_with_retry(url, timeout=None) u = _urlopen_with_retry(url, timeout=None)
self.addCleanup(u.close)
finally: finally:
socket.setdefaulttimeout(None) socket.setdefaulttimeout(None)
self.assertTrue(u.fp.raw._sock.gettimeout() is None) self.assertTrue(u.fp.raw._sock.gettimeout() is None)
...@@ -262,6 +265,7 @@ class TimeoutTest(unittest.TestCase): ...@@ -262,6 +265,7 @@ class TimeoutTest(unittest.TestCase):
url = "http://www.python.org" url = "http://www.python.org"
with support.transient_internet(url): with support.transient_internet(url):
u = _urlopen_with_retry(url, timeout=120) u = _urlopen_with_retry(url, timeout=120)
self.addCleanup(u.close)
self.assertEqual(u.fp.raw._sock.gettimeout(), 120) self.assertEqual(u.fp.raw._sock.gettimeout(), 120)
FTP_HOST = "ftp://ftp.mirror.nl/pub/gnu/" FTP_HOST = "ftp://ftp.mirror.nl/pub/gnu/"
...@@ -270,6 +274,7 @@ class TimeoutTest(unittest.TestCase): ...@@ -270,6 +274,7 @@ class TimeoutTest(unittest.TestCase):
self.assertTrue(socket.getdefaulttimeout() is None) self.assertTrue(socket.getdefaulttimeout() is None)
with support.transient_internet(self.FTP_HOST, timeout=None): with support.transient_internet(self.FTP_HOST, timeout=None):
u = _urlopen_with_retry(self.FTP_HOST) u = _urlopen_with_retry(self.FTP_HOST)
self.addCleanup(u.close)
self.assertTrue(u.fp.fp.raw._sock.gettimeout() is None) self.assertTrue(u.fp.fp.raw._sock.gettimeout() is None)
def test_ftp_default_timeout(self): def test_ftp_default_timeout(self):
...@@ -278,6 +283,7 @@ class TimeoutTest(unittest.TestCase): ...@@ -278,6 +283,7 @@ class TimeoutTest(unittest.TestCase):
socket.setdefaulttimeout(60) socket.setdefaulttimeout(60)
try: try:
u = _urlopen_with_retry(self.FTP_HOST) u = _urlopen_with_retry(self.FTP_HOST)
self.addCleanup(u.close)
finally: finally:
socket.setdefaulttimeout(None) socket.setdefaulttimeout(None)
self.assertEqual(u.fp.fp.raw._sock.gettimeout(), 60) self.assertEqual(u.fp.fp.raw._sock.gettimeout(), 60)
...@@ -288,6 +294,7 @@ class TimeoutTest(unittest.TestCase): ...@@ -288,6 +294,7 @@ class TimeoutTest(unittest.TestCase):
socket.setdefaulttimeout(60) socket.setdefaulttimeout(60)
try: try:
u = _urlopen_with_retry(self.FTP_HOST, timeout=None) u = _urlopen_with_retry(self.FTP_HOST, timeout=None)
self.addCleanup(u.close)
finally: finally:
socket.setdefaulttimeout(None) socket.setdefaulttimeout(None)
self.assertTrue(u.fp.fp.raw._sock.gettimeout() is None) self.assertTrue(u.fp.fp.raw._sock.gettimeout() is None)
...@@ -295,6 +302,7 @@ class TimeoutTest(unittest.TestCase): ...@@ -295,6 +302,7 @@ class TimeoutTest(unittest.TestCase):
def test_ftp_timeout(self): def test_ftp_timeout(self):
with support.transient_internet(self.FTP_HOST): with support.transient_internet(self.FTP_HOST):
u = _urlopen_with_retry(self.FTP_HOST, timeout=60) u = _urlopen_with_retry(self.FTP_HOST, timeout=60)
self.addCleanup(u.close)
self.assertEqual(u.fp.fp.raw._sock.gettimeout(), 60) self.assertEqual(u.fp.fp.raw._sock.gettimeout(), 60)
......
...@@ -1146,6 +1146,8 @@ class AbstractHTTPHandler(BaseHandler): ...@@ -1146,6 +1146,8 @@ class AbstractHTTPHandler(BaseHandler):
r = h.getresponse() # an HTTPResponse instance r = h.getresponse() # an HTTPResponse instance
except socket.error as err: except socket.error as err:
raise URLError(err) raise URLError(err)
finally:
h.close()
r.url = req.get_full_url() r.url = req.get_full_url()
# This line replaces the .msg attribute of the HTTPResponse # This line replaces the .msg attribute of the HTTPResponse
......
...@@ -916,7 +916,7 @@ LIBSUBDIRS= tkinter tkinter/test tkinter/test/test_tkinter \ ...@@ -916,7 +916,7 @@ LIBSUBDIRS= tkinter tkinter/test tkinter/test/test_tkinter \
test/subprocessdata \ test/subprocessdata \
test/tracedmodules test/encoded_modules \ test/tracedmodules test/encoded_modules \
collections concurrent concurrent/futures encodings \ collections concurrent concurrent/futures encodings \
email email/mime email/test email/test/data \ email email/mime test/test_email test/test_email/data \
html json test/json_tests http dbm xmlrpc \ html json test/json_tests http dbm xmlrpc \
sqlite3 sqlite3/test \ sqlite3 sqlite3/test \
logging csv wsgiref urllib \ logging csv wsgiref urllib \
......
...@@ -193,6 +193,10 @@ Core and Builtins ...@@ -193,6 +193,10 @@ Core and Builtins
Library Library
------- -------
- Issue #12133: AbstractHTTPHandler.do_open() of urllib.request closes the HTTP
connection if its getresponse() method fails with a socket error. Patch
written by Ezio Melotti.
- Issue #12240: Allow multiple setup hooks in packaging's setup.cfg files. - Issue #12240: Allow multiple setup hooks in packaging's setup.cfg files.
Original patch by Erik Bray. Original patch by Erik Bray.
......
...@@ -1162,11 +1162,11 @@ static int ...@@ -1162,11 +1162,11 @@ static int
win32_xstat_impl(const char *path, struct win32_stat *result, win32_xstat_impl(const char *path, struct win32_stat *result,
BOOL traverse) BOOL traverse)
{ {
int code; int code;
HANDLE hFile, hFile2; HANDLE hFile, hFile2;
BY_HANDLE_FILE_INFORMATION info; BY_HANDLE_FILE_INFORMATION info;
ULONG reparse_tag = 0; ULONG reparse_tag = 0;
wchar_t *target_path; wchar_t *target_path;
const char *dot; const char *dot;
if(!check_GetFinalPathNameByHandle()) { if(!check_GetFinalPathNameByHandle()) {
...@@ -1262,7 +1262,7 @@ win32_xstat_impl_w(const wchar_t *path, struct win32_stat *result, ...@@ -1262,7 +1262,7 @@ win32_xstat_impl_w(const wchar_t *path, struct win32_stat *result,
HANDLE hFile, hFile2; HANDLE hFile, hFile2;
BY_HANDLE_FILE_INFORMATION info; BY_HANDLE_FILE_INFORMATION info;
ULONG reparse_tag = 0; ULONG reparse_tag = 0;
wchar_t *target_path; wchar_t *target_path;
const wchar_t *dot; const wchar_t *dot;
if(!check_GetFinalPathNameByHandle()) { if(!check_GetFinalPathNameByHandle()) {
...@@ -1281,7 +1281,7 @@ win32_xstat_impl_w(const wchar_t *path, struct win32_stat *result, ...@@ -1281,7 +1281,7 @@ win32_xstat_impl_w(const wchar_t *path, struct win32_stat *result,
/* FILE_FLAG_OPEN_REPARSE_POINT does not follow the symlink. /* FILE_FLAG_OPEN_REPARSE_POINT does not follow the symlink.
Because of this, calls like GetFinalPathNameByHandle will return Because of this, calls like GetFinalPathNameByHandle will return
the symlink path agin and not the actual final path. */ the symlink path agin and not the actual final path. */
FILE_ATTRIBUTE_NORMAL|FILE_FLAG_BACKUP_SEMANTICS| FILE_ATTRIBUTE_NORMAL|FILE_FLAG_BACKUP_SEMANTICS|
FILE_FLAG_OPEN_REPARSE_POINT, FILE_FLAG_OPEN_REPARSE_POINT,
NULL); NULL);
...@@ -2275,7 +2275,7 @@ posix_fchown(PyObject *self, PyObject *args) ...@@ -2275,7 +2275,7 @@ posix_fchown(PyObject *self, PyObject *args)
int fd; int fd;
long uid, gid; long uid, gid;
int res; int res;
if (!PyArg_ParseTuple(args, "ill:chown", &fd, &uid, &gid)) if (!PyArg_ParseTuple(args, "ill:fchown", &fd, &uid, &gid))
return NULL; return NULL;
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
res = fchown(fd, (uid_t) uid, (gid_t) gid); res = fchown(fd, (uid_t) uid, (gid_t) gid);
...@@ -6076,7 +6076,7 @@ posix_open(PyObject *self, PyObject *args) ...@@ -6076,7 +6076,7 @@ posix_open(PyObject *self, PyObject *args)
#ifdef MS_WINDOWS #ifdef MS_WINDOWS
PyUnicodeObject *po; PyUnicodeObject *po;
if (PyArg_ParseTuple(args, "Ui|i:mkdir", &po, &flag, &mode)) { if (PyArg_ParseTuple(args, "Ui|i:open", &po, &flag, &mode)) {
Py_BEGIN_ALLOW_THREADS Py_BEGIN_ALLOW_THREADS
/* PyUnicode_AS_UNICODE OK without thread /* PyUnicode_AS_UNICODE OK without thread
lock as it is a simple dereference. */ lock as it is a simple dereference. */
...@@ -6091,7 +6091,7 @@ posix_open(PyObject *self, PyObject *args) ...@@ -6091,7 +6091,7 @@ posix_open(PyObject *self, PyObject *args)
PyErr_Clear(); PyErr_Clear();
#endif #endif
if (!PyArg_ParseTuple(args, "O&i|i", if (!PyArg_ParseTuple(args, "O&i|i:open",
PyUnicode_FSConverter, &ofile, PyUnicode_FSConverter, &ofile,
&flag, &mode)) &flag, &mode))
return NULL; return NULL;
...@@ -8982,12 +8982,12 @@ posix_futimesat(PyObject *self, PyObject *args) ...@@ -8982,12 +8982,12 @@ posix_futimesat(PyObject *self, PyObject *args)
} }
else { else {
if (extract_time(PyTuple_GET_ITEM(arg, 0), if (extract_time(PyTuple_GET_ITEM(arg, 0),
&(buf[0].tv_sec), &(buf[0].tv_usec)) == -1) { &(buf[0].tv_sec), &(buf[0].tv_usec)) == -1) {
Py_DECREF(opath); Py_DECREF(opath);
return NULL; return NULL;
} }
if (extract_time(PyTuple_GET_ITEM(arg, 1), if (extract_time(PyTuple_GET_ITEM(arg, 1),
&(buf[1].tv_sec), &(buf[1].tv_usec)) == -1) { &(buf[1].tv_sec), &(buf[1].tv_usec)) == -1) {
Py_DECREF(opath); Py_DECREF(opath);
return NULL; return NULL;
} }
......
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