1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 20:51:30 +00:00

Apply PEP 8 style guidance to zenmap

Using the pep8 tool (https://pypi.python.org/pypi/pep8), fixed the
following style issues:

Count   Issue
11      E201 whitespace after '['
8       E203 whitespace before ','
41      E211 whitespace before '('
11      E221 multiple spaces before operator
61      E225 missing whitespace around operator
237     E231 missing whitespace after ':'
91      E251 no spaces around keyword / parameter equals
19      E261 at least two spaces before inline comment
41      E301 expected 1 blank line, found 0
200     E302 expected 2 blank lines, found 1
356     E303 too many blank lines (2)
563     E501 line too long (106 characters)
39      E701 multiple statements on one line (colon)
13      E702 multiple statements on one line (semicolon)
4       W291 trailing whitespace
2       W293 blank line contains whitespace
8       W391 blank line at end of file
21      W601 .has_key() is deprecated, use 'in'
2       W602 deprecated form of raising exception

The remaining issues are long lines due to very deep data structures. I
chose not to alter them, as it would involve backslash-continuation
where whitespace is not permitted:

./zenmapGUI/ScanInterface.py:323:80: E501 line too long (90 characters)
./zenmapGUI/ScanInterface.py:456:80: E501 line too long (84 characters)
./zenmapGUI/ScanInterface.py:464:80: E501 line too long (84 characters)
./zenmapGUI/ScanInterface.py:472:80: E501 line too long (122 characters)
./zenmapGUI/ScanInterface.py:479:80: E501 line too long (122 characters)
./zenmapGUI/ScanInterface.py:920:80: E501 line too long (94 characters)
./zenmapGUI/ScanInterface.py:923:80: E501 line too long (93 characters)
./zenmapGUI/MainWindow.py:575:80: E501 line too long (99 characters)
./zenmapGUI/MainWindow.py:906:80: E501 line too long (99 characters)
This commit is contained in:
dmiller
2014-01-08 19:50:22 +00:00
parent 9210a7f1fa
commit 5c662fffdc
100 changed files with 2287 additions and 1814 deletions

View File

@@ -134,13 +134,14 @@ from zenmapCore.UmitConf import NmapOutputHighlight
from zenmapGUI.NmapOutputProperties import NmapOutputProperties
class NmapOutputViewer (gtk.VBox):
HIGHLIGHT_PROPERTIES = ["details", "date", "hostname", "ip", "port_list",
"open_port", "closed_port", "filtered_port"]
def __init__ (self, refresh=1, stop=1):
def __init__(self, refresh=1, stop=1):
self.nmap_highlight = NmapOutputHighlight()
gtk.VBox.__init__ (self)
gtk.VBox.__init__(self)
# Creating widgets
self.__create_widgets()
@@ -158,7 +159,7 @@ class NmapOutputViewer (gtk.VBox):
self.refreshing = True
# Adding widgets to the VBox
self.pack_start(self.scrolled, expand = True, fill = True)
self.pack_start(self.scrolled, expand=True, fill=True)
# The NmapCommand instance, if any, whose output is shown in this
# display.
@@ -166,16 +167,16 @@ class NmapOutputViewer (gtk.VBox):
# The position of the last read from the output stream.
self.output_file_pointer = None
def __create_widgets (self):
def __create_widgets(self):
# Creating widgets
self.scrolled = gtk.ScrolledWindow ()
self.text_view = gtk.TextView ()
self.scrolled = gtk.ScrolledWindow()
self.text_view = gtk.TextView()
def __set_scrolled_window (self):
def __set_scrolled_window(self):
# Seting scrolled window
self.scrolled.set_border_width (5)
self.scrolled.set_border_width(5)
self.scrolled.add(self.text_view)
self.scrolled.set_policy (gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC)
self.scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
def __set_text_view(self):
self.text_view.set_wrap_mode(gtk.WRAP_WORD)
@@ -205,8 +206,12 @@ class NmapOutputViewer (gtk.VBox):
text_color = settings[3]
highlight_color = settings[4]
tag.set_property("foreground", gtk.color_selection_palette_to_string([gtk.gdk.Color(*text_color),]))
tag.set_property("background", gtk.color_selection_palette_to_string([gtk.gdk.Color(*highlight_color),]))
tag.set_property(
"foreground", gtk.color_selection_palette_to_string(
[gtk.gdk.Color(*text_color), ]))
tag.set_property(
"background", gtk.color_selection_palette_to_string(
[gtk.gdk.Color(*highlight_color), ]))
def go_to_host(self, host):
"""Go to host line on nmap output result"""
@@ -218,7 +223,8 @@ class NmapOutputViewer (gtk.VBox):
for i in xrange(len(output)):
if re_host.match(output[i]):
self.text_view.scroll_to_iter(buff.get_iter_at_line(i), 0, True, 0, 0)
self.text_view.scroll_to_iter(
buff.get_iter_at_line(i), 0, True, 0, 0)
break
def show_output_properties(self, widget):
@@ -259,7 +265,7 @@ class NmapOutputViewer (gtk.VBox):
self.nmap_highlight.save_changes()
self.apply_highlighting()
def apply_highlighting(self, start_iter = None, end_iter = None):
def apply_highlighting(self, start_iter=None, end_iter=None):
buf = self.text_view.get_buffer()
if start_iter is None:
@@ -302,7 +308,7 @@ class NmapOutputViewer (gtk.VBox):
self.output_file_pointer = None
self.refresh_output()
def refresh_output(self, widget = None):
def refresh_output(self, widget=None):
"""Update the output from the latest output of the command associated
with this view, as set by set_command_execution. It has no effect if no
command has been set."""
@@ -316,7 +322,8 @@ class NmapOutputViewer (gtk.VBox):
pos = self.command_execution.stdout_file.tell()
new_output = self.command_execution.stdout_file.read()
self.output_file_pointer = self.command_execution.stdout_file.tell()
# print "read %d -> %d %d" % (pos, self.output_file_pointer, len(new_output))
# print "read %d -> %d %d" % (
# pos, self.output_file_pointer, len(new_output))
v_adj = self.scrolled.get_vadjustment()
if new_output and v_adj is not None:
@@ -324,15 +331,19 @@ class NmapOutputViewer (gtk.VBox):
at_end = (v_adj.value >= v_adj.upper - v_adj.page_size)
buf = self.text_view.get_buffer()
prev_end_mark = buf.create_mark(None, buf.get_end_iter(), left_gravity = True)
prev_end_mark = buf.create_mark(
None, buf.get_end_iter(), left_gravity=True)
buf.insert(buf.get_end_iter(), new_output)
# Highlight the new text.
self.apply_highlighting(buf.get_iter_at_mark(prev_end_mark), buf.get_end_iter())
self.apply_highlighting(
buf.get_iter_at_mark(prev_end_mark), buf.get_end_iter())
if at_end:
# If we were already scrolled to the bottom, scroll back to the
# bottom again. Also do it in an idle handler in case the added
# text causes a scroll bar to appear and reflow the text, making
# the text a bit taller.
# text causes a scroll bar to appear and reflow the text,
# making the text a bit taller.
self.text_view.scroll_mark_onscreen(self.end_mark)
gobject.idle_add(lambda: self.text_view.scroll_mark_onscreen(self.end_mark))
gobject.idle_add(
lambda: self.text_view.scroll_mark_onscreen(
self.end_mark))