<s> from selenium . common . exceptions import ElementNotSelectableException <EOL> from selenium . common . exceptions import ElementNotVisibleException <EOL> from selenium . common . exceptions import InvalidCookieDomainException <EOL> from selenium . common . exceptions import InvalidElementStateException <EOL> from selenium . common . exceptions import InvalidSelectorException <EOL> from selenium . common . exceptions import ImeNotAvailableException <EOL> from selenium . common . exceptions import ImeActivationFailedException <EOL> from selenium . common . exceptions import NoSuchElementException <EOL> from selenium . common . exceptions import NoSuchFrameException <EOL> from selenium . common . exceptions import NoSuchWindowException <EOL> from selenium . common . exceptions import StaleElementReferenceException <EOL> from selenium . common . exceptions import UnableToSetCookieException <EOL> from selenium . common . exceptions import UnexpectedAlertPresentException <EOL> from selenium . common . exceptions import NoAlertPresentException <EOL> from selenium . common . exceptions import ErrorInResponseException <EOL> from selenium . common . exceptions import TimeoutException <EOL> from selenium . common . exceptions import WebDriverException <EOL> from selenium . common . exceptions import MoveTargetOutOfBoundsException <EOL> try : <EOL> basestring <EOL> except NameError : <EOL> basestring = str <EOL> class ErrorCode ( object ) : <EOL> """<STR_LIT>""" <EOL> SUCCESS = <NUM_LIT:0> <EOL> NO_SUCH_ELEMENT = <NUM_LIT:7> <EOL> NO_SUCH_FRAME = <NUM_LIT:8> <EOL> UNKNOWN_COMMAND = <NUM_LIT:9> <EOL> STALE_ELEMENT_REFERENCE = <NUM_LIT:10> <EOL> ELEMENT_NOT_VISIBLE = <NUM_LIT:11> <EOL> INVALID_ELEMENT_STATE = <NUM_LIT:12> <EOL> UNKNOWN_ERROR = <NUM_LIT> <EOL> ELEMENT_IS_NOT_SELECTABLE = <NUM_LIT:15> <EOL> JAVASCRIPT_ERROR = <NUM_LIT> <EOL> XPATH_LOOKUP_ERROR = <NUM_LIT> <EOL> TIMEOUT = <NUM_LIT> <EOL> NO_SUCH_WINDOW = <NUM_LIT> <EOL> INVALID_COOKIE_DOMAIN = <NUM_LIT> <EOL> UNABLE_TO_SET_COOKIE = <NUM_LIT> <EOL> UNEXPECTED_ALERT_OPEN = <NUM_LIT> <EOL> NO_ALERT_OPEN = <NUM_LIT> <EOL> SCRIPT_TIMEOUT = <NUM_LIT> <EOL> INVALID_ELEMENT_COORDINATES = <NUM_LIT> <EOL> IME_NOT_AVAILABLE = <NUM_LIT:30> ; <EOL> IME_ENGINE_ACTIVATION_FAILED = <NUM_LIT> <EOL> INVALID_SELECTOR = <NUM_LIT:32> <EOL> MOVE_TARGET_OUT_OF_BOUNDS = <NUM_LIT> <EOL> INVALID_XPATH_SELECTOR = <NUM_LIT> <EOL> INVALID_XPATH_SELECTOR_RETURN_TYPER = <NUM_LIT> <EOL> METHOD_NOT_ALLOWED = <NUM_LIT> <EOL> class ErrorHandler ( object ) : <EOL> """<STR_LIT>""" <EOL> def check_response ( self , response ) : <EOL> """<STR_LIT>""" <EOL> status = response [ '<STR_LIT:status>' ] <EOL> if status == ErrorCode . SUCCESS : <EOL> return <EOL> exception_class = ErrorInResponseException <EOL> if status == ErrorCode . NO_SUCH_ELEMENT : <EOL> exception_class = NoSuchElementException <EOL> elif status == ErrorCode . NO_SUCH_FRAME : <EOL> exception_class = NoSuchFrameException <EOL> elif status == ErrorCode . NO_SUCH_WINDOW : <EOL> exception_class = NoSuchWindowException <EOL> elif status == ErrorCode . STALE_ELEMENT_REFERENCE : <EOL> exception_class = StaleElementReferenceException <EOL> elif status == ErrorCode . ELEMENT_NOT_VISIBLE : <EOL> exception_class = ElementNotVisibleException <EOL> elif status == ErrorCode . INVALID_ELEMENT_STATE : <EOL> exception_class = InvalidElementStateException <EOL> elif status == ErrorCode . INVALID_SELECTOR or status == ErrorCode . INVALID_XPATH_SELECTOR or status == ErrorCode . INVALID_XPATH_SELECTOR_RETURN_TYPER : <EOL> exception_class = InvalidSelectorException <EOL> elif status == ErrorCode . ELEMENT_IS_NOT_SELECTABLE : <EOL> exception_class = ElementNotSelectableException <EOL> elif status == ErrorCode . INVALID_COOKIE_DOMAIN : <EOL> exception_class = WebDriverException <EOL> elif status == ErrorCode . UNABLE_TO_SET_COOKIE : <EOL> exception_class = WebDriverException <EOL> elif status == ErrorCode . TIMEOUT : <EOL> exception_class = TimeoutException <EOL> elif status == ErrorCode . SCRIPT_TIMEOUT : <EOL> exception_class = TimeoutException <EOL> elif status == ErrorCode . UNKNOWN_ERROR : <EOL> exception_class = WebDriverException <EOL> elif status == ErrorCode . UNEXPECTED_ALERT_OPEN : <EOL> exception_class = UnexpectedAlertPresentException <EOL> elif status == ErrorCode . NO_ALERT_OPEN : <EOL> exception_class = NoAlertPresentException <EOL> elif status == ErrorCode . IME_NOT_AVAILABLE : <EOL> exception_class = ImeNotAvailableException <EOL> elif status == ErrorCode . IME_ENGINE_ACTIVATION_FAILED : <EOL> exception_class = ImeActivationFailedException <EOL> elif status == ErrorCode . MOVE_TARGET_OUT_OF_BOUNDS : <EOL> exception_class = MoveTargetOutOfBoundsException <EOL> else : <EOL> exception_class = WebDriverException <EOL> value = response [ '<STR_LIT:value>' ] <EOL> if isinstance ( value , basestring ) : <EOL> if exception_class == ErrorInResponseException : <EOL> raise exception_class ( response , value ) <EOL> raise exception_class ( value ) <EOL> message = '<STR_LIT>' <EOL> if '<STR_LIT:message>' in value : <EOL> message = value [ '<STR_LIT:message>' ] <EOL> screen = None <EOL> if '<STR_LIT>' in value : <EOL> screen = value [ '<STR_LIT>' ] <EOL> stacktrace = None <EOL> if '<STR_LIT>' in value and value [ '<STR_LIT>' ] : <EOL> stacktrace = [ ] <EOL> try : <EOL> for frame in value [ '<STR_LIT>' ] : <EOL> line = self . _value_or_default ( frame , '<STR_LIT>' , '<STR_LIT>' ) <EOL> file = self . _value_or_default ( frame , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if line : <EOL> file = "<STR_LIT>" % ( file , line ) <EOL> meth = self . _value_or_default ( frame , '<STR_LIT>' , '<STR_LIT>' ) <EOL> if '<STR_LIT>' in frame : <EOL> meth = "<STR_LIT>" % ( frame [ '<STR_LIT>' ] , meth ) <EOL> msg = "<STR_LIT>" <EOL> msg = msg % ( meth , file ) <EOL> stacktrace . append ( msg ) <EOL> except TypeError : <EOL> pass <EOL> if exception_class == ErrorInResponseException : <EOL> raise exception_class ( response , message ) <EOL> raise exception_class ( message , screen , stacktrace ) <EOL> def _value_or_default ( self , obj , key , default ) : <EOL> return obj [ key ] if key in obj else default </s>
