Instantiate parsers only once #153
                
     Open
            
            
          
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Changes:
A new module,
parsel.parser, hosts two new classes:HTMLParserandXMLParser. These classes have a single, common method,parse. They are wrappers for the correspondinglxmlparsers.Two new constants have been created:
parsel.parser.html.HTML_PARSERandparsel.parser.xml.XML_PARSER, which are instances of those classes. They exist in separate modules so that they are only loaded on demand, lazily, and only instantiated once._ctgroup[*]['_parser']is now a string with the import path of one of those constants, which theSelectorconstructor loads. As a result, when you create multipleSelectorobjects from text, a new parser is no longer created each time; the same parser is reused instead.parsel.selector.create_root_nodeandparsel.selector.SafeXMLParserare now deprecated.Now that parser constructor parameters are defined on the new wrapping classes (
parsel.parser.HTMLParserandparsel.parser.XMLParser), it’s easier to implement new wrappers for parsers that do not support the same constructor parameters (recover,encoding), such as an HTML5 parser.