Skip to content

Commit

Permalink
Merge pull request Arelle#1385 from stevenbronson-wk/package-validations
Browse files Browse the repository at this point in the history
  • Loading branch information
austinmatherne-wk authored Oct 23, 2024
2 parents 3cdc2f5 + 2fa7ffa commit 6da0cef
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 32 deletions.
2 changes: 2 additions & 0 deletions arelle/PackageManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,7 @@ def validateTaxonomyPackage(cntlr, filesource, errors=[]) -> bool:
cntlr.addToLog(
validation.msg,
messageCode=validation.codes,
messageArgs=validation.args,
file=filesource.urlBasename,
level=logging.ERROR,
)
Expand All @@ -433,6 +434,7 @@ def validateTaxonomyPackage(cntlr, filesource, errors=[]) -> bool:
cntlr.addToLog(
validation.msg,
messageCode=validation.codes,
messageArgs=validation.args,
file=filesource.urlBasename,
level=logging.ERROR,
)
Expand Down
50 changes: 18 additions & 32 deletions arelle/packages/PackageValidation.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ def validatePackageZipFormat(
return Validation.error(
codes=f"{packageType.errorPrefix}:invalidArchiveFormat",
msg=_("%(packageType)s package is not valid and could not be opened: %(file)s"),
args={
"packageType": packageType.name,
"file": os.path.basename(str(filesource.url)),
},
packageType=packageType.name,
file=os.path.basename(str(filesource.url)),
)
return None

Expand All @@ -45,10 +43,8 @@ def validatePackageNotEncrypted(
return Validation.error(
codes=f"{packageType.errorPrefix}:invalidArchiveFormat",
msg=_("%(packageType)s package contains encrypted files: %(file)s"),
args={
"packageType": packageType.name,
"file": os.path.basename(str(filesource.url)),
},
packageType=packageType.name,
file=os.path.basename(str(filesource.url)),
)
return None

Expand All @@ -61,10 +57,8 @@ def validateZipFileSeparators(
return Validation.error(
codes=f"{packageType.errorPrefix}:invalidArchiveFormat",
msg=_("%(packageType)s package directory uses '\\' as a file separator."),
args={
"packageType": packageType.name,
"file": os.path.basename(str(filesource.url)),
},
packageType=packageType.name,
file=os.path.basename(str(filesource.url)),
)
return None

Expand All @@ -79,12 +73,10 @@ def validateTopLevelFiles(
return Validation.error(
codes=f"{packageType.errorPrefix}:invalidDirectoryStructure",
msg=_("%(packageType)s package contains %(count)s top level file(s): %(topLevelFiles)s"),
args={
"packageType": packageType.name,
"count": numTopLevelFiles,
"topLevelFiles": ", ".join(sorted(topLevelFiles)),
"file": os.path.basename(str(filesource.url)),
},
packageType=packageType.name,
count=numTopLevelFiles,
topLevelFiles=", ".join(sorted(topLevelFiles)),
file=os.path.basename(str(filesource.url)),
)
return None

Expand All @@ -99,21 +91,17 @@ def validateTopLevelDirectories(
return Validation.error(
codes=f"{packageType.errorPrefix}:invalidDirectoryStructure",
msg=_("%(packageType)s Package does not contain a top level directory"),
args={
"packageType": packageType.name,
"file": os.path.basename(str(filesource.url)),
},
packageType=packageType.name,
file=os.path.basename(str(filesource.url)),
)
if numTopLevelDirectories > 1:
return Validation.error(
codes=f"{packageType.errorPrefix}:invalidDirectoryStructure",
msg=_("%(packageType)s package contains %(count)s top level directories: %(topLevelDirectories)s"),
args={
"packageType": packageType.name,
"count": numTopLevelDirectories,
"topLevelDirectories": ", ".join(sorted(topLevelDirectories)),
"file": os.path.basename(str(filesource.url)),
},
packageType=packageType.name,
count=numTopLevelDirectories,
topLevelDirectories=", ".join(sorted(topLevelDirectories)),
file=os.path.basename(str(filesource.url)),
)
return None

Expand All @@ -126,9 +114,7 @@ def validateMetadataDirectory(
return Validation.error(
codes=f"{packageType.errorPrefix}:metadataDirectoryNotFound",
msg=_("%(packageType)s package top-level directory does not contain a subdirectory META-INF"),
args={
"packageType": packageType.name,
"file": os.path.basename(str(filesource.url)),
},
packageType=packageType.name,
file=os.path.basename(str(filesource.url)),
)
return None

0 comments on commit 6da0cef

Please sign in to comment.