Skip to content

Commit 98c44b1

Browse files
committed
chore(refactor):
- Added proper type hinting (checked with mypy). - Refactored some methods/functions to remove redundant control flow without changing the expected/initial behaviour of those methods. - Refactored Nmap classes to use a proper inheritance hierarchy. This also allowed for better typing. All this was implemented without changing the initial/default behaviour of those classes in any way.
1 parent d108946 commit 98c44b1

File tree

5 files changed

+1278
-539
lines changed

5 files changed

+1278
-539
lines changed

nmap3/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
# __init__.py
2-
#
2+
#
33
# Copyright 2020 Wangolo Joel <wangolo@ldap.testlumiotic.com>
4-
#
4+
#
55
# This program is free software; you can redistribute it and/or modify
66
# it under the terms of the GNU General Public License as published by
77
# the Free Software Foundation; either version 2 of the License, or
88
# (at your option) any later version.
9-
#
9+
#
1010
# This program is distributed in the hope that it will be useful,
1111
# but WITHOUT ANY WARRANTY; without even the implied warranty of
1212
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313
# GNU General Public License for more details.
14-
#
14+
#
1515
# You should have received a copy of the GNU General Public License
1616
# along with this program; if not, write to the Free Software
1717
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
1818
# MA 02110-1301, USA.
19-
#
20-
#
19+
#
20+
#
2121

2222
from .nmap3 import * # noqa
2323
from .nmap3 import __author__ # noqa

nmap3/exceptions.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,47 @@
11
# nmap3.py
2-
#
2+
#
33
# Copyright 2019 Wangolo Joel <wangolo@ldap.testlumiotic.com>
4-
#
4+
#
55
# This program is free software; you can redistribute it and/or modify
66
# it under the terms of the GNU General Public License as published by
77
# the Free Software Foundation; either version 2 of the License, or
88
# (at your option) any later version.
9-
#
9+
#
1010
# This program is distributed in the hope that it will be useful,
1111
# but WITHOUT ANY WARRANTY; without even the implied warranty of
1212
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1313
# GNU General Public License for more details.
14-
#
14+
#
1515
# You should have received a copy of the GNU General Public License
1616
# along with this program; if not, write to the Free Software
1717
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
1818
# MA 02110-1301, USA.
19-
#
19+
#
20+
21+
__author__ = "Wangolo Joel (inquiry@nmapper.com)"
22+
__version__ = "1.9.3"
23+
__last_modification__ = "Jun/06/2025"
24+
25+
import typing
2026

21-
__author__ = 'Wangolo Joel (inquiry@nmapper.com)'
22-
__version__ = '1.9.3'
23-
__last_modification__ = 'Jun/06/2025'
2427

2528
class NmapNotInstalledError(Exception):
2629
"""Exception raised when nmap is not installed"""
27-
28-
def __init__(self, path=""):
30+
31+
def __init__(self, path: typing.Optional[str] = None):
2932
self.message = f"Nmap is either not installed or we couldn't locate \
3033
nmap path. Please ensure nmap is installed and provide right path string. \n\
3134
Provided: *{path if path else 'Not provided'}*"
3235
super().__init__(self.message)
33-
36+
37+
3438
class NmapXMLParserError(Exception):
3539
"""Exception raised when we can't parse the output"""
36-
37-
def __init__(self, message="Unable to parse xml output"):
38-
self.message = message
40+
41+
def __init__(self, message: str = "Unable to parse xml output"):
42+
self.message = message
3943
super().__init__(message)
4044

45+
4146
class NmapExecutionError(Exception):
4247
"""Exception raised when en error occurred during nmap call"""
43-

0 commit comments

Comments
 (0)