Skip to content

Commit a741751

Browse files
committed
Small update
1 parent 53b02e5 commit a741751

1 file changed

Lines changed: 58 additions & 47 deletions

File tree

pyarchivefile/pyfile.py

Lines changed: 58 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7914,9 +7914,20 @@ def PackArchiveFileFromInFile(infile, outfile, fmttype="auto", compression="auto
79147914
return False
79157915
return False
79167916

7917-
# --- Add this helper (Py2/3 compatible) ---
7918-
def ArchiveFileArrayValidate(listarrayfiles, verbose=False):
7919-
# Top-level checks
7917+
def ArchiveFileArrayValidate(infile, verbose=False):
7918+
# ---------- Input handling ----------
7919+
if isinstance(infile, dict):
7920+
listarrayfileslist = [infile]
7921+
elif isinstance(infile, list):
7922+
listarrayfileslist = infile
7923+
else:
7924+
if (infile != "-" and not isinstance(infile, (bytes, bytearray, memoryview)) # bytes is str on Py2
7925+
and not hasattr(infile, "read") and not hasattr(infile, "write")):
7926+
infile = RemoveWindowsPath(infile)
7927+
listarrayfileslist = ArchiveFileToArray(
7928+
infile, fmttype, filestart, 0, 0,
7929+
False, True, False, True, formatspecs, saltkey, seektoend, returnfp
7930+
)
79207931
if not isinstance(listarrayfiles, dict):
79217932
if verbose: logging.warning("listarrayfiles must be a dict, got %r", type(listarrayfiles))
79227933
return False
@@ -7928,53 +7939,53 @@ def ArchiveFileArrayValidate(listarrayfiles, verbose=False):
79287939
if verbose: logging.warning("ffilelist must be a list, got %r", type(listarrayfiles["ffilelist"]))
79297940
return False
79307941

7931-
# Per-entry required keys
7932-
required = [
7933-
"fname", "fencoding", "fheadersize", "fsize", "flinkname",
7934-
"fatime", "fmtime", "fctime", "fbtime",
7935-
"fmode", "fchmode", "fuid", "funame", "fgid", "fgname",
7936-
"finode", "flinkcount", "fwinattributes",
7937-
"fcompression", "fcsize",
7938-
"fdev", "fminor", "fmajor",
7939-
"fseeknextfile", "fextradata", "fextrafields",
7940-
"fcontents", "fcontentasfile", "fjsondata", "ftype",
7941-
]
7942-
ok = True
7943-
for i, ent in enumerate(listarrayfiles["ffilelist"]):
7944-
if not isinstance(ent, dict):
7945-
if verbose: logging.warning("ffilelist[%d] must be a dict, got %r", i, type(ent))
7946-
ok = False
7947-
continue
7948-
missing = [k for k in required if k not in ent]
7949-
if missing:
7950-
if verbose: logging.warning("ffilelist[%d] missing keys: %s", i, ", ".join(missing))
7951-
ok = False
7952-
continue
7953-
# Light type/convert checks for numeric-ish fields
7954-
intish = [
7955-
"fheadersize", "fsize", "fatime", "fmtime", "fctime", "fbtime",
7956-
"fmode", "fchmode", "fuid", "fgid", "finode",
7957-
"flinkcount", "fwinattributes", "fcsize",
7958-
"fdev", "fminor", "fmajor", "ftype",
7942+
for listarrayfiles in listarrayfileslist:
7943+
# Per-entry required keys
7944+
required = [
7945+
"fname", "fencoding", "fheadersize", "fsize", "flinkname",
7946+
"fatime", "fmtime", "fctime", "fbtime",
7947+
"fmode", "fchmode", "fuid", "funame", "fgid", "fgname",
7948+
"finode", "flinkcount", "fwinattributes",
7949+
"fcompression", "fcsize", "fdev", "frdev",
7950+
"fseeknextfile", "fextradata", "fextrafields",
7951+
"fcontents", "fcontentasfile", "fjsondata", "ftype",
79597952
]
7960-
for k in intish:
7961-
try:
7962-
int(ent[k])
7963-
except Exception:
7964-
if verbose: logging.warning("ffilelist[%d].%s expected int-convertible, got %r", i, k, ent[k])
7953+
ok = True
7954+
for i, ent in enumerate(listarrayfiles["ffilelist"]):
7955+
if not isinstance(ent, dict):
7956+
if verbose: logging.warning("ffilelist[%d] must be a dict, got %r", i, type(ent))
7957+
ok = False
7958+
continue
7959+
missing = [k for k in required if k not in ent]
7960+
if missing:
7961+
if verbose: logging.warning("ffilelist[%d] missing keys: %s", i, ", ".join(missing))
7962+
ok = False
7963+
continue
7964+
# Light type/convert checks for numeric-ish fields
7965+
intish = [
7966+
"fheadersize", "fsize", "fatime", "fmtime", "fctime", "fbtime",
7967+
"fmode", "fchmode", "fuid", "fgid", "finode",
7968+
"flinkcount", "fwinattributes", "fcsize",
7969+
"fdev", "frdev", "ftype",
7970+
]
7971+
for k in intish:
7972+
try:
7973+
int(ent[k])
7974+
except Exception:
7975+
if verbose: logging.warning("ffilelist[%d].%s expected int-convertible, got %r", i, k, ent[k])
7976+
ok = False
7977+
# Booleans/flags presence
7978+
if not isinstance(ent["fcontentasfile"], (bool, int)): # tolerate 0/1
7979+
if verbose: logging.warning("ffilelist[%d].fcontentasfile should be bool-like, got %r", i, ent["fcontentasfile"])
79657980
ok = False
7966-
# Booleans/flags presence
7967-
if not isinstance(ent["fcontentasfile"], (bool, int)): # tolerate 0/1
7968-
if verbose: logging.warning("ffilelist[%d].fcontentasfile should be bool-like, got %r", i, ent["fcontentasfile"])
7969-
ok = False
7970-
# Arrays presence
7971-
for arrk in ("fextradata",):
7972-
if not isinstance(ent[arrk], list):
7973-
if verbose: logging.warning("ffilelist[%d].%s should be a list, got %r", i, arrk, type(ent[arrk]))
7981+
# Arrays presence
7982+
for arrk in ("fextradata",):
7983+
if not isinstance(ent[arrk], list):
7984+
if verbose: logging.warning("ffilelist[%d].%s should be a list, got %r", i, arrk, type(ent[arrk]))
7985+
ok = False
7986+
if not isinstance(ent.get("fjsondata", {}), dict):
7987+
if verbose: logging.warning("ffilelist[%d].fjsondata should be a dict, got %r", i, type(ent.get("fjsondata")))
79747988
ok = False
7975-
if not isinstance(ent.get("fjsondata", {}), dict):
7976-
if verbose: logging.warning("ffilelist[%d].fjsondata should be a dict, got %r", i, type(ent.get("fjsondata")))
7977-
ok = False
79787989
return ok
79797990

79807991
def ArchiveFileValidate(infile, fmttype="auto", filestart=0, formatspecs=__file_format_multi_dict__, saltkey=None, seektoend=False, verbose=False, returnfp=False):

0 commit comments

Comments
 (0)