diff --git a/zenmap/radialnet/core/XMLHandler.py b/zenmap/radialnet/core/XMLHandler.py index a755b8097..f05374ba6 100644 --- a/zenmap/radialnet/core/XMLHandler.py +++ b/zenmap/radialnet/core/XMLHandler.py @@ -179,10 +179,7 @@ class XMLNode: def get_attr(self, attr): """ """ - if attr in self.__attrs: - return self.__attrs[attr] - - return None + return self.__attrs.get(attr) def get_attrs(self): """ diff --git a/zenmap/radialnet/gui/NodeNotebook.py b/zenmap/radialnet/gui/NodeNotebook.py index ee2521dda..c8c323297 100644 --- a/zenmap/radialnet/gui/NodeNotebook.py +++ b/zenmap/radialnet/gui/NodeNotebook.py @@ -254,17 +254,9 @@ class ServicesPage(gtk.Notebook): color = get_service_color(port['state']['state']) - if 'name' in port['service']: - service_name = port['service']['name'] + service_name = port['service'].get('name', _('')) - else: - service_name = _('') - - if 'method' in port['service']: - service_method = port['service']['method'] - - else: - service_method = _('') + service_method = port['service'].get('method', _('')) reference = self.__ports_store.append(None, [port['id'], @@ -576,10 +568,7 @@ class SystemPage(BWScrolledWindow): for os_class in os['classes']: - os_gen = '' - - if 'os_gen' in os_class: - os_gen = os_class['os_gen'] + os_gen = os_class.get('os_gen', '') self.__class_store.append([os_class['accuracy'], os_class['vendor'], diff --git a/zenmap/radialnet/gui/RadialNet.py b/zenmap/radialnet/gui/RadialNet.py index 742c4e8d1..1fef3bd14 100644 --- a/zenmap/radialnet/gui/RadialNet.py +++ b/zenmap/radialnet/gui/RadialNet.py @@ -2042,10 +2042,7 @@ class NetNode(Node): if info == None: return self.__draw_info - if info in self.__draw_info: - return self.__draw_info[info] - - return None + return self.__draw_info.get(info) def set_draw_info(self, info): """ diff --git a/zenmap/zenmapGUI/DiffCompare.py b/zenmap/zenmapGUI/DiffCompare.py index 46de6f7d3..3e133b74e 100644 --- a/zenmap/zenmapGUI/DiffCompare.py +++ b/zenmap/zenmapGUI/DiffCompare.py @@ -293,18 +293,12 @@ class ScanChooser(HIGVBox): """Return the currently selected scan's parsed output as an NmapParser object, or None if no valid scan is selected.""" selected_scan = self.combo_scan.child.get_text() - if selected_scan in self.scan_dict: - return self.scan_dict[selected_scan] - # What's typed in the entry doesn't match a registered scan. - return None + return self.scan_dict.get(selected_scan) def get_nmap_output(self): """Return the currently selected scan's output as a string, or None if no valid scan is selected.""" - parsed = self.parsed_scan - if parsed is not None: - return parsed.nmap_output - return None + return self.parsed_scan nmap_output = property(get_nmap_output) parsed_scan = property(get_parsed_scan) diff --git a/zenmap/zenmapGUI/ProfileHelp.py b/zenmap/zenmapGUI/ProfileHelp.py index 21fef0074..51d04657b 100644 --- a/zenmap/zenmapGUI/ProfileHelp.py +++ b/zenmap/zenmapGUI/ProfileHelp.py @@ -137,28 +137,19 @@ class ProfileHelp: self.labels[option_name] = text def get_label(self): - if self.currentstate in self.labels.keys(): - return self.labels[self.currentstate] - else: - return "" # blank + return self.labels.get(self.currentstate, "") def add_shortdesc(self, option_name, text): self.descs[option_name] = text def get_shortdesc(self): - if self.currentstate in self.descs.keys(): - return self.descs[self.currentstate] - else: - return "" # blank + return self.descs.get(self.currentstate, "") def add_example(self, option_name, text): self.examples[option_name] = text def get_example(self): - if self.currentstate in self.examples.keys(): - return self.examples[self.currentstate] - else: - return "" # blank + return self.examples.get(self.currentstate, "") def handler(self, whichLabel): log.debug("whichLabel: %s" % whichLabel)