Skip to content

Commit

Permalink
Merge pull request #752 from p-l-/pylint-fixes
Browse files Browse the repository at this point in the history
Pylint: fix deprecated-method & redefined-outer-name
  • Loading branch information
p-l- committed Aug 15, 2019
2 parents abd97de + ca72964 commit 592549d
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 28 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,arguments-differ,attribute-defined-outside-init,bad-continuation,broad-except,cyclic-import,deprecated-method,deprecated-module,duplicate-code,exec-used,fixme,function-redefined,global-statement,global-variable-undefined,import-error,invalid-name,locally-disabled,missing-docstring,no-absolute-import,no-member,non-parent-init-called,no-self-use,old-division,protected-access,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,unsubscriptable-object,unsupported-membership-test,unused-argument,useless-object-inheritance,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,arguments-differ,attribute-defined-outside-init,bad-continuation,broad-except,cyclic-import,deprecated-module,duplicate-code,exec-used,fixme,function-redefined,global-statement,global-variable-undefined,import-error,invalid-name,locally-disabled,missing-docstring,no-absolute-import,no-member,non-parent-init-called,no-self-use,old-division,protected-access,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,unsubscriptable-object,unsupported-membership-test,unused-argument,useless-object-inheritance,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
26 changes: 13 additions & 13 deletions ivre/activecli.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,13 +461,13 @@ def displayfunction_gnmap(cur):
_display_gnmap_host(h, out=sys.stdout)


def displayfunction_explain(flt, db):
sys.stdout.write(db.explain(db._get(flt), indent=4) + '\n')
def displayfunction_explain(flt, dbase):
sys.stdout.write(dbase.explain(dbase._get(flt), indent=4) + '\n')


def displayfunction_remove(cur, db):
def displayfunction_remove(cur, dbase):
for h in cur:
db.remove(h)
dbase.remove(h)


def displayfunction_graphroute(cur, arg, gr_include, gr_dont_reset):
Expand Down Expand Up @@ -548,7 +548,7 @@ def displayfunction_csv(cur, arg, csv_sep, csv_na_str, add_infos):
_displayhost_csv(fields, csv_sep, csv_na_str, h, out=sys.stdout)


def displayfunction_json(cur, db, no_screenshots=False):
def displayfunction_json(cur, dbase, no_screenshots=False):
if os.isatty(sys.stdout.fileno()):
indent = 4
else:
Expand All @@ -566,24 +566,24 @@ def displayfunction_json(cur, db, no_screenshots=False):
del port[fname]
elif 'screendata' in port:
port['screendata'] = utils.encode_b64(
db.from_binary(port['screendata'])
dbase.from_binary(port['screendata'])
)
for script in port.get('scripts', []):
if 'masscan' in script and 'raw' in script['masscan']:
script['masscan']['raw'] = utils.encode_b64(
db.from_binary(
dbase.from_binary(
script['masscan']['raw']
)
)
print(json.dumps(h, indent=indent,
default=db.serialize))
default=dbase.serialize))


def display_short(db, flt, srt, lmt, skp):
for val in db.distinct("addr", flt=flt, sort=srt, limit=lmt, skip=skp):
sys.stdout.write(db.internal2ip(val) + '\n')
def display_short(dbase, flt, srt, lmt, skp):
for val in dbase.distinct("addr", flt=flt, sort=srt, limit=lmt, skip=skp):
sys.stdout.write(dbase.internal2ip(val) + '\n')


def display_distinct(db, arg, flt, srt, lmt, skp):
for val in db.distinct(arg, flt=flt, sort=srt, limit=lmt, skip=skp):
def display_distinct(dbase, arg, flt, srt, lmt, skp):
for val in dbase.distinct(arg, flt=flt, sort=srt, limit=lmt, skip=skp):
sys.stdout.write(str(val) + '\n')
7 changes: 3 additions & 4 deletions ivre/db/mongo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5138,11 +5138,10 @@ def _edge2json_flow_map(row):
Returns a dict representing an edge in flow map graph output.
row must be a flow entry.
"""
flow = ()
if row.get('proto') in ['udp', 'tcp']:
flow = (row.get('proto'), row.get('dport'))
flowkey = (row.get('proto'), row.get('dport'))
else:
flow = (row.get('proto'), None)
flowkey = (row.get('proto'), None)
res = {
"id": str(row.get('_id')),
"label": "MERGED_FLOWS",
Expand All @@ -5151,7 +5150,7 @@ def _edge2json_flow_map(row):
"target": row.get('dst_addr'),
"data": {
"count": 1,
"flows": [flow]
"flows": [flowkey]
}
}
return res
Expand Down
2 changes: 2 additions & 0 deletions ivre/db/neo4j.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
"""

# This module should disappear soon
# pylint: disable=redefined-outer-name

from datetime import datetime, time as dtime
import operator
Expand Down
8 changes: 0 additions & 8 deletions ivre/mathutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
"""


from fractions import gcd


def genprimes():
'''Yields the sequence of prime numbers via the Sieve of Eratosthenes.
Expand Down Expand Up @@ -59,8 +56,3 @@ def factors(n):
if p * p > n:
yield n
break


if __name__ == '__main__':
# Use gcd() here to avoid "unused import / variable" warnings
gcd(1, 2)
2 changes: 1 addition & 1 deletion ivre/parser/bro.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def parse_header_line(self, line):
if line.startswith(b'#separator '):
keyval = [b'separator', line[11:]]
else:
LOGGER.warn("Invalid header line")
LOGGER.warning("Invalid header line")
return

directive = keyval[0]
Expand Down
7 changes: 6 additions & 1 deletion ivre/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@


from functools import reduce
try:
from math import gcd
except ImportError:
from fractions import gcd
import os
import random
import re
Expand Down Expand Up @@ -91,7 +95,8 @@ def __init__(self, target, rand=True, state=None):
self.previous = random.randint(0, self.lcg_m - 1)
# GCD(c, m) == 1
self.lcg_c = random.randint(1, self.lcg_m - 1)
while mathutils.gcd(self.lcg_c, self.lcg_m) != 1:
# pylint: disable=deprecated-method
while gcd(self.lcg_c, self.lcg_m) != 1:
self.lcg_c = random.randint(1, self.lcg_m - 1)
# a - 1 is divisible by all prime factors of m
mfactors = reduce(lambda x, y: x * y,
Expand Down

0 comments on commit 592549d

Please sign in to comment.