<s> """<STR_LIT>""" <EOL> from . import exceptions <EOL> __all__ = [ '<STR_LIT>' ] <EOL> exceptions_by_name = dict ( ( name , getattr ( exceptions , name ) ) <EOL> for name in ( <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ) <EOL> ) <EOL> exception_patterns_trailing = { <EOL> '<STR_LIT>' : exceptions . NotFoundException , <EOL> '<STR_LIT>' : exceptions . AlreadyExistsException , <EOL> } <EOL> def raise_if_error ( status , result , request = None ) : <EOL> """<STR_LIT>""" <EOL> assert isinstance ( status , int ) <EOL> if status < <NUM_LIT> : <EOL> return <EOL> if status == <NUM_LIT> and isinstance ( result , dict ) and '<STR_LIT:error>' not in result : <EOL> raise exceptions . NotFoundException ( "<STR_LIT>" , status , result , request ) <EOL> if not isinstance ( result , dict ) or '<STR_LIT:error>' not in result : <EOL> raise exceptions . ElasticSearchException ( "<STR_LIT>" % ( status , result ) , status , <EOL> result , request ) <EOL> error = result [ '<STR_LIT:error>' ] <EOL> if '<STR_LIT>' in error : <EOL> error_list = error . split ( '<STR_LIT>' ) <EOL> error = error_list [ len ( error_list ) - <NUM_LIT:1> ] <EOL> bits = error . split ( '<STR_LIT:[>' , <NUM_LIT:1> ) <EOL> if len ( bits ) == <NUM_LIT:2> : <EOL> excClass = exceptions_by_name . get ( bits [ <NUM_LIT:0> ] , None ) <EOL> if excClass is not None : <EOL> msg = bits [ <NUM_LIT:1> ] <EOL> if msg . endswith ( '<STR_LIT:]>' ) : <EOL> msg = msg [ : - <NUM_LIT:1> ] <EOL> '''<STR_LIT>''' <EOL> raise excClass ( msg , status , result , request ) <EOL> for pattern , excClass in list ( exception_patterns_trailing . items ( ) ) : <EOL> if not error . endswith ( pattern ) : <EOL> continue <EOL> raise excClass ( error , status , result , request ) <EOL> raise exceptions . ElasticSearchException ( error , status , result , request ) </s>
