def do_command(self, caps : typedict): def print_fn(s): sys.stdout.write("%s\n" % (s,)) if not caps: self.quit(EXIT_NO_DATA) return exit_code = EXIT_OK try: if FLATTEN_INFO<2: #compatibility mode: c = flatten_dict(caps) for k in sorted_nicely(c.keys()): v = c.get(k) #FIXME: this is a nasty and horrible python3 workaround (yet again) #we want to print bytes as strings without the ugly 'b' prefix.. #it assumes that all the strings are raw or in (possibly nested) lists or tuples only #we assume that all strings we get are utf-8, #and fallback to the bytestostr hack if that fails def fixvalue(w): if isinstance(w, bytes): if k.endswith(".data"): return hexstr(w) return u(w) elif isinstance(w, (tuple,list)): return type(w)([fixvalue(x) for x in w]) return w v = fixvalue(v) k = fixvalue(k) print_fn("%s=%s" % (k, nonl(v))) else: print_nested_dict(caps, print_fn=print_fn) except OSError: exit_code = EXIT_IO_ERROR self.quit(exit_code)
def do_command(self): if self.server_capabilities: if FLATTEN_INFO<2: #compatibility mode: c = flatten_dict(self.server_capabilities) for k in sorted_nicely(c.keys()): v = c.get(k) if PYTHON3: #FIXME: this is a nasty and horrible python3 workaround (yet again) #we want to print bytes as strings without the ugly 'b' prefix.. #it assumes that all the strings are raw or in (possibly nested) lists or tuples only #we assume that all strings we get are utf-8, #and fallback to the bytestostr hack if that fails def fixvalue(w): if type(w)==bytes: try: return w.decode("utf-8") except: return bytestostr(w) elif type(w) in (tuple,list): return type(w)([fixvalue(x) for x in w]) return w v = fixvalue(v) k = fixvalue(k) log.info("%s=%s", k, nonl(v)) else: print_nested_dict(self.server_capabilities) self.quit(EXIT_OK)
def do_command(self): if self.server_capabilities: if FLATTEN_INFO<2: #compatibility mode: for k in sorted_nicely(self.server_capabilities.keys()): v = self.server_capabilities.get(k) if sys.version_info[0]>=3: #FIXME: this is a nasty and horrible python3 workaround (yet again) #we want to print bytes as strings without the ugly 'b' prefix.. #it assumes that all the strings are raw or in (possibly nested) lists or tuples only def fixvalue(w): if type(w)==bytes: return bytestostr(w) elif type(w) in (tuple,list): return type(w)([fixvalue(x) for x in w]) return w v = fixvalue(v) log.info("%s=%s", bytestostr(k), nonl(v)) else: print_nested_dict(self.server_capabilities) self.quit(EXIT_OK)