def __request(self, line, raw=False, want_reply=True): """ Send a request to the server, if connected, and return its response """ line = line.strip() if not (self.is_connected or line.split()[0] == 'login'): print_d("Can't do '%s' - not connected" % line.split()[0], self) return None if self._debug: print_(">>>> \"%s\"" % line) try: self.telnet.write((line + "\n").encode('utf-8')) if not want_reply: return None raw_response = self.telnet.read_until(b"\n").decode('utf-8') except socket.error as e: print_w("Couldn't communicate with squeezebox (%s)" % e) self.failures += 1 if self.failures >= self._MAX_FAILURES: print_w("Too many Squeezebox failures. Disconnecting") self.is_connected = False return None response = (raw_response if raw else unquote(raw_response)).strip() if self._debug: print_("<<<< \"%s\"" % (response, )) return (response[len(line) - 1:] if line.endswith("?") else response[len(line) + 1:])
def __request(self, line, raw=False, want_reply=True): """ Send a request to the server, if connected, and return its response """ line = line.strip() if not (self.is_connected or line.split()[0] == 'login'): print_d("Can't do '%s' - not connected" % line.split()[0], self) return None if self._debug: print_(">>>> \"%s\"" % line) try: self.telnet.write((line + "\n").encode('utf-8')) if not want_reply: return None raw_response = self.telnet.read_until(b"\n").decode('utf-8') except socket.error as e: print_w("Couldn't communicate with squeezebox (%s)" % e) self.failures += 1 if self.failures >= self._MAX_FAILURES: print_w("Too many Squeezebox failures. Disconnecting") self.is_connected = False return None response = (raw_response if raw else unquote(raw_response)).strip() if self._debug: print_("<<<< \"%s\"" % (response,)) return response[len(line) - 1:] if line.endswith("?")\ else response[len(line) + 1:]
def unescape_filename(s): """Unescape a string in a manner suitable for a filename. Args: filename (fsnative) Returns: text_type """ assert isinstance(s, fsnative) return fsn2text(unquote(s))
def demunge(string): s = unquote(string) cpos = s.index(":") return s[0:cpos], s[cpos + 1:]