Skip to content

Commit

Permalink
another run of py-black with updated version + isort + fix travis
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Bister committed Nov 25, 2020
1 parent fbded5d commit 286f00e
Show file tree
Hide file tree
Showing 42 changed files with 744 additions and 703 deletions.
3 changes: 2 additions & 1 deletion .travis.yml
Expand Up @@ -18,6 +18,7 @@ install:
- "pip install flake8"
- "pip install defusedxml"
- "pip install pytest"
- "pip install pytest-cov"
# - "pip install boto" # disabled: since boto not supporting py3
# - "pip install pymongo sqlalchemy MySQL-python" # disabled MySQL-python (not py3 compatible)
# - "pip install pymongo sqlalchemy pymysql"
Expand All @@ -26,7 +27,7 @@ install:
before_script:
- "flake8 . --exclude test,docs,examples"
# - mysql -e 'create database poulet;'
script: pytest --ignore=libnmap/test/test_backend_plugin_factory.py .
script: pytest --cov=libnmap/ --ignore=libnmap/test/test_backend_plugin_factory.py .
after_success:
coveralls
deploy:
Expand Down
15 changes: 12 additions & 3 deletions docs/conf.py
Expand Up @@ -11,7 +11,8 @@
# All configuration values have a default; values that are commented out
# serve to show the default.

import sys, os
import os
import sys

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down Expand Up @@ -184,7 +185,13 @@
# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title, author, documentclass [howto/manual]).
latex_documents = [
("index", "libnmap.tex", u"libnmap Documentation", u"Ronald Bister", "manual")
(
"index",
"libnmap.tex",
u"libnmap Documentation",
u"Ronald Bister",
"manual",
)
]

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

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [("index", "libnmap", u"libnmap Documentation", [u"Ronald Bister"], 1)]
man_pages = [
("index", "libnmap", u"libnmap Documentation", [u"Ronald Bister"], 1)
]

# If true, show URL addresses after external links.
# man_show_urls = False
Expand Down
6 changes: 4 additions & 2 deletions examples/elastikibana.py
@@ -1,10 +1,12 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from libnmap.parser import NmapParser
from elasticsearch import Elasticsearch
from datetime import datetime

import pygeoip
from elasticsearch import Elasticsearch

from libnmap.parser import NmapParser


def store_report(nmap_report, database, index):
Expand Down
7 changes: 4 additions & 3 deletions examples/es_plugin.py
@@ -1,10 +1,11 @@
#!/usr/bin/env python

import json
from datetime import datetime

from libnmap.parser import NmapParser
from libnmap.reportjson import ReportDecoder
from libnmap.plugins.es import NmapElasticsearchPlugin
from datetime import datetime
import json
from libnmap.reportjson import ReportDecoder

nmap_report = NmapParser.parse_fromfile("libnmap/test/files/1_hosts.xml")
mindex = datetime.fromtimestamp(nmap_report.started).strftime("%Y-%m-%d")
Expand Down
3 changes: 2 additions & 1 deletion examples/json_serialize.py
@@ -1,9 +1,10 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import json

from libnmap.parser import NmapParser
from libnmap.reportjson import ReportDecoder, ReportEncoder
import json

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

Expand Down
2 changes: 1 addition & 1 deletion examples/proc_async.py
@@ -1,9 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from libnmap.process import NmapProcess
from time import sleep

from libnmap.process import NmapProcess

nmap_proc = NmapProcess(targets="scanme.nmap.org", options="-sT")
nmap_proc.run_background()
Expand Down
2 changes: 1 addition & 1 deletion examples/proc_nmap_like.py
@@ -1,8 +1,8 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from libnmap.process import NmapProcess
from libnmap.parser import NmapParser, NmapParserException
from libnmap.process import NmapProcess


# start a new nmap scan on localhost with some specific options
Expand Down
58 changes: 29 additions & 29 deletions libnmap/diff.py
Expand Up @@ -3,11 +3,11 @@

class DictDiffer(object):
"""
Calculate the difference between two dictionaries as:
(1) items added
(2) items removed
(3) keys same in both but changed values
(4) keys same in both and unchanged values
Calculate the difference between two dictionaries as:
(1) items added
(2) items removed
(3) keys same in both but changed values
(4) keys same in both and unchanged values
"""

