增加open容错处理

This commit is contained in:
Jing Ling
2020-01-10 15:26:41 +08:00
parent d99cf64ae8
commit 2ff7d45348
4 changed files with 5 additions and 5 deletions
+1 -1
View File
@@ -226,7 +226,7 @@ class Module(object):
dpath.mkdir(parents=True, exist_ok=True) dpath.mkdir(parents=True, exist_ok=True)
name = self.source + '.json' name = self.source + '.json'
path = dpath.joinpath(name) path = dpath.joinpath(name)
with open(path, mode='w', encoding='utf-8') as file: with open(path, mode='w', encoding='utf-8', errors='ignore') as file:
result = {'domain': self.domain, result = {'domain': self.domain,
'name': self.module, 'name': self.module,
'source': self.source, 'source': self.source,
+2 -2
View File
@@ -120,7 +120,7 @@ def get_domains(target):
elif isinstance(target, str): elif isinstance(target, str):
path = Path(target) path = Path(target)
if path.is_file(): if path.is_file():
with open(target) as file: with open(target, encoding='utf-8', errors='ignore') as file:
for line in file: for line in file:
domain = Domain(line.strip()).match() domain = Domain(line.strip()).match()
if domain: if domain:
@@ -189,7 +189,7 @@ def check_format(format, count):
def save_data(fpath, data): def save_data(fpath, data):
try: try:
with open(fpath, 'w', encoding="utf-8", newline='') as file: with open(fpath, 'w', encoding="utf-8", errors='ignore', newline='') as file:
file.write(data) file.write(data)
logger.log('ALERT', fpath) logger.log('ALERT', fpath)
except TypeError: except TypeError:
+1 -1
View File
@@ -26,7 +26,7 @@ class BruteSRV(Module):
def gen_names(self): def gen_names(self):
path = data_storage_path.joinpath('srv_prefixes.json') path = data_storage_path.joinpath('srv_prefixes.json')
with open(path) as file: with open(path, encoding='utf-8', errors='ignore') as file:
prefixes = json.load(file) prefixes = json.load(file)
names = map(lambda prefix: prefix + self.domain, prefixes) names = map(lambda prefix: prefix + self.domain, prefixes)
+1 -1
View File
@@ -25,7 +25,7 @@ from common.domain import Domain
def get_fingerprint(): def get_fingerprint():
path = config.data_storage_path.joinpath('fingerprints.json') path = config.data_storage_path.joinpath('fingerprints.json')
with open(path) as file: with open(path, encoding='utf-8', errors='ignore') as file:
fingerprints = json.load(file) fingerprints = json.load(file)
return fingerprints return fingerprints