Permalink
Browse files

STY: pycodestyle 2.4.0 required changes

  • Loading branch information...
wagner-certat committed Apr 16, 2018
1 parent 1a6725e commit 7ea16c9f6edb06bdf55f8e11f8d59b388f189b62
@@ -4,6 +4,8 @@ CHANGELOG
1.0.4 Bugfix release (unreleased)
---------------------------------
- make code style compatible to pycodestyle 2.4.0
### Contrib
### Core
@@ -304,7 +304,7 @@ def __status_process(self, pid, module):
class IntelMQController():
def __init__(self, interactive: bool=False, return_type: str="python", quiet: bool=False):
def __init__(self, interactive: bool = False, return_type: str = "python", quiet: bool = False):
"""
Initializes intelmqctl.
@@ -34,7 +34,7 @@ def process(self):
if (self.parameters.subject_regex and
not re.search(self.parameters.subject_regex,
re.sub("\r\n\s", " ", message.subject))):
re.sub(r"\r\n\s", " ", message.subject))):
continue
for attach in message.attachments:
@@ -43,7 +43,7 @@ def process(self):
if (self.parameters.subject_regex and
not re.search(self.parameters.subject_regex,
re.sub("\r\n\s", " ", message.subject))):
re.sub(r"\r\n\s", " ", message.subject))):
continue
erroneous = False # If errors occured this will be set to true.
@@ -33,14 +33,14 @@ def process(self):
# Get IP and Type
info1 = re.search(
">[\ ]*(\d+\.\d+\.\d+\.\d+)[\ ]*<.*</td><td>([^<]+)</td>", row)
r">[\ ]*(\d+\.\d+\.\d+\.\d+)[\ ]*<.*</td><td>([^<]+)</td>", row)
if not info1:
continue
# Get Timestamp
info2 = re.search(
"<td>[\ ]*(\d{4}-\d{2}-\d{2}\ \d{2}:\d{2}:\d{2})[\ ]*</td>",
r"<td>[\ ]*(\d{4}-\d{2}-\d{2}\ \d{2}:\d{2}:\d{2})[\ ]*</td>",
row)
event = self.new_event(report)
@@ -116,9 +116,9 @@ def init(self):
def shutdown(self):
pass
def start(self, starting: bool=True, error_on_pipeline: bool=True,
error_on_message: bool=False, source_pipeline: Optional[str]=None,
destination_pipeline: Optional[str]=None):
def start(self, starting: bool = True, error_on_pipeline: bool = True,
error_on_message: bool = False, source_pipeline: Optional[str] = None,
destination_pipeline: Optional[str] = None):
self.__source_pipeline = source_pipeline
self.__destination_pipeline = destination_pipeline
@@ -259,7 +259,7 @@ def __sleep(self):
self.__handle_sighup()
remaining = self.parameters.rate_limit - (time.time() - starttime)
def stop(self, exitcode: int=1):
def stop(self, exitcode: int = 1):
try:
self.shutdown()
except BaseException:
@@ -289,11 +289,11 @@ def __print_log_buffer(self):
self.__log_buffer = []
def __check_bot_id(self, name: str):
res = re.search('[^0-9a-zA-Z\-]+', name)
res = re.search(r'[^0-9a-zA-Z\-]+', name)
if res:
self.__log_buffer.append(('error',
"Invalid bot id, must match '"
"[^0-9a-zA-Z\-]+'."))
r"[^0-9a-zA-Z\-]+'."))
self.stop()
def __connect_pipelines(self):
@@ -18,7 +18,7 @@
class Cache():
def __init__(self, host: str, port: int, db: str, ttl: int,
password: Optional[str]=None):
password: Optional[str] = None):
if host.startswith("/"):
kwargs = {"unix_socket_path": host}
@@ -45,7 +45,7 @@ def get(self, key: str):
return utils.decode(retval)
return retval
def set(self, key: str, value: Any, ttl: Optional[int]=None):
def set(self, key: str, value: Any, ttl: Optional[int] = None):
if ttl is None:
ttl = self.ttl
if isinstance(value, str):
@@ -28,7 +28,7 @@ class MessageFactory(object):
@staticmethod
def from_dict(message: dict, harmonization=None,
default_type: Optional[str]=None) -> dict:
default_type: Optional[str] = None) -> dict:
"""
Takes dictionary Message object, returns instance of correct class.
@@ -54,8 +54,8 @@ def from_dict(message: dict, harmonization=None,
return class_reference(message, auto=True, harmonization=harmonization)
@staticmethod
def unserialize(raw_message: str, harmonization: dict=None,
default_type: Optional[str]=None) -> dict:
def unserialize(raw_message: str, harmonization: dict = None,
default_type: Optional[str] = None) -> dict:
"""
Takes JSON-encoded Message object, returns instance of correct class.
@@ -118,7 +118,7 @@ def __init__(self, message=(), auto=False, harmonization=None):
def __setitem__(self, key, value):
self.add(key, value)
def is_valid(self, key: str, value: str, sanitize: bool=True) -> bool:
def is_valid(self, key: str, value: str, sanitize: bool = True) -> bool:
"""
Checks if a value is valid for the key (after sanitation).
@@ -147,9 +147,9 @@ def is_valid(self, key: str, value: str, sanitize: bool=True) -> bool:
return True
return False
def add(self, key: str, value: str, sanitize: bool=True,
overwrite: bool=False, ignore: Sequence=(),
raise_failure: bool=True) -> bool:
def add(self, key: str, value: str, sanitize: bool = True,
overwrite: bool = False, ignore: Sequence = (),
raise_failure: bool = True) -> bool:
"""
Add a value for the key (after sanitation).
@@ -217,7 +217,7 @@ def update(self, other: dict):
if not self.add(key, value, sanitize=False, raise_failure=False, overwrite=True):
self.add(key, value, sanitize=True, overwrite=True)
def change(self, key: str, value: str, sanitize: bool=True):
def change(self, key: str, value: str, sanitize: bool = True):
if key not in self:
raise exceptions.KeyNotExists(key)
return self.add(key, value, overwrite=True, sanitize=sanitize)
@@ -327,7 +327,7 @@ def hash(self, *, filter_keys=frozenset(), filter_type="blacklist"):
return event_hash.hexdigest()
def to_dict(self, hierarchical: bool=False, with_type: bool=False):
def to_dict(self, hierarchical: bool = False, with_type: bool = False):
json_dict = dict()
if with_type:
@@ -362,8 +362,8 @@ def to_json(self, hierarchical=False, with_type=False):
class Event(Message):
def __init__(self, message: Optional[dict]=(), auto: bool=False,
harmonization: Optional[dict]=None):
def __init__(self, message: Optional[dict] = (), auto: bool = False,
harmonization: Optional[dict] = None):
"""
Parameters:
message: Give a report and feed.name, feed.url and
@@ -397,8 +397,8 @@ def __init__(self, message: Optional[dict]=(), auto: bool=False,
class Report(Message):
def __init__(self, message: Optional[dict]=(), auto: bool=False,
harmonization: Optional[dict]=None):
def __init__(self, message: Optional[dict] = (), auto: bool = False,
harmonization: Optional[dict] = None):
"""
Parameters:
message: Passed along to Message's and dict's init
@@ -214,7 +214,7 @@ class Parameters(object):
if self.default_input_message: # None for collectors
self.input_queue = [self.default_input_message]
def run_bot(self, iterations: int=1, error_on_pipeline: bool=False, prepare=True):
def run_bot(self, iterations: int = 1, error_on_pipeline: bool = False, prepare=True):
"""
Call this method for actually doing a test run for the specified bot.
@@ -259,8 +259,8 @@ def run_bot(self, iterations: int=1, error_on_pipeline: bool=False, prepare=True
""" Test if bot log messages are correctly formatted. """
self.assertLoglineMatches(0, "{} initialized with id {} and intelmq [0-9a-z.]* and python"
" [0-9a-z.]{{5,8}}\+? \([a-zA-Z0-9,:. ]+\)( \[GCC\])?"
" as process [0-9]+\."
r" [0-9a-z.]{{5,8}}\+? \([a-zA-Z0-9,:. ]+\)( \[GCC\])?"
r" as process [0-9]+\."
"".format(self.bot_name,
self.bot_id), "INFO")
self.assertRegexpMatchesLog("INFO - Bot is starting.")
@@ -325,7 +325,7 @@ def test_bot_name(self):
self.assertEqual('Test{}'.format(self.bot_name),
self.__class__.__name__)
def assertAnyLoglineEqual(self, message: str, levelname: str="ERROR"):
def assertAnyLoglineEqual(self, message: str, levelname: str = "ERROR"):
"""
Asserts if any logline matches a specific requirement.
@@ -347,7 +347,7 @@ def assertAnyLoglineEqual(self, message: str, levelname: str="ERROR"):
raise ValueError('Logline with level {!r} and message {!r} not found'
''.format(levelname, message))
def assertLoglineEqual(self, line_no: int, message: str, levelname: str="ERROR"):
def assertLoglineEqual(self, line_no: int, message: str, levelname: str = "ERROR"):
"""
Asserts if a logline matches a specific requirement.
@@ -368,7 +368,7 @@ def assertLoglineEqual(self, line_no: int, message: str, levelname: str="ERROR")
self.assertEqual(levelname, fields["log_level"])
self.assertEqual(message, fields["message"])
def assertLoglineMatches(self, line_no: int, pattern: str, levelname: str="ERROR"):
def assertLoglineMatches(self, line_no: int, pattern: str, levelname: str = "ERROR"):
"""
Asserts if a logline matches a specific requirement.
@@ -389,7 +389,7 @@ def assertLoglineMatches(self, line_no: int, pattern: str, levelname: str="ERROR
self.assertEqual(levelname, fields["log_level"])
self.assertRegex(fields["message"], pattern)
def assertLogMatches(self, pattern: str, levelname: str="ERROR"):
def assertLogMatches(self, pattern: str, levelname: str = "ERROR"):
"""
Asserts if any logline matches a specific requirement.
@@ -41,16 +41,16 @@
r' (?P<bot_id>([-\w]+|py\.warnings)) - '
r'(?P<log_level>[A-Z]+) - '
r'(?P<message>.+)$')
SYSLOG_REGEX = ('^(?P<date>\w{3} \d{2} \d{2}:\d{2}:\d{2}) (?P<hostname>[-\.\w]+) '
'(?P<bot_id>([-\w]+|py\.warnings)): (?P<log_level>[A-Z]+) (?P<message>.+)$')
SYSLOG_REGEX = (r'^(?P<date>\w{3} \d{2} \d{2}:\d{2}:\d{2}) (?P<hostname>[-\.\w]+) '
r'(?P<bot_id>([-\w]+|py\.warnings)): (?P<log_level>[A-Z]+) (?P<message>.+)$')
class Parameters(object):
pass
def decode(text: Union[bytes, str], encodings: Sequence[str]=("utf-8", ),
force: bool=False) -> str:
def decode(text: Union[bytes, str], encodings: Sequence[str] = ("utf-8", ),
force: bool = False) -> str:
"""
Decode given string to UTF-8 (default).
@@ -85,8 +85,8 @@ def decode(text: Union[bytes, str], encodings: Sequence[str]=("utf-8", ),
".".format(encodings))
def encode(text: Union[bytes, str], encodings: Sequence[str]=("utf-8", ),
force: bool=False) -> str:
def encode(text: Union[bytes, str], encodings: Sequence[str] = ("utf-8", ),
force: bool = False) -> str:
"""
Encode given string from UTF-8 (default).
@@ -213,8 +213,8 @@ def emit(self, record):
self.handleError(record)
def log(name: str, log_path: str=intelmq.DEFAULT_LOGGING_PATH, log_level: str="DEBUG",
stream: Optional[object]=None, syslog: Union[bool, str, list, tuple]=None):
def log(name: str, log_path: str = intelmq.DEFAULT_LOGGING_PATH, log_level: str = "DEBUG",
stream: Optional[object] = None, syslog: Union[bool, str, list, tuple] = None):
"""
Returns a logger instance logging to file and sys.stderr or other stream.
The warnings module will log to the same handlers.
@@ -303,7 +303,7 @@ def reverse_readline(filename: str, buf_size=100000) -> str:
yield line[::-1]
def parse_logline(logline: str, regex: str=LOG_REGEX) -> dict:
def parse_logline(logline: str, regex: str = LOG_REGEX) -> dict:
"""
Parses the given logline string into its components.
@@ -17,7 +17,7 @@ ignore = E221, E722
max-line-length = 132
[pycodestyle]
ignore = E221, E722
ignore = E221, E722, W504
max-line-length = 132
[metadata]

0 comments on commit 7ea16c9

Please sign in to comment.