(self,
               method: str,
               urlpath: str,
               data: Optional[dict] = None,
               with_session: bool = False,
               timeout: Optional[float] = None)
do http request
do http request
do http request
def _fetch(self,
               method: str,
               urlpath: str,
               data: Optional[dict] = None,
               with_session: bool = False,
               timeout: Optional[float] = None) -> AttrDict:
        """ do http request """
        urlpath = "/" + urlpath.lstrip("/")  # urlpath always startswith /

        callbacks = self.__callbacks

        if self.__callback_running:
            callbacks = None

        url = urljoin(self.__wda_url, urlpath)

        run_callback = functools.partial(self._run_callback,
                                         callbacks=callbacks,
                                         method=method,
                                         url=url,
                                         urlpath=urlpath,
                                         with_session=with_session,
                                         data=data,
                                         client=self)

        try:
            if with_session:
                url = urljoin(self.__wda_url, "session", self.session_id,
                              urlpath)
            run_callback(Callback.HTTP_REQUEST_BEFORE)
            response = httpdo(url, method, data, timeout)
            run_callback(Callback.HTTP_REQUEST_AFTER, response=response)
            return response
        except Exception as err:
            ret = run_callback(Callback.ERROR, err=err)
            if ret == Callback.RET_RETRY:
                return self._fetch(method, urlpath, data, with_session)
            elif ret == Callback.RET_CONTINUE:
                return
            else:
                raise
def _fetch ( self , method : str , urlpath : str , data : Optional [ dict ] = None , with_session : bool = False , timeout : Optional [ float ] = None ) -> AttrDict : urlpath = "/" + urlpath . lstrip ( "/" ) # urlpath always startswith / callbacks = self . __callbacks if self . __callback_running : callbacks = None url = urljoin ( self . __wda_url , urlpath ) run_callback = functools . partial ( self . _run_callback , callbacks = callbacks , method = method , url = url , urlpath = urlpath , with_session = with_session , data = data , client = self ) try : if with_session : url = urljoin ( self . __wda_url , "session" , self . session_id , urlpath ) run_callback ( Callback . HTTP_REQUEST_BEFORE ) response = httpdo ( url , method , data , timeout ) run_callback ( Callback . HTTP_REQUEST_AFTER , response = response ) return response except Exception as err : ret = run_callback ( Callback . ERROR , err = err ) if ret == Callback . RET_RETRY : return self . _fetch ( method , urlpath , data , with_session ) elif ret == Callback . RET_CONTINUE : return else : raise