<s> from importlib import import_module <EOL> from django . utils import six <EOL> from django . utils . functional import LazyObject <EOL> from compressor . parser . base import ParserBase <EOL> from compressor . parser . lxml import LxmlParser <EOL> from compressor . parser . default_htmlparser import DefaultHtmlParser as HtmlParser <EOL> from compressor . parser . beautifulsoup import BeautifulSoupParser <EOL> from compressor . parser . html5lib import Html5LibParser <EOL> class AutoSelectParser ( LazyObject ) : <EOL> options = ( <EOL> ( six . moves . html_parser . __name__ , HtmlParser ) , <EOL> ( '<STR_LIT>' , LxmlParser ) , <EOL> ) <EOL> def __init__ ( self , content ) : <EOL> self . _wrapped = None <EOL> self . _setup ( content ) <EOL> def __getattr__ ( self , name ) : <EOL> return getattr ( self . _wrapped , name ) <EOL> def _setup ( self , content ) : <EOL> for dependency , parser in self . options : <EOL> try : <EOL> import_module ( dependency ) <EOL> self . _wrapped = parser ( content ) <EOL> break <EOL> except ( ImportError , TypeError ) : <EOL> continue </s>
