<s> """<STR_LIT>""" <EOL> import weakref <EOL> from lxml import etree <EOL> from ants . utils . trackref import object_ref <EOL> def _factory ( response , parser_cls ) : <EOL> url = response . url <EOL> body = response . body_as_unicode ( ) . strip ( ) . encode ( '<STR_LIT:utf8>' ) or '<STR_LIT>' <EOL> parser = parser_cls ( recover = True , encoding = '<STR_LIT:utf8>' ) <EOL> return etree . fromstring ( body , parser = parser , base_url = url ) <EOL> class LxmlDocument ( object_ref ) : <EOL> cache = weakref . WeakKeyDictionary ( ) <EOL> __slots__ = [ '<STR_LIT>' ] <EOL> def __new__ ( cls , response , parser = etree . HTMLParser ) : <EOL> cache = cls . cache . setdefault ( response , { } ) <EOL> if parser not in cache : <EOL> obj = object_ref . __new__ ( cls ) <EOL> cache [ parser ] = _factory ( response , parser ) <EOL> return cache [ parser ] <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % self . root . tag </s>
