1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-07 05:01:29 +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

@@ -152,6 +152,7 @@ paths_config = PathsConfig()
log.debug(">>> Platform: %s" % sys.platform)
def wrap_file_in_preferred_encoding(f):
"""Wrap an open file to automatically decode its contents when reading from
the encoding given by locale.getpreferredencoding, or just return the file
@@ -184,17 +185,19 @@ def wrap_file_in_preferred_encoding(f):
return f
def escape_nmap_filename(filename):
"""Escape '%' characters so they are not interpreted as strftime format
specifiers, which are not supported by Zenmap."""
return filename.replace("%", "%%")
class NmapCommand(object):
"""This class represents an Nmap command line. It is responsible for
starting, stopping, and returning the results from a command-line scan. A
command line is represented as a string but it is split into a list of
arguments for execution.
The normal output (stdout and stderr) are written to the file object
self.stdout_file."""
@@ -231,7 +234,8 @@ class NmapCommand(object):
self.ops[op] = escape_nmap_filename(self.ops[op])
if self.xml_is_temp:
self.xml_output_filename = tempfile.mktemp(prefix = APP_NAME + "-", suffix = ".xml")
self.xml_output_filename = tempfile.mktemp(
prefix=APP_NAME + "-", suffix=".xml")
self.ops["-oX"] = escape_nmap_filename(self.xml_output_filename)
log.debug(">>> Temporary files:")
@@ -261,7 +265,8 @@ class NmapCommand(object):
else:
try:
import ctypes
ctypes.windll.kernel32.TerminateProcess(int(self.command_process._handle), -1)
ctypes.windll.kernel32.TerminateProcess(
int(self.command_process._handle), -1)
except:
pass
@@ -279,13 +284,13 @@ class NmapCommand(object):
search_paths.append(path)
return os.pathsep.join(search_paths)
def run_scan(self, stderr = None):
def run_scan(self, stderr=None):
"""Run the command represented by this class."""
# We don't need a file name for stdout output, just a handle. A
# TemporaryFile is deleted as soon as it is closed, and in Unix is
# unlinked immediately after creation so it's not even visible.
f = tempfile.TemporaryFile(mode = "rb", prefix = APP_NAME + "-stdout-")
f = tempfile.TemporaryFile(mode="rb", prefix=APP_NAME + "-stdout-")
self.stdout_file = wrap_file_in_preferred_encoding(f)
if stderr is None:
stderr = f
@@ -303,7 +308,8 @@ class NmapCommand(object):
# This keeps a terminal window from opening.
startupinfo = subprocess.STARTUPINFO()
try:
startupinfo.dwFlags |= subprocess._subprocess.STARTF_USESHOWWINDOW
startupinfo.dwFlags |= \
subprocess._subprocess.STARTF_USESHOWWINDOW
except AttributeError:
# This name is used before Python 2.6.5.
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
@@ -312,7 +318,7 @@ class NmapCommand(object):
stdin=subprocess.PIPE,
stdout=f,
stderr=stderr,
startupinfo = startupinfo,
startupinfo=startupinfo,
env=env)
def scan_state(self):
@@ -327,15 +333,18 @@ class NmapCommand(object):
state = self.command_process.poll()
if state == None:
return True # True means that the process is still running
return True # True means that the process is still running
elif state == 0:
return False # False means that the process had a successful exit
return False # False means that the process had a successful exit
else:
log.warning("An error occurred during the scan execution!")
log.warning("Command that raised the exception: '%s'" % self.ops.render_string())
log.warning("Command that raised the exception: '%s'" %
self.ops.render_string())
log.warning("Scan output:\n%s" % self.get_output())
raise Exception("An error occurred during the scan execution!\n\n'%s'" % self.get_output())
raise Exception(
"An error occurred during the scan execution!\n\n'%s'" %
self.get_output())
def get_output(self):
"""Return the complete contents of the self.stdout_file. This modifies
@@ -348,4 +357,5 @@ class NmapCommand(object):
return self.xml_output_filename
if __name__ == '__main__':
unittest.TextTestRunner().run(unittest.TestLoader().loadTestsFromTestCase(SplitQuotedTest))
unittest.TextTestRunner().run(
unittest.TestLoader().loadTestsFromTestCase(SplitQuotedTest))