def __init__(self, current_dict, past_dict):
Expand Down Expand Up @@ -40,35 +40,35 @@ def unchanged(self):

class NmapDiff(DictDiffer):
"""
NmapDiff compares two objects of same type to enable the user to check:
- what has changed
- what has been added
- what has been removed
- what was kept unchanged
NmapDiff inherit from DictDiffer which makes the actual comparaison.
The different methods from DictDiffer used by NmapDiff are the
following:
- NmapDiff.changed()
- NmapDiff.added()
- NmapDiff.removed()
- NmapDiff.unchanged()
Each of the returns a python set() of key which have changed in the
compared objects. To check the different keys that could be returned,
refer to the get_dict() method of the objects you which to
compare (i.e: libnmap.objects.NmapHost, NmapService,...).
NmapDiff compares two objects of same type to enable the user to check:
- what has changed
- what has been added
- what has been removed
- what was kept unchanged
NmapDiff inherit from DictDiffer which makes the actual comparaison.
The different methods from DictDiffer used by NmapDiff are the
following:
- NmapDiff.changed()
- NmapDiff.added()
- NmapDiff.removed()
- NmapDiff.unchanged()
Each of the returns a python set() of key which have changed in the
compared objects. To check the different keys that could be returned,
refer to the get_dict() method of the objects you which to
compare (i.e: libnmap.objects.NmapHost, NmapService,...).
"""

def __init__(self, nmap_obj1, nmap_obj2):
"""
Constructor of NmapDiff:
Constructor of NmapDiff:
- Checks if the two objects are of the same class
- Checks if the objects are "comparable" via a call to id() (dirty)
- Inherits from DictDiffer and
- Checks if the two objects are of the same class
- Checks if the objects are "comparable" via a call to id() (dirty)
- Inherits from DictDiffer and
"""
if (
nmap_obj1.__class__ != nmap_obj2.__class__
Expand Down
2 changes: 1 addition & 1 deletion libnmap/objects/__init__.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

from libnmap.objects.report import NmapReport
from libnmap.objects.host import NmapHost
from libnmap.objects.report import NmapReport
from libnmap.objects.service import NmapService

__all__ = ["NmapReport", "NmapHost", "NmapService"]
32 changes: 16 additions & 16 deletions libnmap/objects/cpe.py
Expand Up @@ -3,11 +3,11 @@

class CPE(object):
"""
CPE class offers an API for basic CPE objects.
These objects could be found in NmapService or in <os> tag
within NmapHost.
CPE class offers an API for basic CPE objects.
These objects could be found in NmapService or in <os> tag
within NmapHost.
:todo: interpret CPE string and provide appropriate API
:todo: interpret CPE string and provide appropriate API
"""

def __init__(self, cpestring):
Expand All @@ -29,14 +29,14 @@ def __init__(self, cpestring):
@property
def cpestring(self):
"""
Accessor for the full CPE string.
Accessor for the full CPE string.
"""
return self._cpestring

@property
def cpedict(self):
"""
Accessor for _cpedict
Accessor for _cpedict
"""
return self._cpedict

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

def get_part(self):
"""
Returns the cpe part (/o, /h, /a)
Returns the cpe part (/o, /h, /a)
"""
return self._cpedict["part"]

def get_vendor(self):
"""
Returns the vendor name
Returns the vendor name
"""
return self._cpedict["vendor"]

def get_product(self):
"""
Returns the product name
Returns the product name
"""
return self._cpedict["product"]

def get_version(self):
"""
Returns the version of the cpe
Returns the version of the cpe
"""
return self._cpedict["version"]

def get_update(self):
"""
Returns the update version
Returns the update version
"""
return self._cpedict["update"]

def get_edition(self):
"""
Returns the cpe edition
Returns the cpe edition
"""
return self._cpedict["edition"]

def get_language(self):
"""
Returns the cpe language
Returns the cpe language
"""
return self._cpedict["language"]

def is_application(self):
"""
Returns True if cpe describes an application
Returns True if cpe describes an application
"""
return self.get_part() == "/a"

def is_hardware(self):
"""
Returns True if cpe describes a hardware
Returns True if cpe describes a hardware
"""
return self.get_part() == "/h"

def is_operating_system(self):
"""
Returns True if cpe describes an operating system
Returns True if cpe describes an operating system
"""
return self.get_part() == "/o"

0 comments on commit 286f00e

Please sign in to comment.