From eadfa63bfbe28990077b9f6a9468338429bf2876 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Delfino?= Date: Tue, 25 Sep 2018 15:39:03 -0300 Subject: [PATCH 1/9] bpo-34789: make xml.sax.make_parser accept iterables --- Lib/test/test_sax.py | 6 ++++++ Lib/xml/sax/__init__.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py index 3044960a0ed165..ec3011fba2cb69 100644 --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -254,6 +254,12 @@ def test_make_parser2(self): from xml.sax import make_parser p = make_parser() + def test_make_parser3(self): + # Testing that make_parser can handle iterables other than a + # list + make_parser(('module', )) + make_parser({'module'}) + make_parser({'module': None}) # =========================================================================== # diff --git a/Lib/xml/sax/__init__.py b/Lib/xml/sax/__init__.py index 13f6cf58d0d2f2..364a1c674ca52e 100644 --- a/Lib/xml/sax/__init__.py +++ b/Lib/xml/sax/__init__.py @@ -75,7 +75,7 @@ def make_parser(parser_list = []): default_parser_list. The lists must contain the names of Python modules containing both a SAX parser and a create_parser function.""" - for parser_name in parser_list + default_parser_list: + for parser_name in list(parser_list) + default_parser_list: try: return _create_parser(parser_name) except ImportError as e: From e7c39dd27604f13f67b957b013871b003aa53057 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Delfino?= Date: Tue, 25 Sep 2018 15:40:22 -0300 Subject: [PATCH 2/9] Add period --- Lib/test/test_sax.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py index ec3011fba2cb69..a836c18a8a418e 100644 --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -256,7 +256,7 @@ def test_make_parser2(self): def test_make_parser3(self): # Testing that make_parser can handle iterables other than a - # list + # list. make_parser(('module', )) make_parser({'module'}) make_parser({'module': None}) From ac3325f33a2cfbb6de381b0af73f723f4bf075ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Delfino?= Date: Tue, 25 Sep 2018 15:44:08 -0300 Subject: [PATCH 3/9] Add documentation update --- Doc/library/xml.sax.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Doc/library/xml.sax.rst b/Doc/library/xml.sax.rst index aa3ea9bfc55a98..0b6973b8c8a8b3 100644 --- a/Doc/library/xml.sax.rst +++ b/Doc/library/xml.sax.rst @@ -40,10 +40,13 @@ The convenience functions are: Create and return a SAX :class:`~xml.sax.xmlreader.XMLReader` object. The first parser found will - be used. If *parser_list* is provided, it must be a sequence of strings which + be used. If *parser_list* is provided, it must be an iterable of strings which name modules that have a function named :func:`create_parser`. Modules listed in *parser_list* will be used before modules in the default list of parsers. + .. versionchanged:: 3.8 + The *parser_list* argument can be any iterable, not just a list. + .. function:: parse(filename_or_stream, handler, error_handler=handler.ErrorHandler()) From ba02222ae4516870838f270026cdd0626951a23a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Delfino?= Date: Tue, 25 Sep 2018 15:48:56 -0300 Subject: [PATCH 4/9] Add blurb entry --- .../next/Library/2018-09-25-15-48-50.bpo-34789.rPOEj5.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2018-09-25-15-48-50.bpo-34789.rPOEj5.rst diff --git a/Misc/NEWS.d/next/Library/2018-09-25-15-48-50.bpo-34789.rPOEj5.rst b/Misc/NEWS.d/next/Library/2018-09-25-15-48-50.bpo-34789.rPOEj5.rst new file mode 100644 index 00000000000000..56fbe5febc3374 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-09-25-15-48-50.bpo-34789.rPOEj5.rst @@ -0,0 +1,2 @@ +Make :func:`xml.sax.make_parser` take any iterable as its parser_list +argument. From bf2310cad5e40dae72dd3ae17b7c670ce3670865 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Delfino?= Date: Tue, 25 Sep 2018 15:52:28 -0300 Subject: [PATCH 5/9] Update 2018-09-25-15-48-50.bpo-34789.rPOEj5.rst --- .../next/Library/2018-09-25-15-48-50.bpo-34789.rPOEj5.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2018-09-25-15-48-50.bpo-34789.rPOEj5.rst b/Misc/NEWS.d/next/Library/2018-09-25-15-48-50.bpo-34789.rPOEj5.rst index 56fbe5febc3374..94c868759a3ad9 100644 --- a/Misc/NEWS.d/next/Library/2018-09-25-15-48-50.bpo-34789.rPOEj5.rst +++ b/Misc/NEWS.d/next/Library/2018-09-25-15-48-50.bpo-34789.rPOEj5.rst @@ -1,2 +1,2 @@ -Make :func:`xml.sax.make_parser` take any iterable as its parser_list +Make :func:`xml.sax.make_parser` take any iterable as its *parser_list* argument. From b4cf5bb603e3143db39d1d6f1798bd55f9b911f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Delfino?= Date: Fri, 26 Oct 2018 10:42:24 -0300 Subject: [PATCH 6/9] Address Tal'comments and update docstring --- Lib/test/test_sax.py | 21 +++++++++++++++++++++ Lib/xml/sax/__init__.py | 6 +++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py index a836c18a8a418e..550ada88e54353 100644 --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -259,7 +259,28 @@ def test_make_parser3(self): # list. make_parser(('module', )) make_parser({'module'}) + make_parser(frozenset({'module'})) make_parser({'module': None}) + make_parser(iter(['module'])) + + def test_make_parser4(self): + # Testing that make_parser can handle empty iterables. + make_parser([]) + make_parser(tuple()) + make_parser(set()) + make_parser(frozenset()) + make_parser({}) + make_parser(iter([])) + + def test_make_parser5(self): + # Testing that make_parser can handle iterables with more than + # one item. + make_parser(['module1', 'module2']) + make_parser(('module1', 'module2')) + make_parser({'module1', 'module2'}) + make_parser(frozenset({'module1', 'module2'})) + make_parser({'module1': None, 'module2': None}) + make_parser(iter(['module1', 'module2'])) # =========================================================================== # diff --git a/Lib/xml/sax/__init__.py b/Lib/xml/sax/__init__.py index 364a1c674ca52e..8221afd6e47e94 100644 --- a/Lib/xml/sax/__init__.py +++ b/Lib/xml/sax/__init__.py @@ -67,12 +67,12 @@ def parseString(string, handler, errorHandler=ErrorHandler()): default_parser_list = sys.registry.getProperty(_key).split(",") -def make_parser(parser_list = []): +def make_parser(parser_list=tuple()): """Creates and returns a SAX parser. Creates the first parser it is able to instantiate of the ones - given in the list created by doing parser_list + - default_parser_list. The lists must contain the names of Python + given in the iterable created by chaining parser_list and + default_parser_list. The iterables must contain the names of Python modules containing both a SAX parser and a create_parser function.""" for parser_name in list(parser_list) + default_parser_list: From f7cfa4ba2c824338661c05c6f8a53aca7df48c58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Delfino?= Date: Fri, 26 Oct 2018 10:47:15 -0300 Subject: [PATCH 7/9] Update 2018-09-25-15-48-50.bpo-34789.rPOEj5.rst --- .../next/Library/2018-09-25-15-48-50.bpo-34789.rPOEj5.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2018-09-25-15-48-50.bpo-34789.rPOEj5.rst b/Misc/NEWS.d/next/Library/2018-09-25-15-48-50.bpo-34789.rPOEj5.rst index 94c868759a3ad9..46acf784c41829 100644 --- a/Misc/NEWS.d/next/Library/2018-09-25-15-48-50.bpo-34789.rPOEj5.rst +++ b/Misc/NEWS.d/next/Library/2018-09-25-15-48-50.bpo-34789.rPOEj5.rst @@ -1,2 +1,2 @@ -Make :func:`xml.sax.make_parser` take any iterable as its *parser_list* +:func:`xml.sax.make_parser` now accepts any iterable as its *parser_list* argument. From ea2e8d95d181f897ccb36c5249232e0143d58ab5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Delfino?= Date: Fri, 26 Oct 2018 11:28:54 -0300 Subject: [PATCH 8/9] Address more comments from Tal --- Lib/test/test_sax.py | 5 +++-- Lib/xml/sax/__init__.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py index 550ada88e54353..894d86ac71f03c 100644 --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -255,8 +255,9 @@ def test_make_parser2(self): p = make_parser() def test_make_parser3(self): - # Testing that make_parser can handle iterables other than a - # list. + # Testing that make_parser can handle different types of + # iterables. + make_parser(['module']) make_parser(('module', )) make_parser({'module'}) make_parser(frozenset({'module'})) diff --git a/Lib/xml/sax/__init__.py b/Lib/xml/sax/__init__.py index 8221afd6e47e94..a0f5d40b2000ce 100644 --- a/Lib/xml/sax/__init__.py +++ b/Lib/xml/sax/__init__.py @@ -67,7 +67,7 @@ def parseString(string, handler, errorHandler=ErrorHandler()): default_parser_list = sys.registry.getProperty(_key).split(",") -def make_parser(parser_list=tuple()): +def make_parser(parser_list=()): """Creates and returns a SAX parser. Creates the first parser it is able to instantiate of the ones From 6c505ae7e09a61cb8094cef0b00b34e81fe4db89 Mon Sep 17 00:00:00 2001 From: Tal Einat Date: Fri, 26 Oct 2018 17:39:07 +0300 Subject: [PATCH 9/9] add contributor name to NEWS entry --- .../next/Library/2018-09-25-15-48-50.bpo-34789.rPOEj5.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2018-09-25-15-48-50.bpo-34789.rPOEj5.rst b/Misc/NEWS.d/next/Library/2018-09-25-15-48-50.bpo-34789.rPOEj5.rst index 46acf784c41829..28f15c3f41225f 100644 --- a/Misc/NEWS.d/next/Library/2018-09-25-15-48-50.bpo-34789.rPOEj5.rst +++ b/Misc/NEWS.d/next/Library/2018-09-25-15-48-50.bpo-34789.rPOEj5.rst @@ -1,2 +1,2 @@ :func:`xml.sax.make_parser` now accepts any iterable as its *parser_list* -argument. +argument. Patch by Andrés Delfino.