From ed270fab649c8b2a454c3aaa0c3702d50b9ff127 Mon Sep 17 00:00:00 2001 From: Senthil Kumaran Date: Mon, 18 Jul 2011 06:42:46 +0800 Subject: Fix closes Issue12479 - Add HTTPErrorProcessor class definition - Patch by Sandro Tosi --- Doc/library/urllib.request.rst | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Doc/library/urllib.request.rst b/Doc/library/urllib.request.rst index 2cd0620..65e94fb 100644 --- a/Doc/library/urllib.request.rst +++ b/Doc/library/urllib.request.rst @@ -313,6 +313,11 @@ The following classes are provided: A catch-all class to handle unknown URLs. +.. class:: HTTPErrorProcessor() + + Process HTTP error responses. + + .. _request-objects: Request Objects -- cgit v0.12 From 0215d09ca927096325ec470074b1dc608b9083ba Mon Sep 17 00:00:00 2001 From: Senthil Kumaran Date: Mon, 18 Jul 2011 07:12:40 +0800 Subject: Fix closes Issue12478 - HTTPErrorProcess 's methods are http_response and https_response. --- Doc/library/urllib.request.rst | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Doc/library/urllib.request.rst b/Doc/library/urllib.request.rst index 65e94fb..acb6888 100644 --- a/Doc/library/urllib.request.rst +++ b/Doc/library/urllib.request.rst @@ -921,7 +921,7 @@ UnknownHandler Objects HTTPErrorProcessor Objects -------------------------- -.. method:: HTTPErrorProcessor.unknown_open() +.. method:: HTTPErrorProcessor.http_response() Process HTTP error responses. @@ -933,6 +933,13 @@ HTTPErrorProcessor Objects :exc:`HTTPError` if no other handler handles the error. +.. method:: HTTPErrorProcessor.https_response() + + Process HTTPS error responses. + + The behavior is same as :meth:`http_response`. + + .. _urllib-request-examples: Examples -- cgit v0.12 From 3e7f33fc82136f1620ad48df6068d3ac17ba8b44 Mon Sep 17 00:00:00 2001 From: Senthil Kumaran Date: Mon, 18 Jul 2011 07:17:20 +0800 Subject: fix whitespace nit. --- Doc/library/urllib.request.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/urllib.request.rst b/Doc/library/urllib.request.rst index acb6888..7dfdf3e 100644 --- a/Doc/library/urllib.request.rst +++ b/Doc/library/urllib.request.rst @@ -935,8 +935,8 @@ HTTPErrorProcessor Objects .. method:: HTTPErrorProcessor.https_response() - Process HTTPS error responses. - + Process HTTPS error responses. + The behavior is same as :meth:`http_response`. -- cgit v0.12 From e151d21883ae2e5c7b17be883a3be298041da7ad Mon Sep 17 00:00:00 2001 From: Alex Gaynor Date: Sun, 17 Jul 2011 16:21:30 -0700 Subject: Mark itertools tests of tuple reuse as being specific to CPython. --- Lib/test/test_itertools.py | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/Lib/test/test_itertools.py b/Lib/test/test_itertools.py index f4928ca..957991c 100644 --- a/Lib/test/test_itertools.py +++ b/Lib/test/test_itertools.py @@ -168,7 +168,8 @@ class TestBasicOps(unittest.TestCase): self.assertEqual(result, list(combinations2(values, r))) # matches second pure python version self.assertEqual(result, list(combinations3(values, r))) # matches second pure python version - # Test implementation detail: tuple re-use + @support.impl_detail("tuple reuse is specific to CPython") + def test_combinations_tuple_reuse(self): self.assertEqual(len(set(map(id, combinations('abcde', 3)))), 1) self.assertNotEqual(len(set(map(id, list(combinations('abcde', 3))))), 1) @@ -238,7 +239,9 @@ class TestBasicOps(unittest.TestCase): self.assertEqual(result, list(cwr1(values, r))) # matches first pure python version self.assertEqual(result, list(cwr2(values, r))) # matches second pure python version - # Test implementation detail: tuple re-use + @support.impl_detail("tuple reuse is specific to CPython") + def test_combinations_with_replacement_tuple_reuse(self): + cwr = combinations_with_replacement self.assertEqual(len(set(map(id, cwr('abcde', 3)))), 1) self.assertNotEqual(len(set(map(id, list(cwr('abcde', 3))))), 1) @@ -302,7 +305,8 @@ class TestBasicOps(unittest.TestCase): self.assertEqual(result, list(permutations(values, None))) # test r as None self.assertEqual(result, list(permutations(values))) # test default r - # Test implementation detail: tuple re-use + @support.impl_detail("tuple resuse is CPython specific") + def test_permutations_tuple_reuse(self): self.assertEqual(len(set(map(id, permutations('abcde', 3)))), 1) self.assertNotEqual(len(set(map(id, list(permutations('abcde', 3))))), 1) @@ -566,11 +570,13 @@ class TestBasicOps(unittest.TestCase): self.assertEqual(list(zip()), lzip()) self.assertRaises(TypeError, zip, 3) self.assertRaises(TypeError, zip, range(3), 3) - # Check tuple re-use (implementation detail) self.assertEqual([tuple(list(pair)) for pair in zip('abc', 'def')], lzip('abc', 'def')) self.assertEqual([pair for pair in zip('abc', 'def')], lzip('abc', 'def')) + + @support.impl_detail("tuple reuse is specific to CPython") + def test_zip_tuple_reuse(self): ids = list(map(id, zip('abc', 'def'))) self.assertEqual(min(ids), max(ids)) ids = list(map(id, list(zip('abc', 'def')))) @@ -613,11 +619,13 @@ class TestBasicOps(unittest.TestCase): else: self.fail('Did not raise Type in: ' + stmt) - # Check tuple re-use (implementation detail) self.assertEqual([tuple(list(pair)) for pair in zip_longest('abc', 'def')], list(zip('abc', 'def'))) self.assertEqual([pair for pair in zip_longest('abc', 'def')], list(zip('abc', 'def'))) + + @support.impl_detail("tuple reuse is specific to CPython") + def test_zip_longest_tuple_reuse(self): ids = list(map(id, zip_longest('abc', 'def'))) self.assertEqual(min(ids), max(ids)) ids = list(map(id, list(zip_longest('abc', 'def')))) @@ -721,7 +729,8 @@ class TestBasicOps(unittest.TestCase): args = map(iter, args) self.assertEqual(len(list(product(*args))), expected_len) - # Test implementation detail: tuple re-use + @support.impl_detail("tuple reuse is specific to CPython") + def test_product_tuple_reuse(self): self.assertEqual(len(set(map(id, product('abc', 'def')))), 1) self.assertNotEqual(len(set(map(id, list(product('abc', 'def'))))), 1) -- cgit v0.12 From 52a7d982736fd4111b7937c4e575adb1a39f8afa Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Sun, 17 Jul 2011 19:17:55 -0700 Subject: Make warnings accept a callable for showwarnings instead of restricting itself to just functions and methods (which allows built-in functions to be used, etc.). Closes issue #10271. Thanks to lekma for the bug report. --- Lib/test/test_warnings.py | 14 ++++++++------ Python/_warnings.c | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Lib/test/test_warnings.py b/Lib/test/test_warnings.py index 79be835..953b282 100644 --- a/Lib/test/test_warnings.py +++ b/Lib/test/test_warnings.py @@ -512,12 +512,11 @@ class _WarningsTests(BaseTest): def test_showwarning_not_callable(self): with original_warnings.catch_warnings(module=self.module): self.module.filterwarnings("always", category=UserWarning) - old_showwarning = self.module.showwarning + self.module.showwarning = print + with support.captured_output('stdout'): + self.module.warn('Warning!') self.module.showwarning = 23 - try: - self.assertRaises(TypeError, self.module.warn, "Warning!") - finally: - self.module.showwarning = old_showwarning + self.assertRaises(TypeError, self.module.warn, "Warning!") def test_show_warning_output(self): # With showarning() missing, make sure that output is okay. @@ -547,10 +546,13 @@ class _WarningsTests(BaseTest): globals_dict = globals() oldfile = globals_dict['__file__'] try: - with original_warnings.catch_warnings(module=self.module) as w: + catch = original_warnings.catch_warnings(record=True, + module=self.module) + with catch as w: self.module.filterwarnings("always", category=UserWarning) globals_dict['__file__'] = None original_warnings.warn('test', UserWarning) + self.assertTrue(len(w)) finally: globals_dict['__file__'] = oldfile diff --git a/Python/_warnings.c b/Python/_warnings.c index 615a2d3..f8a7175 100644 --- a/Python/_warnings.c +++ b/Python/_warnings.c @@ -409,10 +409,10 @@ warn_explicit(PyObject *category, PyObject *message, else { PyObject *res; - if (!PyMethod_Check(show_fxn) && !PyFunction_Check(show_fxn)) { + if (!PyCallable_Check(show_fxn)) { PyErr_SetString(PyExc_TypeError, "warnings.showwarning() must be set to a " - "function or method"); + "callable"); Py_DECREF(show_fxn); goto cleanup; } -- cgit v0.12 From e52181c05af4b5cbe6951dce8440ed4d76f11726 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Sun, 17 Jul 2011 19:25:50 -0700 Subject: Add Misc/NEWS entry and relevant doc change for issue 10271. --- Doc/library/warnings.rst | 3 +-- Misc/NEWS | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Doc/library/warnings.rst b/Doc/library/warnings.rst index 8af19a2..8387f5a 100644 --- a/Doc/library/warnings.rst +++ b/Doc/library/warnings.rst @@ -339,8 +339,7 @@ Available Functions Write a warning to a file. The default implementation calls ``formatwarning(message, category, filename, lineno, line)`` and writes the resulting string to *file*, which defaults to ``sys.stderr``. You may replace - this function with an alternative implementation by assigning to - ``warnings.showwarning``. + this function with any callable by assigning to ``warnings.showwarning``. *line* is a line of source code to be included in the warning message; if *line* is not supplied, :func:`showwarning` will try to read the line specified by *filename* and *lineno*. diff --git a/Misc/NEWS b/Misc/NEWS index 3301d3f..a456bf3 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,6 +10,8 @@ What's New in Python 3.3 Alpha 1? Core and Builtins ----------------- +- Issue #10271: Allow warnings.showwarning() be any callable. + - Issue #11627: Fix segfault when __new__ on a exception returns a non-exception class. -- cgit v0.12