Skip to content

Commit 286f00e

Browse files
author
Ronald Bister
committed
another run of py-black with updated version + isort + fix travis
1 parent fbded5d commit 286f00e

42 files changed

Lines changed: 744 additions & 703 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ install:
1818
- "pip install flake8"
1919
- "pip install defusedxml"
2020
- "pip install pytest"
21+
- "pip install pytest-cov"
2122
# - "pip install boto" # disabled: since boto not supporting py3
2223
# - "pip install pymongo sqlalchemy MySQL-python" # disabled MySQL-python (not py3 compatible)
2324
# - "pip install pymongo sqlalchemy pymysql"
@@ -26,7 +27,7 @@ install:
2627
before_script:
2728
- "flake8 . --exclude test,docs,examples"
2829
# - mysql -e 'create database poulet;'
29-
script: pytest --ignore=libnmap/test/test_backend_plugin_factory.py .
30+
script: pytest --cov=libnmap/ --ignore=libnmap/test/test_backend_plugin_factory.py .
3031
after_success:
3132
coveralls
3233
deploy:

docs/conf.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
# All configuration values have a default; values that are commented out
1212
# serve to show the default.
1313

14-
import sys, os
14+
import os
15+
import sys
1516

1617
# If extensions (or modules to document with autodoc) are in another directory,
1718
# add these directories to sys.path here. If the directory is relative to the
@@ -184,7 +185,13 @@
184185
# Grouping the document tree into LaTeX files. List of tuples
185186
# (source start file, target name, title, author, documentclass [howto/manual]).
186187
latex_documents = [
187-
("index", "libnmap.tex", u"libnmap Documentation", u"Ronald Bister", "manual")
188+
(
189+
"index",
190+
"libnmap.tex",
191+
u"libnmap Documentation",
192+
u"Ronald Bister",
193+
"manual",
194+
)
188195
]
189196

190197
# The name of an image file (relative to this directory) to place at the top of
@@ -212,7 +219,9 @@
212219

213220
# One entry per manual page. List of tuples
214221
# (source start file, name, description, authors, manual section).
215-
man_pages = [("index", "libnmap", u"libnmap Documentation", [u"Ronald Bister"], 1)]
222+
man_pages = [
223+
("index", "libnmap", u"libnmap Documentation", [u"Ronald Bister"], 1)
224+
]
216225

217226
# If true, show URL addresses after external links.
218227
# man_show_urls = False

examples/elastikibana.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
from libnmap.parser import NmapParser
5-
from elasticsearch import Elasticsearch
64
from datetime import datetime
5+
76
import pygeoip
7+
from elasticsearch import Elasticsearch
8+
9+
from libnmap.parser import NmapParser
810

911

1012
def store_report(nmap_report, database, index):

examples/es_plugin.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#!/usr/bin/env python
22

3+
import json
4+
from datetime import datetime
5+
36
from libnmap.parser import NmapParser
4-
from libnmap.reportjson import ReportDecoder
57
from libnmap.plugins.es import NmapElasticsearchPlugin
6-
from datetime import datetime
7-
import json
8+
from libnmap.reportjson import ReportDecoder
89

910
nmap_report = NmapParser.parse_fromfile("libnmap/test/files/1_hosts.xml")
1011
mindex = datetime.fromtimestamp(nmap_report.started).strftime("%Y-%m-%d")

examples/json_serialize.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4+
import json
5+
46
from libnmap.parser import NmapParser
57
from libnmap.reportjson import ReportDecoder, ReportEncoder
6-
import json
78

89
nmap_report_obj = NmapParser.parse_fromfile("libnmap/test/files/1_hosts.xml")
910

examples/proc_async.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
from libnmap.process import NmapProcess
54
from time import sleep
65

6+
from libnmap.process import NmapProcess
77

88
nmap_proc = NmapProcess(targets="scanme.nmap.org", options="-sT")
99
nmap_proc.run_background()

examples/proc_nmap_like.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33

4-
from libnmap.process import NmapProcess
54
from libnmap.parser import NmapParser, NmapParserException
5+
from libnmap.process import NmapProcess
66

77

88
# start a new nmap scan on localhost with some specific options

libnmap/diff.py

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
class DictDiffer(object):
55
"""
6-
Calculate the difference between two dictionaries as:
7-
(1) items added
8-
(2) items removed
9-
(3) keys same in both but changed values
10-
(4) keys same in both and unchanged values
6+
Calculate the difference between two dictionaries as:
7+
(1) items added
8+
(2) items removed
9+
(3) keys same in both but changed values
10+
(4) keys same in both and unchanged values
1111
"""
1212

1313
def __init__(self, current_dict, past_dict):
@@ -40,35 +40,35 @@ def unchanged(self):
4040

