diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_sax.py | 28 | ||||
-rw-r--r-- | Lib/xml/sax/__init__.py | 8 |
2 files changed, 32 insertions, 4 deletions
diff --git a/Lib/test/test_sax.py b/Lib/test/test_sax.py index 3044960a0e..894d86ac71 100644 --- a/Lib/test/test_sax.py +++ b/Lib/test/test_sax.py @@ -254,6 +254,34 @@ class MakeParserTest(unittest.TestCase): from xml.sax import make_parser p = make_parser() + def test_make_parser3(self): + # Testing that make_parser can handle different types of + # iterables. + make_parser(['module']) + 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 13f6cf58d0..a0f5d40b20 100644 --- a/Lib/xml/sax/__init__.py +++ b/Lib/xml/sax/__init__.py @@ -67,15 +67,15 @@ if sys.platform[:4] == "java" and sys.registry.containsKey(_key): default_parser_list = sys.registry.getProperty(_key).split(",") -def make_parser(parser_list = []): +def make_parser(parser_list=()): """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 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: |