def send_command(self, method, url, body=None): """ Send a command to the remote end and validate its success. :param method: HTTP method to use in request. :param uri: "Command part" of the HTTP request URL, e.g. `window/rect`. :param body: Optional body of the HTTP request. :return: `None` if the HTTP response body was empty, otherwise the result of parsing the body as JSON. :raises error.WebDriverException: If the remote end returns an error. """ response = self.transport.send(method, url, body) if "value" in response.body: value = response.body["value"] else: raise error.UnknownErrorException( "No 'value' key in response body:\n%s" % json.dumps(response.body)) if response.status != 200: cls = error.get(value.get("error")) raise cls(value.get("message")) return value
def send_command(self, method, url, body=None, key=None): """Send a command to the remote end and validate its success. :param method: HTTP method to use in request :param url: "command part" of the requests URL path :param body: body of the HTTP request :param key: (deprecated) when specified, this string value will be used to de-reference the HTTP response body following JSON parsing :return: None if the HTTP response body was empty, otherwise the result of parsing the HTTP response body as JSON """ if self.session_id is None: raise error.SessionNotCreatedException() response = self.send_raw_command(method, url, body) if response.status != 200: cls = error.get(response.body["value"].get("error")) raise cls(response.body["value"].get("message")) if key is not None: response.body = response.body[key] if not response.body: response.body = None return response.body
def send_command(self, method, url, body=None): """ Send a command to the remote end and validate its success. :param method: HTTP method to use in request. :param uri: "Command part" of the HTTP request URL, e.g. `window/rect`. :param body: Optional body of the HTTP request. :return: `None` if the HTTP response body was empty, otherwise the result of parsing the body as JSON. :raises error.WebDriverException: If the remote end returns an error. """ response = self.transport.send(method, url, body) if "value" in response.body: value = response.body["value"] else: raise error.UnknownErrorException("No 'value' key in response body:\n%s" % json.dumps(response.body)) if response.status != 200: cls = error.get(value.get("error")) raise cls(value.get("message")) return value
def send(self, method, url, body=None, headers=None, key=None): """Send a command to the remote. :param method: "POST" or "GET". :param body: Body of the request. Defaults to an empty dictionary if ``method`` is "POST". :param headers: Additional headers to include in the request. :param key: Extract this key from the dictionary returned from the remote. """ if body is None and method == "POST": body = {} if isinstance(body, dict): body = json.dumps(body) if isinstance(body, unicode): body = body.encode("utf-8") if headers is None: headers = {} url = self.url_prefix + url conn = httplib.HTTPConnection(self.host, self.port, strict=True, timeout=self._timeout) conn.request(method, url, body, headers) resp = conn.getresponse() resp_body = resp.read() conn.close() try: data = json.loads(resp_body) except: raise IOError("Could not parse response body as JSON: '%s'" % resp_body) if resp.status != 200: cls = error.get(data.get("error")) raise cls(data.get("message")) if key is not None: data = data[key] if not data: data = None return data
def send(self, method, url, body=None, headers=None, key=None): """Send a command to the remote. :param method: "POST" or "GET". :param body: Body of the request. Defaults to an empty dictionary if ``method`` is "POST". :param headers: Additional headers to include in the request. :param key: Extract this key from the dictionary returned from the remote. """ if body is None and method == "POST": body = {} if isinstance(body, dict): body = json.dumps(body) if isinstance(body, unicode): body = body.encode("utf-8") if headers is None: headers = {} url = self.url_prefix + url conn = httplib.HTTPConnection( self.host, self.port, strict=True, timeout=self._timeout) conn.request(method, url, body, headers) resp = conn.getresponse() resp_body = resp.read() conn.close() try: data = json.loads(resp_body) except: raise IOError("Could not parse response body as JSON: '%s'" % resp_body) if resp.status != 200: cls = error.get(data.get("error")) raise cls(data.get("message")) if key is not None: data = data[key] if not data: data = None return data
def coach( music, mode ): # Decides of the following events according to the difficulties of the player if mode == 'basic': # Just waits for the player to press the right keys in order to generate the animation of the next 2 seconds fsampling, Notes = read_file.read_tlp(music) tau = 1 / fsampling t = 0 for sample in Notes: # Pause of a tau length t += tau display.disp(sample) error = error.get( ) # We check if the player has made an error or not else: print("Unavailable function at the moment") return exit_flag # The player needs to be able to quit the software at any moment
def send_raw_command(self, method, url, body=None, headers=None): """ Send a raw unchecked and unaltered command to the remote end, even when there is no active session. :param method: HTTP method to use in request. :param url: Full request URL. :param body: Optional body of the HTTP request. :param headers: Optional additional headers to include in the HTTP request. :return: Instance of ``transport.Response`` describing the HTTP response received from the remote end. :raises error.WebDriverException: If the remote end returns an error. """ response = self.transport.send(method, url, body, headers) if response.status != 200: value = response.body["value"] cls = error.get(value.get("error")) raise cls(value.get("message")) return response