Fix pylint warnings: logging, globals, exceptions, imports, duplicates
Agent-Logs-Url: https://github.com/christianlouis/dmarq/sessions/576427d4-4f6a-46d2-b75f-6862ecbcf526 Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
@@ -56,7 +56,7 @@ def _validate_domain_labels(
|
||||
return True, None, None
|
||||
|
||||
|
||||
def validate_domain(
|
||||
def validate_domain( # pylint: disable=too-many-return-statements
|
||||
domain_name: str, check_dns: bool = True
|
||||
) -> Tuple[bool, Optional[str], Optional[str]]:
|
||||
"""
|
||||
@@ -103,7 +103,6 @@ def validate_domain(
|
||||
if check_dns:
|
||||
try:
|
||||
socket.gethostbyname(domain_name)
|
||||
return True, None, None
|
||||
except socket.gaierror:
|
||||
# We could consider this valid if we don't require DNS resolution,
|
||||
# but since DMARC requires valid DNS, we'll mark it as warning
|
||||
@@ -133,7 +132,7 @@ def validate_domain_config(domain_data: Dict) -> Dict[str, Union[bool, str]]:
|
||||
# Validate domain name
|
||||
if "name" in domain_data:
|
||||
# Don't check DNS for domain config validation
|
||||
is_valid, error_msg, error_code = validate_domain(domain_data["name"], check_dns=False)
|
||||
is_valid, error_msg, _ = validate_domain(domain_data["name"], check_dns=False)
|
||||
if not is_valid:
|
||||
errors["name"] = error_msg
|
||||
else:
|
||||
|
||||
@@ -63,10 +63,10 @@ class StatsSummarizer:
|
||||
return None
|
||||
|
||||
# Read cache file
|
||||
with open(cache_file, "r") as f:
|
||||
with open(cache_file, "r", encoding="utf-8") as f:
|
||||
return json.load(f)
|
||||
except Exception as e:
|
||||
logger.warning(f"Error reading cache file {cache_file}: {str(e)}")
|
||||
except Exception as e: # pylint: disable=broad-exception-caught
|
||||
logger.warning("Error reading cache file %s: %s", cache_file, str(e))
|
||||
return None
|
||||
|
||||
def save_summary(self, stats: Dict[str, Any], domain_id: Optional[str] = None) -> bool:
|
||||
@@ -87,12 +87,12 @@ class StatsSummarizer:
|
||||
stats["cached_at"] = datetime.now().isoformat()
|
||||
|
||||
# Write to cache file
|
||||
with open(cache_file, "w") as f:
|
||||
with open(cache_file, "w", encoding="utf-8") as f:
|
||||
json.dump(stats, f)
|
||||
|
||||
return True
|
||||
except Exception as e:
|
||||
logger.error(f"Error writing cache file {cache_file}: {str(e)}")
|
||||
except Exception as e: # pylint: disable=broad-exception-caught
|
||||
logger.error("Error writing cache file %s: %s", cache_file, str(e))
|
||||
return False
|
||||
|
||||
def invalidate_cache(self, domain_id: Optional[str] = None) -> None:
|
||||
@@ -126,12 +126,13 @@ class StatsSummarizer:
|
||||
"""
|
||||
if domain_id is None:
|
||||
return os.path.join(self.cache_dir, "global_summary.json")
|
||||
else:
|
||||
# Sanitize domain_id to use as filename
|
||||
safe_domain = domain_id.replace(".", "_").replace("/", "_")
|
||||
return os.path.join(self.cache_dir, f"domain_{safe_domain}.json")
|
||||
# Sanitize domain_id to use as filename
|
||||
safe_domain = domain_id.replace(".", "_").replace("/", "_")
|
||||
return os.path.join(self.cache_dir, f"domain_{safe_domain}.json")
|
||||
|
||||
def calculate_summary_statistics(self, db, domain_id: Optional[str] = None) -> Dict[str, Any]:
|
||||
def calculate_summary_statistics(
|
||||
self, _db, domain_id: Optional[str] = None
|
||||
) -> Dict[str, Any]:
|
||||
"""
|
||||
Calculate summary statistics from the database
|
||||
|
||||
|
||||
Reference in New Issue
Block a user