Added is_valid method to readers.
detect_format now takes in optional compression type.
This commit is contained in:
parent
5573d7ef7d
commit
d6597bdc22
|
@ -344,7 +344,7 @@ class Core(CorePluginBase):
|
||||||
:raises UnknownFormatError: if the format cannot be detected
|
:raises UnknownFormatError: if the format cannot be detected
|
||||||
"""
|
"""
|
||||||
self.config["list_compression"] = detect_compression(blocklist)
|
self.config["list_compression"] = detect_compression(blocklist)
|
||||||
self.config["list_type"] = detect_format(blocklist)
|
self.config["list_type"] = detect_format(blocklist, self.config["list_compression"])
|
||||||
if not self.config["list_type"]:
|
if not self.config["list_type"]:
|
||||||
self.config["list_compression"] = ""
|
self.config["list_compression"] = ""
|
||||||
raise UnknownFormatError
|
raise UnknownFormatError
|
||||||
|
|
|
@ -48,6 +48,6 @@ def detect_compression(filename):
|
||||||
f.close()
|
f.close()
|
||||||
return COMPRESSION_TYPES.get(magic_number, "")
|
return COMPRESSION_TYPES.get(magic_number, "")
|
||||||
|
|
||||||
def detect_format(filename):
|
def detect_format(filename, compression=""):
|
||||||
# TODO: implement this function
|
# TODO: implement this function
|
||||||
return ""
|
return ""
|
||||||
|
|
|
@ -60,6 +60,21 @@ class BaseReader(object):
|
||||||
"""Ignore commented lines and blank lines"""
|
"""Ignore commented lines and blank lines"""
|
||||||
return line.startswith('#') or not line.strip()
|
return line.startswith('#') or not line.strip()
|
||||||
|
|
||||||
|
def is_valid(self, file):
|
||||||
|
"""Determines whether file is valid for this reader"""
|
||||||
|
blocklist = self.open()
|
||||||
|
valid = True
|
||||||
|
for line in blocklist:
|
||||||
|
if not self.is_ignored(line):
|
||||||
|
try:
|
||||||
|
(start, end) = self.parse(line)
|
||||||
|
except:
|
||||||
|
valid = False
|
||||||
|
finally:
|
||||||
|
break
|
||||||
|
blocklist.close()
|
||||||
|
return valid
|
||||||
|
|
||||||
def readranges(self):
|
def readranges(self):
|
||||||
"""Yields each ip range from the file"""
|
"""Yields each ip range from the file"""
|
||||||
blocklist = self.open()
|
blocklist = self.open()
|
||||||
|
|
Loading…
Reference in New Issue