Skip to content

Commit

Permalink
Merge pull request #745 from p-l-/pylint-fixes
Browse files Browse the repository at this point in the history
Pylint fixes
  • Loading branch information
p-l- committed Aug 9, 2019
2 parents db8fd8b + 0c69fa5 commit 58f46be
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ before_script:
- export BRO_SAMPLES=`pwd`/usr/local/bro/testing
- ivre --version; echo; bro --version; echo; nmap --version

script: (test "$DB" != "maxmind" || test "$TRAVIS_PYTHON_VERSION" = 2.6 || test "$TRAVIS_PYTHON_VERSION" = 3.3 || (flake8 --ignore=F401,E402 doc/conf.py && flake8 --ignore=W504 setup.py bin/ivre && flake8 --ignore=E402,W504 tests/tests.py && flake8 --ignore=W504 ivre/ && echo "flake8 OK (except W504)")) && (test "$DB" != "maxmind" || test "$TRAVIS_PYTHON_VERSION" != 3.7 || (codespell --ignore-words=.travis/codespell_ignore `git ls-files | grep -vE '^web/static/(doc|an|bs|d3|jq|lk)/|^data/|\.(png|gif|svg)$'` && echo "codespell OK")) && (test "$DB" != "maxmind" || test "$TRAVIS_PYTHON_VERSION" != 3.7 || (pylint -e all -d abstract-method,access-member-before-definition,arguments-differ,attribute-defined-outside-init,bad-continuation,broad-except,comparison-with-callable,comprehension-escape,cyclic-import,deprecated-method,deprecated-module,dict-values-not-iterating,duplicate-code,eq-without-hash,exec-used,fixme,function-redefined,global-statement,global-variable-undefined,import-error,invalid-name,len-as-condition,locally-disabled,missing-docstring,next-method-called,no-absolute-import,no-member,non-parent-init-called,nonzero-method,no-self-use,no-value-for-parameter,old-division,protected-access,raising-format-tuple,redefined-argument-from-local,redefined-outer-name,reload-builtin,round-builtin,singleton-comparison,stop-iteration-return,subprocess-popen-preexec-fn,superfluous-parens,super-init-not-called,suppressed-message,too-few-public-methods,too-many-ancestors,too-many-arguments,too-many-boolean-expressions,too-many-branches,too-many-instance-attributes,too-many-lines,too-many-locals,too-many-nested-blocks,too-many-public-methods,too-many-return-statements,too-many-statements,unexpected-keyword-arg,ungrouped-imports,unreachable,unsubscriptable-object,unsupported-assignment-operation,unsupported-membership-test,unused-argument,useless-object-inheritance,useless-super-delegation,wrong-import-order,wrong-import-position ivre && echo "pylint OK")) && cd tests/ && coverage erase && coverage run --parallel-mode tests.py --coverage && coverage combine && coverage report
script: (test "$DB" != "maxmind" || test "$TRAVIS_PYTHON_VERSION" = 2.6 || test "$TRAVIS_PYTHON_VERSION" = 3.3 || (flake8 --ignore=F401,E402 doc/conf.py && flake8 --ignore=W504 setup.py bin/ivre && flake8 --ignore=E402,W504 tests/tests.py && flake8 --ignore=W504 ivre/ && echo "flake8 OK (except W504)")) && (test "$DB" != "maxmind" || test "$TRAVIS_PYTHON_VERSION" != 3.7 || (codespell --ignore-words=.travis/codespell_ignore `git ls-files | grep -vE '^web/static/(doc|an|bs|d3|jq|lk)/|^data/|\.(png|gif|svg)$'` && echo "codespell OK")) && (test "$DB" != "maxmind" || test "$TRAVIS_PYTHON_VERSION" != 3.7 || (pylint -e all -d abstract-method,access-member-before-definition,arguments-differ,attribute-defined-outside-init,bad-continuation,broad-except,cyclic-import,deprecated-method,deprecated-module,dict-values-not-iterating,duplicate-code,eq-without-hash,exec-used,fixme,function-redefined,global-statement,global-variable-undefined,import-error,invalid-name,locally-disabled,missing-docstring,next-method-called,no-absolute-import,no-member,non-parent-init-called,nonzero-method,no-self-use,old-division,protected-access,redefined-argument-from-local,redefined-outer-name,reload-builtin,round-builtin,singleton-comparison,subprocess-popen-preexec-fn,super-init-not-called,suppressed-message,too-few-public-methods,too-many-ancestors,too-many-arguments,too-many-boolean-expressions,too-many-branches,too-many-instance-attributes,too-many-lines,too-many-locals,too-many-nested-blocks,too-many-public-methods,too-many-return-statements,too-many-statements,unexpected-keyword-arg,unsubscriptable-object,unsupported-membership-test,unused-argument,useless-object-inheritance,useless-super-delegation,wrong-import-order,wrong-import-position ivre && echo "pylint OK")) && cd tests/ && coverage erase && coverage run --parallel-mode tests.py --coverage && coverage combine && coverage report

after_success:
- codecov
Expand Down
2 changes: 1 addition & 1 deletion ivre/activecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def _display_honeyd_conf(host, honeyd_routes, honeyd_entries, out=sys.stdout):
# let's skip pseudo-port records that are only containers for host
# scripts.
pass
if 'traces' in host and len(host['traces']) > 0:
if 'traces' in host and host['traces'] > 0:
trace = max(host['traces'], key=lambda x: len(x['hops']))['hops']
if trace:
trace.sort(key=lambda x: x['ttl'])
Expand Down
5 changes: 4 additions & 1 deletion ivre/db/maxmind.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,10 @@ def _get_fields(rec, fields):

