Skip to content

Commit 36d7940

Browse files
Sebastian WagnerWagner
authored andcommitted
BUG: lib/bot: ParserBot: mark internal variables correctly
the internal variable handle and current_line were not prefixed with an underscore, so they were detected as parameters.
1 parent d336dc0 commit 36d7940

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

intelmq/bots/parsers/zoneh/parser.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def parse_line(self, row, report):
2424
event.add('classification.type', 'unauthorised-information-modification')
2525
event.add('event_description.text', 'defacement')
2626
event.add('time.source', row["add_date"] + ' UTC')
27-
event.add('raw', self.recover_line(self.current_line))
27+
event.add('raw', self.recover_line())
2828
event.add('source.ip', row["ip_address"], raise_failure=False)
2929
event.add('source.fqdn', parsed_url.netloc, raise_failure=False)
3030
event.add('source.geolocation.cc', row["country_code"],

intelmq/lib/bot.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -925,8 +925,8 @@ def _create_argparser(cls):
925925
class ParserBot(Bot):
926926
_csv_params = {}
927927
_ignore_lines_starting = []
928-
handle = None
929-
current_line = None
928+
_handle = None
929+
_current_line = None
930930

931931
def __init__(self, bot_id: str, start: bool = False, sighup_event=None,
932932
disable_multithreading: bool = None):
@@ -947,9 +947,9 @@ def parse_csv(self, report: libmessage.Report):
947947
raw_report = '\n'.join([line for line in raw_report.splitlines()
948948
if not any([line.startswith(prefix) for prefix
949949
in self._ignore_lines_starting])])
950-
self.handle = RewindableFileHandle(io.StringIO(raw_report))
951-
for line in csv.reader(self.handle, **self._csv_params):
952-
self.current_line = self.handle.current_line
950+
self._handle = RewindableFileHandle(io.StringIO(raw_report))
951+
for line in csv.reader(self._handle, **self._csv_params):
952+
self._current_line = self._handle.current_line
953953
yield line
954954

955955
def parse_csv_dict(self, report: libmessage.Report):
@@ -962,15 +962,15 @@ def parse_csv_dict(self, report: libmessage.Report):
962962
raw_report = '\n'.join([line for line in raw_report.splitlines()
963963
if not any([line.startswith(prefix) for prefix
964964
in self._ignore_lines_starting])])
965-
self.handle = RewindableFileHandle(io.StringIO(raw_report))
965+
self._handle = RewindableFileHandle(io.StringIO(raw_report))
966966

967-
csv_reader = csv.DictReader(self.handle, **self._csv_params)
967+
csv_reader = csv.DictReader(self._handle, **self._csv_params)
968968
# create an array of fieldnames,
969969
# those were automagically created by the dictreader
970970
self.csv_fieldnames = csv_reader.fieldnames
971971

972972
for line in csv_reader:
973-
self.current_line = self.handle.current_line
973+
self._current_line = self._handle.current_line
974974
yield line
975975

976976
def parse_json(self, report: libmessage.Report):
@@ -987,7 +987,7 @@ def parse_json_stream(self, report: libmessage.Report):
987987
"""
988988
raw_report: str = utils.base64_decode(report.get("raw"))
989989
for line in raw_report.splitlines():
990-
self.current_line = line
990+
self._current_line = line
991991
yield json.loads(line)
992992

993993
def parse(self, report: libmessage.Report):
@@ -1077,14 +1077,14 @@ def recover_line(self, line: Optional[str] = None) -> str:
10771077
----------
10781078
line : Optional[str], optional
10791079
The currently process line which should be transferred into it's
1080-
original appearance. As fallback, "self.current_line" is used if
1080+
original appearance. As fallback, "self._current_line" is used if
10811081
available (depending on self.parse).
10821082
The default is None.
10831083
10841084
Raises
10851085
------
10861086
ValueError
1087-
If neither the parameter "line" nor the member "self.current_line"
1087+
If neither the parameter "line" nor the member "self._current_line"
10881088
is available.
10891089
10901090
Returns
@@ -1093,14 +1093,14 @@ def recover_line(self, line: Optional[str] = None) -> str:
10931093
The reconstructed raw data.
10941094
10951095
"""
1096-
if self.handle and self.handle.first_line and not self.tempdata:
1097-
tempdata = [self.handle.first_line.strip()]
1096+
if self._handle and self._handle.first_line and not self.tempdata:
1097+
tempdata = [self._handle.first_line.strip()]
10981098
else:
10991099
tempdata = self.tempdata
1100-
if not line and not self.current_line:
1100+
if not line and not self._current_line:
11011101
raise ValueError('Parameter "line" is not given and '
1102-
'"self.current_line" is also None. Please give one of them.')
1103-
line = line if line else self.current_line
1102+
'"self._current_line" is also None. Please give one of them.')
1103+
line = line if line else self._current_line
11041104
return '\n'.join(tempdata + [line])
11051105

11061106
def recover_line_csv(self, line: str) -> str:
@@ -1117,7 +1117,7 @@ def recover_line_csv_dict(self, line: str) -> str:
11171117
out = io.StringIO()
11181118
writer = csv.DictWriter(out, self.csv_fieldnames, **self._csv_params)
11191119
writer.writeheader()
1120-
out.write(self.current_line)
1120+
out.write(self._current_line)
11211121

11221122
return out.getvalue().strip()
11231123

@@ -1142,7 +1142,7 @@ def recover_line_json_stream(self, line=None) -> str:
11421142
str
11431143
unparsed JSON line.
11441144
"""
1145-
return self.current_line
1145+
return self._current_line
11461146

11471147

11481148
class CollectorBot(Bot):

0 commit comments

Comments
 (0)