<s> import lxml . html <EOL> from brownant . pipeline . base import PipelineProperty <EOL> class ElementTreeProperty ( PipelineProperty ) : <EOL> """<STR_LIT>""" <EOL> def prepare ( self ) : <EOL> self . attr_names . setdefault ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . options . setdefault ( "<STR_LIT>" , None ) <EOL> def provide_value ( self , obj ) : <EOL> text_response = self . get_attr ( obj , "<STR_LIT>" ) <EOL> if self . options [ "<STR_LIT>" ] : <EOL> text_response = text_response . encode ( self . options [ "<STR_LIT>" ] ) <EOL> return lxml . html . fromstring ( text_response ) <EOL> class XPathTextProperty ( PipelineProperty ) : <EOL> """<STR_LIT>""" <EOL> required_attrs = { "<STR_LIT>" } <EOL> def prepare ( self ) : <EOL> self . attr_names . setdefault ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . options . setdefault ( "<STR_LIT>" , False ) <EOL> self . options . setdefault ( "<STR_LIT>" , "<STR_LIT>" ) <EOL> self . options . setdefault ( "<STR_LIT>" , "<STR_LIT:U+0020>" ) <EOL> def choice_pick_impl ( self ) : <EOL> pick_mode = self . options [ "<STR_LIT>" ] <EOL> impl = { <EOL> "<STR_LIT>" : self . pick_joining , <EOL> "<STR_LIT>" : self . pick_first , <EOL> "<STR_LIT>" : self . keep_value , <EOL> } . get ( pick_mode ) <EOL> if not impl : <EOL> raise ValueError ( "<STR_LIT>" % pick_mode ) <EOL> return impl <EOL> def pick_joining ( self , value ) : <EOL> joiner = self . options [ "<STR_LIT>" ] <EOL> return joiner . join ( value ) <EOL> def pick_first ( self , value ) : <EOL> return value [ <NUM_LIT:0> ] if value else "<STR_LIT>" <EOL> def keep_value ( self , value ) : <EOL> return value <EOL> def provide_value ( self , obj ) : <EOL> etree = self . get_attr ( obj , "<STR_LIT>" ) <EOL> value = etree . xpath ( self . xpath ) <EOL> pick_value = self . choice_pick_impl ( ) <EOL> if self . options [ "<STR_LIT>" ] : <EOL> value = [ v . strip ( ) for v in value if v . strip ( ) ] <EOL> return pick_value ( value ) </s>
