def _stringify_result(self): """This method try an automatic transformation from self._result object to self._output string. Variables self._result and self._output always contains last run results. """ # Empty outputs. False is probably a good output value if self._result != False and not self._result: self._output = '' # List outputs. elif isinstance(self._result, ListType): if len(self._result) > 0: columns_num = 1 if isinstance(self._result[0], ListType): columns_num = len(self._result[0]) table = PrettyTable(['']*(columns_num)) table.align = 'l' table.header = False for row in self._result: if isinstance(row, ListType): table.add_row(row) else: table.add_row([ row ]) self._output = table.get_string() # Dict outputs are display as tables elif isinstance(self._result, DictType) and self._result: # Populate the rows randomitem = next(self._result.itervalues()) if isinstance(randomitem, ListType): table = PrettyTable(['']*(len(randomitem)+1)) table.align = 'l' table.header = False for field in self._result: table.add_row([field] + self._result[field]) else: table = PrettyTable(['']*2) table.align = 'l' table.header = False for field in self._result: table.add_row([field, str(self._result[field])]) self._output = table.get_string() # Else, try to stringify else: self._output = str(self._result)
def _output_result(self): # Empty outputs. False is probably a good output value if self._result != False and not self._result: self._output = '' # List outputs. elif isinstance(self._result, ListType): if len(self._result) > 0: columns_num = 1 if isinstance(self._result[0], ListType): columns_num = len(self._result[0]) table = PrettyTable(['']*(columns_num)) table.align = 'l' table.header = False for row in self._result: if isinstance(row, ListType): table.add_row(row) else: table.add_row([ row ]) self._output = table.get_string() # Dict outputs are display as tables elif isinstance(self._result, DictType) and self._result: # Populate the rows randomitem = next(self._result.itervalues()) if isinstance(randomitem, ListType): table = PrettyTable(['']*(len(randomitem)+1)) table.align = 'l' table.header = False for field in self._result: table.add_row([field] + self._result[field]) else: table = PrettyTable(['']*2) table.align = 'l' table.header = False for field in self._result: table.add_row([field, str(self._result[field])]) self._output = table.get_string() # Else, try to stringify else: self._output = str(self._result)
def _format_grouped_helps(self, oneline=False): table_module = PrettyTable(['module', 'description']) table_module.align = 'l' table_generator = PrettyTable(['generator', 'description']) table_generator.align = 'l' for groupname in self.modhandler.modules_names_by_group.keys(): for module in self.modhandler.modules_names_by_group[groupname]: if module.startswith('generate.'): table_generator.add_row([ ':%s' % self.modhandler.load(module).name, self.modhandler.load(module).argparser.description]) else: table_module.add_row([ ':%s' % self.modhandler.load(module).name, self.modhandler.load(module).argparser.description]) return '%s\n%s\n\nHint: Run \':help <module>\' to print detailed usage informations.\n\n' % (table_generator.get_string(), table_module.get_string())
def _stringify_result(self): table = PrettyTable([""] * 5) table.align = "l" table.header = False for field in self._result: if self._result[field] != ["", "", "", ""] or self.args["printall"]: table.add_row([field] + self._result[field]) self._output = table.get_string()
def _stringify_result(self): table = PrettyTable([''] * 5) table.align = 'l' table.header = False for field in self._result: if self._result[field] != ['', '', '', ''] or self.args['printall']: table.add_row([field] + self._result[field]) self._output = table.get_string()
def _output_result(self): table = PrettyTable(['']*5) table.align = 'l' table.header = False for field in self._result: if self._result[field] != ['', '', '', ''] or self.args['printall']: table.add_row([field] + self._result[field]) self._output = table.get_string()
def _format_grouped_helps(self, oneline=False): table_module = PrettyTable(["module", "description"]) table_module.align = "l" table_generator = PrettyTable(["generator", "description"]) table_generator.align = "l" for groupname in self.modhandler.modules_names_by_group.keys(): for module in self.modhandler.modules_names_by_group[groupname]: if module.startswith("generate."): table_generator.add_row( [":%s" % self.modhandler.load(module).name, self.modhandler.load(module).argparser.description] ) else: table_module.add_row( [":%s" % self.modhandler.load(module).name, self.modhandler.load(module).argparser.description] ) return "%s\n%s\n\nHint: Run ':help <module>' to print detailed usage informations.\n\n" % ( table_generator.get_string(), table_module.get_string(), )
def show(args): try: if args[0] == "modules" and mm.moduleLoaded == 0: t = PrettyTable([colors.green+'Modules:', ''+colors.end]) t.add_row(['','']) t.align = 'l' t.valing = 'm' t.border = False for key, val in module_database.database.items(): t.add_row([key, val]) print (t) elif args[0] == "options" and mm.moduleLoaded == 1: moduleop.printoptions(modadd) else: raise UnknownCommand("module not loaded or unknown command") except IndexError: raise UnknownCommand("unknown command")
def _stringify_result(self): Module._stringify_result(self) table_insecurities = PrettyTable([''] * (2)) table_insecurities.align = 'l' table_insecurities.header = False table_insecurities.hrules = ALL for res in self._result_insecurities: if isinstance(self._result_insecurities[res], ListType): field_str = '' for chunk in list(chunks(self._result_insecurities[res], 3)): field_str += ', '.join(chunk) + '\n' table_insecurities.add_row([res, field_str.rstrip()]) self._output += '\n%s' % (table_insecurities.get_string())
def printoptions(modadd): try: print(" ") t = PrettyTable( [colors.green + 'Option', 'Value', 'Description' + colors.end]) t.add_row(["------", "------", "-----------"]) t.align = 'l' t.valing = 'm' t.border = False for key, val in zip(modadd.variables.items(), modadd.vdesc): t.add_row([key[0], key[1], val]) print(t, '\n') try: print(modadd.option_notes, '\n') except (AttributeError): pass except Exception as error: print(colors.red + "error: module is corrupted\n") traceback.print_exc(file=sys.stdout) print(colors.end)