Skip to content

Commit 4ae03b1

Browse files
committed
Small update
1 parent c79bbf5 commit 4ae03b1

1 file changed

Lines changed: 65 additions & 72 deletions

File tree

pyfoxfile/pyfile.py

Lines changed: 65 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -4093,30 +4093,30 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, contentasfile=False, uncom
40934093
fjstart = fp.tell()
40944094
if(fjsontype=="json"):
40954095
fjsoncontent = {}
4096-
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
4096+
fprejsoncontent = fp.read(fjsonsize)
40974097
if(fjsonsize > 0):
40984098
try:
4099-
fjsonrawcontent = base64.b64decode(fprejsoncontent.encode("UTF-8")).decode("UTF-8")
4100-
fjsoncontent = json.loads(base64.b64decode(fprejsoncontent.encode("UTF-8")).decode("UTF-8"))
4099+
fjsonrawcontent = base64.b64decode(fprejsoncontent)
4100+
fjsoncontent = json.loads(base64.b64decode(fprejsoncontent).decode("UTF-8"))
41014101
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
41024102
try:
41034103
fjsonrawcontent = fprejsoncontent
4104-
fjsoncontent = json.loads(fprejsoncontent)
4104+
fjsoncontent = json.loads(fprejsoncontent.decode("UTF-8"))
41054105
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
4106-
fprejsoncontent = ""
4106+
fprejsoncontent = "".encode("UTF-8")
41074107
fjsonrawcontent = fprejsoncontent
41084108
fjsoncontent = {}
41094109
else:
4110-
fprejsoncontent = ""
4110+
fprejsoncontent = "".encode("UTF-8")
41114111
fjsonrawcontent = fprejsoncontent
41124112
fjsoncontent = {}
41134113
elif(testyaml and fjsontype == "yaml"):
41144114
fjsoncontent = {}
4115-
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
4115+
fprejsoncontent = fp.read(fjsonsize)
41164116
if (fjsonsize > 0):
41174117
try:
41184118
# try base64 → utf-8 → YAML
4119-
fjsonrawcontent = base64.b64decode(fprejsoncontent.encode("UTF-8")).decode("UTF-8")
4119+
fjsonrawcontent = base64.b64decode(fprejsoncontent)
41204120
fjsoncontent = yaml.safe_load(fjsonrawcontent) or {}
41214121
except (binascii.Error, UnicodeDecodeError, yaml.YAMLError):
41224122
try:
@@ -4125,20 +4125,20 @@ def ReadFileHeaderDataWithContent(fp, listonly=False, contentasfile=False, uncom
41254125
fjsoncontent = yaml.safe_load(fjsonrawcontent) or {}
41264126
except (UnicodeDecodeError, yaml.YAMLError):
41274127
# final fallback: empty
4128-
fprejsoncontent = ""
4128+
fprejsoncontent = "".encode("UTF-8")
41294129
fjsonrawcontent = fprejsoncontent
41304130
fjsoncontent = {}
41314131
else:
4132-
fprejsoncontent = ""
4132+
fprejsoncontent = "".encode("UTF-8")
41334133
fjsonrawcontent = fprejsoncontent
41344134
fjsoncontent = {}
41354135
elif(not testyaml and fjsontype == "yaml"):
41364136
fjsoncontent = {}
4137-
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
4138-
fprejsoncontent = ""
4137+
fprejsoncontent = fp.read(fjsonsize)
4138+
fprejsoncontent = "".encode("UTF-8")
41394139
fjsonrawcontent = fprejsoncontent
41404140
elif(fjsontype=="list"):
4141-
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
4141+
fprejsoncontent = fp.read(fjsonsize)
41424142
flisttmp = MkTempFile()
41434143
flisttmp.write(fprejsoncontent.encode())
41444144
flisttmp.seek(0)
@@ -4311,30 +4311,30 @@ def ReadFileHeaderDataWithContentToArray(fp, listonly=False, contentasfile=True,
43114311
fjstart = fp.tell()
43124312
if(fjsontype=="json"):
43134313
fjsoncontent = {}
4314-
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
4314+
fprejsoncontent = fp.read(fjsonsize)
43154315
if(fjsonsize > 0):
43164316
try:
4317-
fjsonrawcontent = base64.b64decode(fprejsoncontent.encode("UTF-8")).decode("UTF-8")
4318-
fjsoncontent = json.loads(base64.b64decode(fprejsoncontent.encode("UTF-8")).decode("UTF-8"))
4317+
fjsonrawcontent = base64.b64decode(fprejsoncontent)
4318+
fjsoncontent = json.loads(base64.b64decode(fprejsoncontent).decode("UTF-8"))
43194319
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
43204320
try:
43214321
fjsonrawcontent = fprejsoncontent
4322-
fjsoncontent = json.loads(fprejsoncontent)
4322+
fjsoncontent = json.loads(fprejsoncontent.decode("UTF-8"))
43234323
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
4324-
fprejsoncontent = ""
4324+
fprejsoncontent = "".encode("UTF-8")
43254325
fjsonrawcontent = fprejsoncontent
43264326
fjsoncontent = {}
43274327
else:
4328-
fprejsoncontent = ""
4328+
fprejsoncontent = "".encode("UTF-8")
43294329
fjsonrawcontent = fprejsoncontent
43304330
fjsoncontent = {}
43314331
elif(testyaml and fjsontype == "yaml"):
43324332
fjsoncontent = {}
4333-
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
4333+
fprejsoncontent = fp.read(fjsonsize)
43344334
if (fjsonsize > 0):
43354335
try:
43364336
# try base64 → utf-8 → YAML
4337-
fjsonrawcontent = base64.b64decode(fprejsoncontent.encode("UTF-8")).decode("UTF-8")
4337+
fjsonrawcontent = base64.b64decode(fprejsoncontent)
43384338
fjsoncontent = yaml.safe_load(fjsonrawcontent) or {}
43394339
except (binascii.Error, UnicodeDecodeError, yaml.YAMLError):
43404340
try:
@@ -4343,20 +4343,20 @@ def ReadFileHeaderDataWithContentToArray(fp, listonly=False, contentasfile=True,
43434343
fjsoncontent = yaml.safe_load(fjsonrawcontent) or {}
43444344
except (UnicodeDecodeError, yaml.YAMLError):
43454345
# final fallback: empty
4346-
fprejsoncontent = ""
4346+
fprejsoncontent = "".encode("UTF-8")
43474347
fjsonrawcontent = fprejsoncontent
43484348
fjsoncontent = {}
43494349
else:
4350-
fprejsoncontent = ""
4350+
fprejsoncontent = "".encode("UTF-8")
43514351
fjsonrawcontent = fprejsoncontent
43524352
fjsoncontent = {}
43534353
elif(not testyaml and fjsontype == "yaml"):
43544354
fjsoncontent = {}
4355-
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
4356-
fprejsoncontent = ""
4355+
fprejsoncontent = fp.read(fjsonsize)
4356+
fprejsoncontent = "".encode("UTF-8")
43574357
fjsonrawcontent = fprejsoncontent
43584358
elif(fjsontype=="list"):
4359-
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
4359+
fprejsoncontent = fp.read(fjsonsize)
43604360
flisttmp = MkTempFile()
43614361
flisttmp.write(fprejsoncontent.encode())
43624362
flisttmp.seek(0)
@@ -4530,30 +4530,30 @@ def ReadFileHeaderDataWithContentToList(fp, listonly=False, contentasfile=False,
45304530
fjstart = fp.tell()
45314531
if(fjsontype=="json"):
45324532
fjsoncontent = {}
4533-
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
4533+
fprejsoncontent = fp.read(fjsonsize)
45344534
if(fjsonsize > 0):
45354535
try:
4536-
fjsonrawcontent = base64.b64decode(fprejsoncontent.encode("UTF-8")).decode("UTF-8")
4537-
fjsoncontent = json.loads(base64.b64decode(fprejsoncontent.encode("UTF-8")).decode("UTF-8"))
4536+
fjsonrawcontent = base64.b64decode(fprejsoncontent)
4537+
fjsoncontent = json.loads(base64.b64decode(fprejsoncontent).decode("UTF-8"))
45384538
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
45394539
try:
45404540
fjsonrawcontent = fprejsoncontent
4541-
fjsoncontent = json.loads(fprejsoncontent)
4541+
fjsoncontent = json.loads(fprejsoncontent.decode("UTF-8"))
45424542
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
4543-
fprejsoncontent = ""
4543+
fprejsoncontent = "".encode("UTF-8")
45444544
fjsonrawcontent = fprejsoncontent
45454545
fjsoncontent = {}
45464546
else:
4547-
fprejsoncontent = ""
4547+
fprejsoncontent = "".encode("UTF-8")
45484548
fjsonrawcontent = fprejsoncontent
45494549
fjsoncontent = {}
45504550
elif(testyaml and fjsontype == "yaml"):
45514551
fjsoncontent = {}
4552-
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
4552+
fprejsoncontent = fp.read(fjsonsize)
45534553
if (fjsonsize > 0):
45544554
try:
45554555
# try base64 → utf-8 → YAML
4556-
fjsonrawcontent = base64.b64decode(fprejsoncontent.encode("UTF-8")).decode("UTF-8")
4556+
fjsonrawcontent = base64.b64decode(fprejsoncontent)
45574557
fjsoncontent = yaml.safe_load(fjsonrawcontent) or {}
45584558
except (binascii.Error, UnicodeDecodeError, yaml.YAMLError):
45594559
try:
@@ -4562,20 +4562,20 @@ def ReadFileHeaderDataWithContentToList(fp, listonly=False, contentasfile=False,
45624562
fjsoncontent = yaml.safe_load(fjsonrawcontent) or {}
45634563
except (UnicodeDecodeError, yaml.YAMLError):
45644564
# final fallback: empty
4565-
fprejsoncontent = ""
4565+
fprejsoncontent = "".encode("UTF-8")
45664566
fjsonrawcontent = fprejsoncontent
45674567
fjsoncontent = {}
45684568
else:
4569-
fprejsoncontent = ""
4569+
fprejsoncontent = "".encode("UTF-8")
45704570
fjsonrawcontent = fprejsoncontent
45714571
fjsoncontent = {}
45724572
elif(not testyaml and fjsontype == "yaml"):
45734573
fjsoncontent = {}
4574-
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
4575-
fprejsoncontent = ""
4574+
fprejsoncontent = fp.read(fjsonsize)
4575+
fprejsoncontent = "".encode("UTF-8")
45764576
fjsonrawcontent = fprejsoncontent
45774577
elif(fjsontype=="list"):
4578-
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
4578+
fprejsoncontent = fp.read(fjsonsize)
45794579
flisttmp = MkTempFile()
45804580
flisttmp.write(fprejsoncontent.encode())
45814581
flisttmp.seek(0)
@@ -4807,30 +4807,30 @@ def ReadFileDataWithContentToArray(fp, filestart=0, seekstart=0, seekend=0, list
48074807
fjstart = fp.tell()
48084808
if(fjsontype=="json"):
48094809
fjsoncontent = {}
4810-
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
4810+
fprejsoncontent = fp.read(fjsonsize)
48114811
if(fjsonsize > 0):
48124812
try:
4813-
fjsonrawcontent = base64.b64decode(fprejsoncontent.encode("UTF-8")).decode("UTF-8")
4814-
fjsoncontent = json.loads(base64.b64decode(fprejsoncontent.encode("UTF-8")).decode("UTF-8"))
4813+
fjsonrawcontent = base64.b64decode(fprejsoncontent)
4814+
fjsoncontent = json.loads(base64.b64decode(fprejsoncontent).decode("UTF-8"))
48154815
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
48164816
try:
48174817
fjsonrawcontent = fprejsoncontent
4818-
fjsoncontent = json.loads(fprejsoncontent)
4818+
fjsoncontent = json.loads(fprejsoncontent.decode("UTF-8"))
48194819
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
4820-
fprejsoncontent = ""
4820+
fprejsoncontent = "".encode("UTF-8")
48214821
fjsonrawcontent = fprejsoncontent
48224822
fjsoncontent = {}
48234823
else:
4824-
fprejsoncontent = ""
4824+
fprejsoncontent = "".encode("UTF-8")
48254825
fjsonrawcontent = fprejsoncontent
48264826
fjsoncontent = {}
48274827
elif(testyaml and fjsontype == "yaml"):
48284828
fjsoncontent = {}
4829-
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
4829+
fprejsoncontent = fp.read(fjsonsize)
48304830
if (fjsonsize > 0):
48314831
try:
48324832
# try base64 → utf-8 → YAML
4833-
fjsonrawcontent = base64.b64decode(fprejsoncontent.encode("UTF-8")).decode("UTF-8")
4833+
fjsonrawcontent = base64.b64decode(fprejsoncontent)
48344834
fjsoncontent = yaml.safe_load(fjsonrawcontent) or {}
48354835
except (binascii.Error, UnicodeDecodeError, yaml.YAMLError):
48364836
try:
@@ -4839,20 +4839,20 @@ def ReadFileDataWithContentToArray(fp, filestart=0, seekstart=0, seekend=0, list
48394839
fjsoncontent = yaml.safe_load(fjsonrawcontent) or {}
48404840
except (UnicodeDecodeError, yaml.YAMLError):
48414841
# final fallback: empty
4842-
fprejsoncontent = ""
4842+
fprejsoncontent = "".encode("UTF-8")
48434843
fjsonrawcontent = fprejsoncontent
48444844
fjsoncontent = {}
48454845
else:
4846-
fprejsoncontent = ""
4846+
fprejsoncontent = "".encode("UTF-8")
48474847
fjsonrawcontent = fprejsoncontent
48484848
fjsoncontent = {}
48494849
elif(not testyaml and fjsontype == "yaml"):
48504850
fjsoncontent = {}
4851-
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
4852-
fprejsoncontent = ""
4851+
fprejsoncontent = fp.read(fjsonsize)
4852+
fprejsoncontent = "".encode("UTF-8")
48534853
fjsonrawcontent = fprejsoncontent
48544854
elif(fjsontype=="list"):
4855-
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
4855+
fprejsoncontent = fp.read(fjsonsize)
48564856
flisttmp = MkTempFile()
48574857
flisttmp.write(fprejsoncontent.encode())
48584858
flisttmp.seek(0)
@@ -5070,30 +5070,30 @@ def ReadFileDataWithContentToList(fp, filestart=0, seekstart=0, seekend=0, listo
50705070
fjstart = fp.tell()
50715071
if(fjsontype=="json"):
50725072
fjsoncontent = {}
5073-
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
5073+
fprejsoncontent = fp.read(fjsonsize)
50745074
if(fjsonsize > 0):
50755075
try:
5076-
fjsonrawcontent = base64.b64decode(fprejsoncontent.encode("UTF-8")).decode("UTF-8")
5077-
fjsoncontent = json.loads(base64.b64decode(fprejsoncontent.encode("UTF-8")).decode("UTF-8"))
5076+
fjsonrawcontent = base64.b64decode(fprejsoncontent)
5077+
fjsoncontent = json.loads(base64.b64decode(fprejsoncontent).decode("UTF-8"))
50785078
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
50795079
try:
50805080
fjsonrawcontent = fprejsoncontent
5081-
fjsoncontent = json.loads(fprejsoncontent)
5081+
fjsoncontent = json.loads(fprejsoncontent.decode("UTF-8"))
50825082
except (binascii.Error, json.decoder.JSONDecodeError, UnicodeDecodeError):
5083-
fprejsoncontent = ""
5083+
fprejsoncontent = "".encode("UTF-8")
50845084
fjsonrawcontent = fprejsoncontent
50855085
fjsoncontent = {}
50865086
else:
5087-
fprejsoncontent = ""
5087+
fprejsoncontent = "".encode("UTF-8")
50885088
fjsonrawcontent = fprejsoncontent
50895089
fjsoncontent = {}
50905090
elif(testyaml and fjsontype == "yaml"):
50915091
fjsoncontent = {}
5092-
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
5092+
fprejsoncontent = fp.read(fjsonsize)
50935093
if (fjsonsize > 0):
50945094
try:
50955095
# try base64 → utf-8 → YAML
5096-
fjsonrawcontent = base64.b64decode(fprejsoncontent.encode("UTF-8")).decode("UTF-8")
5096+
fjsonrawcontent = base64.b64decode(fprejsoncontent)
50975097
fjsoncontent = yaml.safe_load(fjsonrawcontent) or {}
50985098
except (binascii.Error, UnicodeDecodeError, yaml.YAMLError):
50995099
try:
@@ -5102,20 +5102,20 @@ def ReadFileDataWithContentToList(fp, filestart=0, seekstart=0, seekend=0, listo
51025102
fjsoncontent = yaml.safe_load(fjsonrawcontent) or {}
51035103
except (UnicodeDecodeError, yaml.YAMLError):
51045104
# final fallback: empty
5105-
fprejsoncontent = ""
5105+
fprejsoncontent = "".encode("UTF-8")
51065106
fjsonrawcontent = fprejsoncontent
51075107
fjsoncontent = {}
51085108
else:
5109-
fprejsoncontent = ""
5109+
fprejsoncontent = "".encode("UTF-8")
51105110
fjsonrawcontent = fprejsoncontent
51115111
fjsoncontent = {}
51125112
elif(not testyaml and fjsontype == "yaml"):
51135113
fjsoncontent = {}
5114-
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
5115-
fprejsoncontent = ""
5114+
fprejsoncontent = fp.read(fjsonsize)
5115+
fprejsoncontent = "".encode("UTF-8")
51165116
fjsonrawcontent = fprejsoncontent
51175117
elif(fjsontype=="list"):
5118-
fprejsoncontent = fp.read(fjsonsize).decode("UTF-8")
5118+
fprejsoncontent = fp.read(fjsonsize)
51195119
flisttmp = MkTempFile()
51205120
flisttmp.write(fprejsoncontent.encode())
51215121
flisttmp.seek(0)
@@ -7923,7 +7923,6 @@ def PackFoxFileFromInFile(infile, outfile, fmttype="auto", compression="auto", c
79237923

79247924
# --- Add this helper (Py2/3 compatible) ---
79257925
def FoxFileArrayValidate(listarrayfiles, verbose=False):
7926-
import logging
79277926
# Top-level checks
79287927
if not isinstance(listarrayfiles, dict):
79297928
if verbose: logging.warning("listarrayfiles must be a dict, got %r", type(listarrayfiles))
@@ -8005,7 +8004,6 @@ def FoxFileValidate(infile, fmttype="auto", filestart=0, formatspecs=__file_form
80058004
return False
80068005
if(not fp):
80078006
return False
8008-
fp.seek(filestart, 0)
80098007
elif(infile == "-"):
80108008
fp = MkTempFile()
80118009
shutil.copyfileobj(PY_STDIN_BUF, fp, length=__filebuff_size__)
@@ -8016,7 +8014,6 @@ def FoxFileValidate(infile, fmttype="auto", filestart=0, formatspecs=__file_form
80168014
formatspecs = formatspecs[checkcompressfile]
80178015
if(not fp):
80188016
return False
8019-
fp.seek(filestart, 0)
80208017
elif(isinstance(infile, bytes)):
80218018
fp = MkTempFile()
80228019
fp.write(infile)
@@ -8027,17 +8024,14 @@ def FoxFileValidate(infile, fmttype="auto", filestart=0, formatspecs=__file_form
80278024
formatspecs = formatspecs[compresscheck]
80288025
if(not fp):
80298026
return False
8030-
fp.seek(filestart, 0)
80318027
elif(re.findall(__download_proto_support__, infile) and pywwwget):
80328028
fp = download_file_from_internet_file(infile)
80338029
fp = UncompressFileAlt(fp, formatspecs, filestart)
80348030
compresscheck = CheckCompressionType(fp, formatspecs, 0, False)
80358031
if(IsNestedDict(formatspecs) and compresscheck in formatspecs):
80368032
formatspecs = formatspecs[compresscheck]
8037-
fp.seek(filestart, 0)
80388033
if(not fp):
80398034
return False
8040-
fp.seek(filestart, 0)
80418035
else:
80428036
infile = RemoveWindowsPath(infile)
80438037
checkcompressfile = CheckCompressionSubType(infile, formatspecs, filestart, True)
@@ -8084,7 +8078,6 @@ def FoxFileValidate(infile, fmttype="auto", filestart=0, formatspecs=__file_form
80848078
return False
80858079
else:
80868080
formatspecs = formatspecs[compresschecking]
8087-
fp.seek(filestart, 0)
80888081
inheaderver = str(int(formatspecs['format_ver'].replace(".", "")))
80898082
headeroffset = fp.tell()
80908083
formstring = fp.read(formatspecs['format_len'] + len(inheaderver)).decode("UTF-8")

0 commit comments

Comments
 (0)