<s> from __future__ import print_function , division , unicode_literals <EOL> from abc import ABCMeta , abstractproperty , abstractmethod <EOL> from collections import namedtuple <EOL> from distutils . version import LooseVersion <EOL> from functools import wraps <EOL> from itertools import takewhile , dropwhile <EOL> import operator <EOL> import re <EOL> import sys <EOL> try : <EOL> from bs4 import BeautifulSoup , PageElement , NavigableString <EOL> except ImportError : <EOL> raise ImportError ( "<STR_LIT>" ) <EOL> try : <EOL> import six <EOL> from six . moves import map <EOL> assert LooseVersion ( six . __version__ ) >= LooseVersion ( '<STR_LIT>' ) <EOL> except ( ImportError , AssertionError ) : <EOL> raise ImportError ( "<STR_LIT>" ) <EOL> __version__ = '<STR_LIT>' <EOL> __all__ = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> QUOTED_STR = re . compile ( "<STR_LIT>" ) <EOL> QDebug = namedtuple ( '<STR_LIT>' , ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> """<STR_LIT>""" <EOL> @ six . add_metaclass ( ABCMeta ) <EOL> class Wrapper ( object ) : <EOL> @ abstractmethod <EOL> def val ( self ) : <EOL> pass <EOL> @ abstractmethod <EOL> def orelse ( self , value ) : <EOL> pass <EOL> def nonnull ( self ) : <EOL> """<STR_LIT>""" <EOL> return self <EOL> @ abstractmethod <EOL> def isnull ( self ) : <EOL> pass <EOL> @ abstractmethod <EOL> def map ( self , func ) : <EOL> pass <EOL> @ abstractmethod <EOL> def apply ( self , func ) : <EOL> pass <EOL> @ classmethod <EOL> def wrap ( cls , value ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( value , Wrapper ) : <EOL> return value <EOL> if hasattr ( value , '<STR_LIT>' ) : <EOL> return Node ( value ) <EOL> return Scalar ( value ) <EOL> def __getitem__ ( self , key ) : <EOL> return self . map ( operator . itemgetter ( key ) ) <EOL> def dump ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if args and kwargs : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> if args : <EOL> result = tuple ( _unwrap ( self . apply ( func ) ) for func in args ) <EOL> else : <EOL> result = dict ( ( name , _unwrap ( self . apply ( func ) ) ) <EOL> for name , func in kwargs . items ( ) ) <EOL> return Wrapper . wrap ( result ) <EOL> @ abstractmethod <EOL> def require ( self , func , msg = '<STR_LIT>' ) : <EOL> pass <EOL> class NullValueError ( ValueError ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class QKeyError ( KeyError ) : <EOL> """<STR_LIT>""" <EOL> def __str__ ( self ) : <EOL> parts = self . args [ <NUM_LIT:0> ] . split ( '<STR_LIT>' ) <EOL> return parts [ <NUM_LIT:0> ] + '<STR_LIT>' + _dequote ( repr ( parts [ <NUM_LIT:1> ] ) ) <EOL> QKeyError . __name__ = str ( '<STR_LIT>' ) <EOL> @ six . python_2_unicode_compatible <EOL> class BaseNull ( Wrapper ) : <EOL> """<STR_LIT>""" <EOL> def val ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NullValueError ( ) <EOL> def orelse ( self , value ) : <EOL> """<STR_LIT>""" <EOL> return Wrapper . wrap ( value ) <EOL> def map ( self , func ) : <EOL> """<STR_LIT>""" <EOL> return self <EOL> def apply ( self , func ) : <EOL> """<STR_LIT>""" <EOL> return self <EOL> def nonnull ( self ) : <EOL> """<STR_LIT>""" <EOL> raise NullValueError ( ) <EOL> def require ( self , func , msg = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> raise NullValueError ( ) <EOL> def isnull ( self ) : <EOL> """<STR_LIT>""" <EOL> return Scalar ( True ) <EOL> def __setitem__ ( self , key , val ) : <EOL> pass <EOL> def __bool__ ( self ) : <EOL> return False <EOL> __nonzero__ = __bool__ <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % type ( self ) . __name__ <EOL> __repr__ = __str__ <EOL> def __hash__ ( self ) : <EOL> return hash ( type ( self ) ) <EOL> def __eq__ ( self , other ) : <EOL> return type ( self ) ( ) <EOL> def __ne__ ( self , other ) : <EOL> return type ( self ) ( ) <EOL> @ six . python_2_unicode_compatible <EOL> class Some ( Wrapper ) : <EOL> def __init__ ( self , value ) : <EOL> self . _value = value <EOL> def map ( self , func ) : <EOL> """<STR_LIT>""" <EOL> return Wrapper . wrap ( _make_callable ( func ) ( self . _value ) ) <EOL> def apply ( self , func ) : <EOL> """<STR_LIT>""" <EOL> return Wrapper . wrap ( _make_callable ( func ) ( self ) ) <EOL> def orelse ( self , value ) : <EOL> """<STR_LIT>""" <EOL> return self <EOL> def val ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _value <EOL> def require ( self , func , msg = "<STR_LIT>" ) : <EOL> """<STR_LIT>""" <EOL> if self . apply ( func ) : <EOL> return self <EOL> raise NullValueError ( msg ) <EOL> def isnull ( self ) : <EOL> """<STR_LIT>""" <EOL> return Scalar ( False ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( type ( self ) . __name__ , _repr ( self . _value ) ) <EOL> def __repr__ ( self ) : <EOL> return repr ( self . __str__ ( ) ) [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> def __setitem__ ( self , key , val ) : <EOL> return self . map ( Q . __setitem__ ( key , val ) ) <EOL> def __hash__ ( self ) : <EOL> return hash ( self . _value ) <EOL> def __eq__ ( self , other ) : <EOL> return self . map ( lambda x : x == other ) <EOL> def __ne__ ( self , other ) : <EOL> return self . map ( lambda x : x != other ) <EOL> class Null ( BaseNull ) : <EOL> """<STR_LIT>""" <EOL> def __getattr__ ( self , attr ) : <EOL> return Null ( ) <EOL> def __call__ ( self , * args , ** kwargs ) : <EOL> return Null ( ) <EOL> def __gt__ ( self , other ) : <EOL> return Null ( ) <EOL> def __ge__ ( self , other ) : <EOL> return Null ( ) <EOL> def __lt__ ( self , other ) : <EOL> return Null ( ) <EOL> def __le__ ( self , other ) : <EOL> return Null ( ) <EOL> def __len__ ( self ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> def __add__ ( self , other ) : <EOL> return Null ( ) <EOL> def __sub__ ( self , other ) : <EOL> return Null ( ) <EOL> def __mul__ ( self , other ) : <EOL> return Null ( ) <EOL> def __div__ ( self , other ) : <EOL> return Null ( ) <EOL> def __floordiv__ ( self , other ) : <EOL> return Null ( ) <EOL> def __pow__ ( self , other ) : <EOL> return Null ( ) <EOL> def __mod__ ( self , other ) : <EOL> return Null ( ) <EOL> def __truediv__ ( self , other ) : <EOL> return Null ( ) <EOL> def __hash__ ( self ) : <EOL> return super ( Null , self ) . __hash__ ( ) <EOL> class Scalar ( Some ) : <EOL> """<STR_LIT>""" <EOL> def __getattr__ ( self , attr ) : <EOL> return self . map ( operator . attrgetter ( attr ) ) <EOL> def __call__ ( self , * args , ** kwargs ) : <EOL> return self . map ( operator . methodcaller ( '<STR_LIT>' , * args , ** kwargs ) ) <EOL> def __gt__ ( self , other ) : <EOL> return self . map ( lambda x : x > other ) <EOL> def __ge__ ( self , other ) : <EOL> return self . map ( lambda x : x >= other ) <EOL> def __lt__ ( self , other ) : <EOL> return self . map ( lambda x : x < other ) <EOL> def __le__ ( self , other ) : <EOL> return self . map ( lambda x : x <= other ) <EOL> def __bool__ ( self ) : <EOL> return bool ( self . _value ) <EOL> __nonzero__ = __bool__ <EOL> def __len__ ( self ) : <EOL> return len ( self . _value ) <EOL> def __add__ ( self , other ) : <EOL> if isinstance ( other , BaseNull ) : <EOL> return other <EOL> return self . map ( Q + _unwrap ( other ) ) <EOL> def __sub__ ( self , other ) : <EOL> if isinstance ( other , BaseNull ) : <EOL> return other <EOL> return self . map ( Q - _unwrap ( other ) ) <EOL> def __mul__ ( self , other ) : <EOL> if isinstance ( other , BaseNull ) : <EOL> return other <EOL> return self . map ( Q * _unwrap ( other ) ) <EOL> def __div__ ( self , other ) : <EOL> if isinstance ( other , BaseNull ) : <EOL> return other <EOL> return self . map ( Q / _unwrap ( other ) ) <EOL> def __floordiv__ ( self , other ) : <EOL> if isinstance ( other , BaseNull ) : <EOL> return other <EOL> return self . map ( Q // _unwrap ( other ) ) <EOL> def __pow__ ( self , other ) : <EOL> if isinstance ( other , BaseNull ) : <EOL> return other <EOL> return self . map ( Q ** _unwrap ( other ) ) <EOL> def __mod__ ( self , other ) : <EOL> if isinstance ( other , BaseNull ) : <EOL> return other <EOL> return self . map ( Q % _unwrap ( other ) ) <EOL> def __truediv__ ( self , other ) : <EOL> if isinstance ( other , BaseNull ) : <EOL> return other <EOL> return self . map ( Q / _unwrap ( other ) ) <EOL> class Collection ( Some ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , items ) : <EOL> super ( Collection , self ) . __init__ ( list ( items ) ) <EOL> self . _items = self . _value <EOL> self . _assert_items_are_wrappers ( ) <EOL> def _assert_items_are_wrappers ( self ) : <EOL> for item in self : <EOL> if not isinstance ( item , Wrapper ) : <EOL> raise TypeError ( "<STR_LIT>" ) <EOL> def val ( self ) : <EOL> """<STR_LIT>""" <EOL> return list ( self . iter_val ( ) ) <EOL> def first ( self ) : <EOL> """<STR_LIT>""" <EOL> return self [ <NUM_LIT:0> ] <EOL> def iter_val ( self ) : <EOL> """<STR_LIT>""" <EOL> return ( item . val ( ) for item in self . _items ) <EOL> def each ( self , * funcs ) : <EOL> """<STR_LIT>""" <EOL> funcs = list ( map ( _make_callable , funcs ) ) <EOL> if len ( funcs ) == <NUM_LIT:1> : <EOL> return Collection ( map ( funcs [ <NUM_LIT:0> ] , self . _items ) ) <EOL> tupler = lambda item : Scalar ( <EOL> tuple ( _unwrap ( func ( item ) ) for func in funcs ) ) <EOL> return Collection ( map ( tupler , self . _items ) ) <EOL> def exclude ( self , func = None ) : <EOL> """<STR_LIT>""" <EOL> func = _make_callable ( func ) <EOL> inverse = lambda x : not func ( x ) <EOL> return self . filter ( inverse ) <EOL> def filter ( self , func = None ) : <EOL> """<STR_LIT>""" <EOL> func = _make_callable ( func ) <EOL> return Collection ( filter ( func , self . _items ) ) <EOL> def takewhile ( self , func = None ) : <EOL> """<STR_LIT>""" <EOL> func = _make_callable ( func ) <EOL> return Collection ( takewhile ( func , self . _items ) ) <EOL> def dropwhile ( self , func = None ) : <EOL> """<STR_LIT>""" <EOL> func = _make_callable ( func ) <EOL> return Collection ( dropwhile ( func , self . _items ) ) <EOL> def __getitem__ ( self , key ) : <EOL> if isinstance ( key , int ) : <EOL> try : <EOL> return self . _items [ key ] <EOL> except IndexError : <EOL> return NullNode ( ) <EOL> return Collection ( list ( self . _items ) . __getitem__ ( key ) ) <EOL> def dump ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . each ( Q . dump ( * args , ** kwargs ) ) <EOL> def __len__ ( self ) : <EOL> return self . map ( len ) . val ( ) <EOL> def count ( self ) : <EOL> """<STR_LIT>""" <EOL> return Scalar ( len ( self ) ) <EOL> def zip ( self , * others ) : <EOL> """<STR_LIT>""" <EOL> args = [ _unwrap ( item ) for item in ( self , ) + others ] <EOL> ct = self . count ( ) <EOL> if not all ( len ( arg ) == ct for arg in args ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> return Collection ( map ( Wrapper . wrap , zip ( * args ) ) ) <EOL> def dictzip ( self , keys ) : <EOL> """<STR_LIT>""" <EOL> return Scalar ( dict ( zip ( _unwrap ( keys ) , self . val ( ) ) ) ) <EOL> def __iter__ ( self ) : <EOL> for item in self . _items : <EOL> yield item <EOL> def all ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . map ( all ) <EOL> def any ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . map ( any ) <EOL> def none ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . map ( lambda items : not any ( items ) ) <EOL> def __bool__ ( self ) : <EOL> return bool ( self . _items ) <EOL> __nonzero__ = __bool__ <EOL> class NullCollection ( BaseNull , Collection ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self ) : <EOL> pass <EOL> def iter_val ( self ) : <EOL> raise NullValueError ( ) <EOL> def each ( self , func ) : <EOL> return self <EOL> def filter ( self , func = None ) : <EOL> return self <EOL> def takewhile ( self , func = None ) : <EOL> return self <EOL> def dropwhile ( self , func = None ) : <EOL> return self <EOL> def first ( self ) : <EOL> return NullNode ( ) <EOL> def __getitem__ ( self , key ) : <EOL> if isinstance ( key , int ) : <EOL> return NullNode ( ) <EOL> return self <EOL> def dump ( self , * args , ** kwargs ) : <EOL> return NullCollection ( ) <EOL> def count ( self ) : <EOL> return Scalar ( <NUM_LIT:0> ) <EOL> @ six . add_metaclass ( ABCMeta ) <EOL> class NodeLike ( object ) : <EOL> parent = abstractproperty ( ) <EOL> next_sibling = abstractproperty ( ) <EOL> previous_sibling = abstractproperty ( ) <EOL> text = abstractproperty ( ) <EOL> attrs = abstractproperty ( ) <EOL> name = abstractproperty ( ) <EOL> children = abstractproperty ( ) <EOL> contents = abstractproperty ( ) <EOL> descendants = abstractproperty ( ) <EOL> parents = abstractproperty ( ) <EOL> next_siblings = abstractproperty ( ) <EOL> previous_siblings = abstractproperty ( ) <EOL> @ abstractmethod <EOL> def find ( self , name = None , attrs = { } , recursive = True , <EOL> text = None , ** kwargs ) : <EOL> pass <EOL> @ abstractmethod <EOL> def find_all ( self , name = None , attrs = { } , recursive = True , <EOL> text = None , ** kwargs ) : <EOL> pass <EOL> @ abstractmethod <EOL> def select ( self , selector ) : <EOL> pass <EOL> @ abstractmethod <EOL> def find_next_sibling ( self , * args , ** kwargs ) : <EOL> pass <EOL> @ abstractmethod <EOL> def find_previous_sibling ( self , * args , ** kwargs ) : <EOL> pass <EOL> @ abstractmethod <EOL> def find_parent ( self , * args , ** kwargs ) : <EOL> pass <EOL> @ abstractmethod <EOL> def find_next_siblings ( self , * args , ** kwargs ) : <EOL> pass <EOL> @ abstractmethod <EOL> def find_previous_siblings ( self , * args , ** kwargs ) : <EOL> pass <EOL> @ abstractmethod <EOL> def find_parents ( self , * args , ** kwargs ) : <EOL> pass <EOL> @ abstractmethod <EOL> def prettify ( self ) : <EOL> pass <EOL> def __iter__ ( self ) : <EOL> for item in self . children : <EOL> yield item <EOL> def __call__ ( self , * args , ** kwargs ) : <EOL> return self . find_all ( * args , ** kwargs ) <EOL> class Node ( NodeLike , Some ) : <EOL> """<STR_LIT>""" <EOL> def __new__ ( cls , value , * args , ** kwargs ) : <EOL> if isinstance ( value , NavigableString ) : <EOL> return object . __new__ ( NavigableStringNode ) <EOL> return object . __new__ ( cls ) <EOL> def _wrap_node ( self , func ) : <EOL> val = func ( self . _value ) <EOL> return NullNode ( ) if val is None else Node ( val ) <EOL> def _wrap_multi ( self , func ) : <EOL> vals = func ( self . _value ) <EOL> return Collection ( map ( Node , vals ) ) <EOL> def _wrap_scalar ( self , func ) : <EOL> val = func ( self . _value ) <EOL> return Scalar ( val ) <EOL> @ property <EOL> def children ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap_multi ( operator . attrgetter ( '<STR_LIT>' ) ) <EOL> @ property <EOL> def parents ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap_multi ( operator . attrgetter ( '<STR_LIT>' ) ) <EOL> @ property <EOL> def contents ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap_multi ( operator . attrgetter ( '<STR_LIT>' ) ) <EOL> @ property <EOL> def descendants ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap_multi ( operator . attrgetter ( '<STR_LIT>' ) ) <EOL> @ property <EOL> def next_siblings ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap_multi ( operator . attrgetter ( '<STR_LIT>' ) ) <EOL> @ property <EOL> def previous_siblings ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap_multi ( operator . attrgetter ( '<STR_LIT>' ) ) <EOL> @ property <EOL> def parent ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap_node ( operator . attrgetter ( '<STR_LIT>' ) ) <EOL> @ property <EOL> def next_sibling ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap_node ( operator . attrgetter ( '<STR_LIT>' ) ) <EOL> @ property <EOL> def previous_sibling ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap_node ( operator . attrgetter ( '<STR_LIT>' ) ) <EOL> @ property <EOL> def attrs ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap_scalar ( operator . attrgetter ( '<STR_LIT>' ) ) <EOL> @ property <EOL> def text ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap_scalar ( operator . attrgetter ( '<STR_LIT:text>' ) ) <EOL> @ property <EOL> def name ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _wrap_scalar ( operator . attrgetter ( '<STR_LIT:name>' ) ) <EOL> def find ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> op = operator . methodcaller ( '<STR_LIT>' , * args , ** kwargs ) <EOL> return self . _wrap_node ( op ) <EOL> def find_next_sibling ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> op = operator . methodcaller ( '<STR_LIT>' , * args , ** kwargs ) <EOL> return self . _wrap_node ( op ) <EOL> def find_parent ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> op = operator . methodcaller ( '<STR_LIT>' , * args , ** kwargs ) <EOL> return self . _wrap_node ( op ) <EOL> def find_previous_sibling ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> op = operator . methodcaller ( '<STR_LIT>' , * args , ** kwargs ) <EOL> return self . _wrap_node ( op ) <EOL> def find_all ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> op = operator . methodcaller ( '<STR_LIT>' , * args , ** kwargs ) <EOL> return self . _wrap_multi ( op ) <EOL> def find_next_siblings ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> op = operator . methodcaller ( '<STR_LIT>' , * args , ** kwargs ) <EOL> return self . _wrap_multi ( op ) <EOL> def find_parents ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> op = operator . methodcaller ( '<STR_LIT>' , * args , ** kwargs ) <EOL> return self . _wrap_multi ( op ) <EOL> def find_previous_siblings ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> op = operator . methodcaller ( '<STR_LIT>' , * args , ** kwargs ) <EOL> return self . _wrap_multi ( op ) <EOL> def select ( self , selector ) : <EOL> """<STR_LIT>""" <EOL> op = operator . methodcaller ( '<STR_LIT>' , selector ) <EOL> return self . _wrap_multi ( op ) <EOL> def prettify ( self ) : <EOL> return self . map ( Q . prettify ( ) ) . val ( ) <EOL> def __len__ ( self ) : <EOL> return len ( self . _value ) <EOL> def __bool__ ( self ) : <EOL> return True <EOL> __nonzero__ = __bool__ <EOL> class NavigableStringNode ( Node ) : <EOL> """<STR_LIT>""" <EOL> @ property <EOL> def attrs ( self ) : <EOL> """<STR_LIT>""" <EOL> return Scalar ( { } ) <EOL> @ property <EOL> def text ( self ) : <EOL> """<STR_LIT>""" <EOL> return Scalar ( self . _value . string ) <EOL> @ property <EOL> def name ( self ) : <EOL> """<STR_LIT>""" <EOL> return Scalar ( '<STR_LIT>' ) <EOL> @ property <EOL> def children ( self ) : <EOL> """<STR_LIT>""" <EOL> return Collection ( [ ] ) <EOL> @ property <EOL> def contents ( self ) : <EOL> """<STR_LIT>""" <EOL> return Collection ( [ ] ) <EOL> @ property <EOL> def descendants ( self ) : <EOL> """<STR_LIT>""" <EOL> return Collection ( [ ] ) <EOL> def find ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return NullNode ( ) <EOL> def find_all ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return Collection ( [ ] ) <EOL> def select ( self , selector ) : <EOL> """<STR_LIT>""" <EOL> return Collection ( [ ] ) <EOL> def prettify ( self ) : <EOL> return self . text . val ( ) <EOL> class NullNode ( NodeLike , BaseNull ) : <EOL> """<STR_LIT>""" <EOL> def _get_null ( self ) : <EOL> """<STR_LIT>""" <EOL> return NullNode ( ) <EOL> def _get_null_set ( self ) : <EOL> """<STR_LIT>""" <EOL> return NullCollection ( ) <EOL> children = property ( _get_null_set ) <EOL> parents = property ( _get_null_set ) <EOL> contents = property ( _get_null_set ) <EOL> descendants = property ( _get_null_set ) <EOL> next_siblings = property ( _get_null_set ) <EOL> previous_siblings = property ( _get_null_set ) <EOL> parent = property ( _get_null ) <EOL> next_sibling = property ( _get_null ) <EOL> previous_sibling = property ( _get_null ) <EOL> attrs = property ( lambda self : Null ( ) ) <EOL> text = property ( lambda self : Null ( ) ) <EOL> name = property ( lambda self : Null ( ) ) <EOL> def find ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return NullNode ( ) <EOL> def find_parent ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return NullNode ( ) <EOL> def find_previous_sibling ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return NullNode ( ) <EOL> def find_next_sibling ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return NullNode ( ) <EOL> def find_all ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return NullCollection ( ) <EOL> def find_parents ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return NullCollection ( ) <EOL> def find_next_siblings ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return NullCollection ( ) <EOL> def find_previous_siblings ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return NullCollection ( ) <EOL> def select ( self , selector ) : <EOL> """<STR_LIT>""" <EOL> return NullCollection ( ) <EOL> def dump ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return Null ( ) <EOL> def prettify ( self ) : <EOL> return "<STR_LIT>" <EOL> def __len__ ( self ) : <EOL> return <NUM_LIT:0> <EOL> def either ( * funcs ) : <EOL> """<STR_LIT>""" <EOL> def either ( val ) : <EOL> for func in funcs : <EOL> result = val . apply ( func ) <EOL> if result : <EOL> return result <EOL> return Null ( ) <EOL> return either <EOL> def _helpful_failure ( method ) : <EOL> """<STR_LIT>""" <EOL> @ wraps ( method ) <EOL> def wrapper ( self , val ) : <EOL> try : <EOL> return method ( self , val ) <EOL> except : <EOL> exc_cls , inst , tb = sys . exc_info ( ) <EOL> if hasattr ( inst , '<STR_LIT>' ) : <EOL> _ , expr , _ , inner_val = Q . __debug_info__ <EOL> Q . __debug_info__ = QDebug ( self , expr , val , inner_val ) <EOL> raise <EOL> if issubclass ( exc_cls , KeyError ) : <EOL> exc_cls = QKeyError <EOL> prettyval = repr ( val ) <EOL> if len ( prettyval ) > <NUM_LIT> : <EOL> prettyval = "<STR_LIT>" % ( type ( val ) . __name__ ) <EOL> msg = "<STR_LIT>" . format ( <EOL> inst , prettyval , self ) <EOL> new_exc = exc_cls ( msg ) <EOL> new_exc . _RERAISE = True <EOL> Q . __debug_info__ = QDebug ( self , self , val , val ) <EOL> six . reraise ( exc_cls , new_exc , tb ) <EOL> return wrapper <EOL> @ six . python_2_unicode_compatible <EOL> class Expression ( object ) : <EOL> """<STR_LIT>""" <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' <EOL> def __repr__ ( self ) : <EOL> return repr ( str ( self ) ) [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> def __iter__ ( self ) : <EOL> yield self <EOL> def _chain ( self , other ) : <EOL> return Chain ( tuple ( iter ( self ) ) + tuple ( iter ( other ) ) ) <EOL> def __getattr__ ( self , key ) : <EOL> return self . _chain ( Attr ( key ) ) <EOL> def __getitem__ ( self , key ) : <EOL> return self . _chain ( GetItem ( key ) ) <EOL> def __call__ ( self , * args , ** kwargs ) : <EOL> return self . _chain ( Call ( args , kwargs ) ) <EOL> def __gt__ ( self , other ) : <EOL> return BinaryOp ( operator . gt , '<STR_LIT:>>' , self , other ) <EOL> def __ge__ ( self , other ) : <EOL> return BinaryOp ( operator . ge , '<STR_LIT>' , self , other ) <EOL> def __lt__ ( self , other ) : <EOL> return BinaryOp ( operator . lt , '<STR_LIT:<>' , self , other ) <EOL> def __le__ ( self , other ) : <EOL> return BinaryOp ( operator . le , '<STR_LIT>' , self , other ) <EOL> def __eq__ ( self , other ) : <EOL> return BinaryOp ( operator . eq , '<STR_LIT>' , self , other ) <EOL> def __ne__ ( self , other ) : <EOL> return BinaryOp ( operator . ne , '<STR_LIT>' , self , other ) <EOL> def __add__ ( self , other ) : <EOL> return BinaryOp ( operator . add , '<STR_LIT:+>' , self , other ) <EOL> def __sub__ ( self , other ) : <EOL> return BinaryOp ( operator . sub , '<STR_LIT:->' , self , other ) <EOL> def __div__ ( self , other ) : <EOL> return BinaryOp ( operator . __div__ , '<STR_LIT:/>' , self , other ) <EOL> def __floordiv__ ( self , other ) : <EOL> return BinaryOp ( operator . floordiv , '<STR_LIT>' , self , other ) <EOL> def __truediv__ ( self , other ) : <EOL> return BinaryOp ( operator . truediv , '<STR_LIT:/>' , self , other ) <EOL> def __mul__ ( self , other ) : <EOL> return BinaryOp ( operator . mul , '<STR_LIT:*>' , self , other ) <EOL> def __rmul__ ( self , other ) : <EOL> return BinaryOp ( operator . mul , '<STR_LIT:*>' , other , self ) <EOL> def __pow__ ( self , other ) : <EOL> return BinaryOp ( operator . pow , '<STR_LIT>' , self , other ) <EOL> def __mod__ ( self , other ) : <EOL> return BinaryOp ( operator . mod , '<STR_LIT:%>' , self , other ) <EOL> @ _helpful_failure <EOL> def eval_ ( self , val ) : <EOL> """<STR_LIT>""" <EOL> return val <EOL> def debug_ ( self ) : <EOL> """<STR_LIT>""" <EOL> result = self . __debug_info__ <EOL> if isinstance ( result , QDebug ) : <EOL> return result <EOL> return QDebug ( None , None , None , None ) <EOL> @ six . python_2_unicode_compatible <EOL> class Call ( Expression ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , args , kwargs ) : <EOL> self . _args = args <EOL> self . _kwargs = kwargs <EOL> @ _helpful_failure <EOL> def eval_ ( self , val ) : <EOL> return val . __call__ ( * self . _args , ** self . _kwargs ) <EOL> def __str__ ( self ) : <EOL> result = list ( map ( _uniquote , self . _args ) ) <EOL> if self . _kwargs : <EOL> result . append ( '<STR_LIT>' % _uniquote ( self . _kwargs ) ) <EOL> return '<STR_LIT>' % ( '<STR_LIT:U+002CU+0020>' . join ( result ) ) <EOL> @ six . python_2_unicode_compatible <EOL> class BinaryOp ( Expression ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , op , symbol , left , right ) : <EOL> self . op = op <EOL> self . left = left <EOL> self . right = right <EOL> self . symbol = symbol <EOL> @ _helpful_failure <EOL> def eval_ ( self , val ) : <EOL> left = self . left <EOL> right = self . right <EOL> if isinstance ( left , Expression ) : <EOL> left = left . eval_ ( val ) <EOL> if isinstance ( right , Expression ) : <EOL> right = right . eval_ ( val ) <EOL> return self . op ( left , right ) <EOL> def __str__ ( self ) : <EOL> l , r = self . left , self . right <EOL> if isinstance ( l , BinaryOp ) : <EOL> l = '<STR_LIT>' % str ( l ) <EOL> if isinstance ( r , BinaryOp ) : <EOL> r = '<STR_LIT>' % str ( r ) <EOL> return "<STR_LIT>" % ( l , self . symbol , r ) <EOL> @ six . python_2_unicode_compatible <EOL> class Attr ( Expression ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , attribute_name ) : <EOL> self . _name = attribute_name <EOL> @ _helpful_failure <EOL> def eval_ ( self , val ) : <EOL> return operator . attrgetter ( self . _name ) ( val ) <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' % self . _name <EOL> @ six . python_2_unicode_compatible <EOL> class GetItem ( Expression ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , key ) : <EOL> self . _name = key <EOL> @ _helpful_failure <EOL> def eval_ ( self , val ) : <EOL> return operator . itemgetter ( self . _name ) ( val ) <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % _uniquote ( self . _name ) <EOL> @ six . python_2_unicode_compatible <EOL> class Chain ( Expression ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , items ) : <EOL> self . _items = items <EOL> def __iter__ ( self ) : <EOL> for item in self . _items : <EOL> yield item <EOL> @ _helpful_failure <EOL> def eval_ ( self , val ) : <EOL> for item in self . _items : <EOL> val = item . eval_ ( val ) <EOL> return val <EOL> def __str__ ( self ) : <EOL> return '<STR_LIT>' . join ( map ( _uniquote , self . _items ) ) <EOL> def _make_callable ( func ) : <EOL> if func is None : <EOL> func = Q <EOL> return getattr ( func , '<STR_LIT>' , func ) <EOL> def _unwrap ( val ) : <EOL> if isinstance ( val , Wrapper ) : <EOL> return val . val ( ) <EOL> return val <EOL> def _dequote ( str ) : <EOL> try : <EOL> return QUOTED_STR . findall ( str ) [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> raise AssertionError ( "<STR_LIT>" ) <EOL> def _uniquote ( value ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( value , six . binary_type ) : <EOL> try : <EOL> value = value . decode ( '<STR_LIT:utf-8>' ) <EOL> except UnicodeDecodeError : <EOL> value = six . text_type ( _dequote ( repr ( value ) ) ) <EOL> result = six . text_type ( value ) <EOL> if isinstance ( value , six . text_type ) : <EOL> result = "<STR_LIT>" % result <EOL> return result <EOL> def _repr ( value ) : <EOL> value = repr ( value ) <EOL> if isinstance ( value , six . binary_type ) : <EOL> value = value . decode ( '<STR_LIT:utf-8>' ) <EOL> return value <EOL> class Soupy ( Node ) : <EOL> def __init__ ( self , val , * args , ** kwargs ) : <EOL> if not isinstance ( val , PageElement ) : <EOL> val = BeautifulSoup ( val , * args , ** kwargs ) <EOL> super ( Soupy , self ) . __init__ ( val ) <EOL> Q = Expression ( ) </s>
