Creates and returns a SAX parser. Creates the first parser it is able to instantiate of the ones 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 fu
(parser_list=())
| 64 | |
| 65 | |
| 66 | def make_parser(parser_list=()): |
| 67 | """Creates and returns a SAX parser. |
| 68 | |
| 69 | Creates the first parser it is able to instantiate of the ones |
| 70 | given in the iterable created by chaining parser_list and |
| 71 | default_parser_list. The iterables must contain the names of Python |
| 72 | modules containing both a SAX parser and a create_parser function.""" |
| 73 | |
| 74 | for parser_name in list(parser_list) + default_parser_list: |
| 75 | try: |
| 76 | return _create_parser(parser_name) |
| 77 | except ImportError: |
| 78 | import sys |
| 79 | if parser_name in sys.modules: |
| 80 | # The parser module was found, but importing it |
| 81 | # failed unexpectedly, pass this exception through |
| 82 | raise |
| 83 | except SAXReaderNotAvailable: |
| 84 | # The parser module detected that it won't work properly, |
| 85 | # so try the next one |
| 86 | pass |
| 87 | |
| 88 | raise SAXReaderNotAvailable("No parsers found", None) |
| 89 | |
| 90 | # --- Internal utility methods used by make_parser |
| 91 |
searching dependent graphs…