4141
class NmapDiff(DictDiffer):
4242
"""
43-
NmapDiff compares two objects of same type to enable the user to check:
44-
45-
- what has changed
46-
- what has been added
47-
- what has been removed
48-
- what was kept unchanged
49-
50-
NmapDiff inherit from DictDiffer which makes the actual comparaison.
51-
The different methods from DictDiffer used by NmapDiff are the
52-
following:
53-
54-
- NmapDiff.changed()
55-
- NmapDiff.added()
56-
- NmapDiff.removed()
57-
- NmapDiff.unchanged()
58-
59-
Each of the returns a python set() of key which have changed in the
60-
compared objects. To check the different keys that could be returned,
61-
refer to the get_dict() method of the objects you which to
62-
compare (i.e: libnmap.objects.NmapHost, NmapService,...).
43+
NmapDiff compares two objects of same type to enable the user to check:
44+
45+
- what has changed
46+
- what has been added
47+
- what has been removed
48+
- what was kept unchanged
49+
50+
NmapDiff inherit from DictDiffer which makes the actual comparaison.
51+
The different methods from DictDiffer used by NmapDiff are the
52+
following:
53+
54+
- NmapDiff.changed()
55+
- NmapDiff.added()
56+
- NmapDiff.removed()
57+
- NmapDiff.unchanged()
58+
59+
Each of the returns a python set() of key which have changed in the
60+
compared objects. To check the different keys that could be returned,
61+
refer to the get_dict() method of the objects you which to
62+
compare (i.e: libnmap.objects.NmapHost, NmapService,...).
6363
"""
6464

6565
def __init__(self, nmap_obj1, nmap_obj2):
6666
"""
67-
Constructor of NmapDiff:
67+
Constructor of NmapDiff:
6868
69-
- Checks if the two objects are of the same class
70-
- Checks if the objects are "comparable" via a call to id() (dirty)
71-
- Inherits from DictDiffer and
69+
- Checks if the two objects are of the same class
70+
- Checks if the objects are "comparable" via a call to id() (dirty)
71+
- Inherits from DictDiffer and
7272
"""
7373
if (
7474
nmap_obj1.__class__ != nmap_obj2.__class__

libnmap/objects/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# -*- coding: utf-8 -*-
22

3-
from libnmap.objects.report import NmapReport
43
from libnmap.objects.host import NmapHost
4+
from libnmap.objects.report import NmapReport
55
from libnmap.objects.service import NmapService
66

77
__all__ = ["NmapReport", "NmapHost", "NmapService"]

libnmap/objects/cpe.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
class CPE(object):
55
"""
6-
CPE class offers an API for basic CPE objects.
7-
These objects could be found in NmapService or in <os> tag
8-
within NmapHost.
6+
CPE class offers an API for basic CPE objects.
7+
These objects could be found in NmapService or in <os> tag
8+
within NmapHost.
99
10-
:todo: interpret CPE string and provide appropriate API
10+
:todo: interpret CPE string and provide appropriate API
1111
"""
1212

1313
def __init__(self, cpestring):
@@ -29,14 +29,14 @@ def __init__(self, cpestring):
2929
@property
3030
def cpestring(self):
3131
"""
32-
Accessor for the full CPE string.
32+
Accessor for the full CPE string.
3333
"""
3434
return self._cpestring
3535

3636
@property
3737
def cpedict(self):
3838
"""
39-
Accessor for _cpedict
39+
Accessor for _cpedict
4040
"""
4141
return self._cpedict
4242

@@ -45,60 +45,60 @@ def __repr__(self):
4545

4646
def get_part(self):
4747
"""
48-
Returns the cpe part (/o, /h, /a)
48+
Returns the cpe part (/o, /h, /a)
4949
"""
5050
return self._cpedict["part"]
5151

5252
def get_vendor(self):
5353
"""
54-
Returns the vendor name
54+
Returns the vendor name
5555
"""
5656
return self._cpedict["vendor"]
5757

5858
def get_product(self):
5959
"""
60-
Returns the product name
60+
Returns the product name
6161
"""
6262
return self._cpedict["product"]
6363

6464
def get_version(self):
6565
"""
66-
Returns the version of the cpe
66+
Returns the version of the cpe
6767
"""
6868
return self._cpedict["version"]
6969

7070
def get_update(self):
7171
"""
72-
Returns the update version
72+
Returns the update version
7373
"""
7474
return self._cpedict["update"]
7575

7676
def get_edition(self):
7777
"""
78-
Returns the cpe edition
78+
Returns the cpe edition
7979
"""
8080
return self._cpedict["edition"]
8181

8282
def get_language(self):
8383
"""
84-
Returns the cpe language
84+
Returns the cpe language
8585
"""
8686
return self._cpedict["language"]
8787

8888
def is_application(self):
8989
"""
90-
Returns True if cpe describes an application
90+
Returns True if cpe describes an application
9191
"""
9292
return self.get_part() == "/a"
9393

9494
def is_hardware(self):
9595
"""
96-
Returns True if cpe describes a hardware
96+
Returns True if cpe describes a hardware
9797
"""
9898
return self.get_part() == "/h"
9999

100100
def is_operating_system(self):
101101
"""
102-
Returns True if cpe describes an operating system
102+
Returns True if cpe describes an operating system
103103
"""
104104
return self.get_part() == "/o"

0 commit comments

Comments
 (0)