def _get_ranges(self, fields):
gen = iter(self)
start, stop, rec = next(gen)
try:
start, stop, rec = next(gen)
except StopIteration:
return
rec = tuple(self._get_fields(rec, fields))
for n_start, n_stop, n_rec in gen:
n_rec = tuple(self._get_fields(n_rec, fields))
Expand Down
7 changes: 5 additions & 2 deletions ivre/db/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -767,8 +767,11 @@ def searchcmp(key, val, cmpop):
return {key: {'$gt': val}}
if cmpop == '>=':
return {key: {'$gte': val}}
raise Exception('Unknown operator %r (for key %r and val %r)', cmpop,
key, val)
raise Exception('Unknown operator %r (for key %r and val %r)' % (
cmpop,
key,
val,
))


class MongoDBActive(MongoDB, DBActive):
Expand Down
2 changes: 1 addition & 1 deletion ivre/db/neo4j.py
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,7 @@ def any2flow(self, bulk, name, rec):
else:
prop = k
if (prop not in rec or rec[prop] is None) and k in props:
del(props[k])
del props[k]
if kind == "flow":
flow_keys = desc.get("flow_keys")
if not flow_keys:
Expand Down
2 changes: 1 addition & 1 deletion ivre/db/sql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def searchobjectid(cls, oid, neg=False):
if isinstance(oid, (int, basestring)):
oid = [int(oid)]
else:
oid = [int(oid) for oid in oid]
oid = [int(suboid) for suboid in oid]
return cls._searchobjectid(oid, neg=neg)

@staticmethod
Expand Down
2 changes: 1 addition & 1 deletion ivre/db/sql/tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def extend_binary_expression(element, compiler, **kwargs):
if opstring == '?':
return compiler.process(func.HAS_KEY(element.left, element.right))
# FIXME: Variant base type Comparator seems to be used here.
if element.operator == json_getitem_op:
if element.operator is json_getitem_op:
return compiler.process(func.ACCESS(element.left, element.right))
return compiler.visit_binary(element)

Expand Down
1 change: 1 addition & 0 deletions ivre/tools/arp2db.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
def reader(fname):
proc = subprocess.Popen(['tcpdump', '-n', '-r', fname, '-w', '-', 'arp'],
stdout=subprocess.PIPE)
# pylint: disable=no-value-for-parameter
return PcapReader(proc.stdout)


Expand Down
2 changes: 1 addition & 1 deletion ivre/tools/ipinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def my_parse_args():
sort = [(field[1:], -1) if field.startswith('~') else (field, 1)
for field in args.sort]
if not args.ips:
if not baseflt and not args.limit and disp_recs == disp_recs_std:
if not baseflt and not args.limit and disp_recs is disp_recs_std:
# default to tail -f mode
disp_recs = disp_recs_tailfnew()
disp_recs(baseflt, sort, args.limit or db.passive.no_limit,
Expand Down
5 changes: 2 additions & 3 deletions ivre/tools/runscans.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from __future__ import print_function
import atexit
import fcntl
from functools import reduce
import functools
import multiprocessing
import os
import re
Expand All @@ -50,7 +50,6 @@


if sys.version_info >= (2, 7):
import functools
USE_PARTIAL = True
else:
# Python version <= 2.6:
Expand Down Expand Up @@ -419,7 +418,7 @@ def main():
parser.error('one argument of --country/--region/--city/--asnum/'
'--range/--network/--routable/--file/--test is required')
if args.again is not None:
accept_target_status = set(reduce(
accept_target_status = set(functools.reduce(
lambda x, y: x + y, [{
'up': [STATUS_DONE_UP],
'down': [STATUS_DONE_DOWN],
Expand Down
20 changes: 10 additions & 10 deletions ivre/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ def _extract_passive_HTTP_CLIENT_HEADER_SERVER(rec):
}]}
# TODO: (?) handle Host: header for DNS
# FIXME: catches ip addresses as domain name.
if 'source' in rec and rec['source'] == 'HOST':
values = rec['value'].split(".")
domains = [values.pop()]
while values:
domains.insert(0, values.pop() + "." + domains[0])
return {'hostnames': [{'domains': domains,
'type': "?",
'name': domains[0]}]}
# if 'source' in rec and rec['source'] == 'HOST':
# values = rec['value'].split(".")
# domains = [values.pop()]
# while values:
# domains.insert(0, values.pop() + "." + domains[0])
# return {'hostnames': [{'domains': domains,
# 'type': "?",
# 'name': domains[0]}]}


def _extract_passive_HTTP_SERVER_HEADER(rec):
Expand Down Expand Up @@ -311,7 +311,7 @@ def from_passive(flt):
"""Iterator over passive results, by address."""
records = passive_to_view(flt)
cur_addr = None
cur_rec = None
cur_rec = {}
for rec in records:
if cur_addr is None:
cur_addr = rec['addr']
Expand All @@ -328,7 +328,7 @@ def from_passive(flt):
cur_addr = rec['addr']
else:
cur_rec = db.view.merge_host_docs(cur_rec, rec)
if cur_rec is not None:
if cur_rec:
yield cur_rec


Expand Down

0 comments on commit 58f46be

Please sign in to comment.