Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Add .pylintrc & pylint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ojarva committed Jan 25, 2021
1 parent 775b4d7 commit 50f58a1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[format]
max-line-length=125

[messages control]
disable=line-too-long,missing-docstring,no-self-use,fixme,bad-indentation,bad-continuation,invalid-name,too-many-locals,duplicate-code,too-many-branches,wrong-import-order
5 changes: 2 additions & 3 deletions p0f/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def get_info(self, ip_address, return_raw_data=False):
values = struct.unpack(self.RESPONSE_FMT, data_received)

data_in = {}
for i in range(len(values)):
for i, value in enumerate(values):
value = values[i]
if isinstance(value, str):
value = value.replace("\x00", "")
Expand All @@ -129,7 +129,7 @@ def get_info(self, ip_address, return_raw_data=False):
status = self.RESPONSE_STATUS[data_in["status"]]
if status == self.RESPONSE_BAD_QUERY:
raise P0fException("Improperly formatted query sent to p0f")
elif status == self.RESPONSE_NO_MATCH:
if status == self.RESPONSE_NO_MATCH:
raise KeyError("No data available in p0f for %s" % ip_address)
if return_raw_data:
return data_in
Expand Down Expand Up @@ -176,7 +176,6 @@ def format_data(cls, data_in):

class P0fException(Exception):
""" Raised when server returns invalid data """
pass


def main():
Expand Down
10 changes: 5 additions & 5 deletions p0f/django/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
log = logging.getLogger(__name__)


class P0fMiddleware:
class P0fMiddleware: # pylint: disable=too-few-public-methods
""" Adds "p0f" attribute to request. Requires P0FSOCKET setting in Django settings.py """
def __init__(self):
try:
Expand All @@ -37,11 +37,11 @@ def __init__(self):

try:
settings.P0FSOCKET
except AttributeError:
except AttributeError as ex:
log.error("P0FSOCKET is not configured.")
raise ImproperlyConfigured(
"P0FSOCKET is not configured. This middleware does not run without path to p0f unix socket"
)
) from ex

def process_request(self, request):
remote_info = None
Expand All @@ -51,8 +51,8 @@ def process_request(self, request):
except socket.error as e:
log.error("p0f API call returned %r", e)
except KeyError as e:
log.warn("No data available for %s - is p0f listening the right interface?", request.META.get("REMOTE_ADDR"))
log.warning("No data available for %s - is p0f listening the right interface?", request.META.get("REMOTE_ADDR"))
except (ValueError, p0f.P0fException) as e:
log.warn("internal error: %r", e)
log.warning("internal error: %r", e)

request.p0f = remote_info

0 comments on commit 50f58a1

Please sign in to comment.