Vote count:
0
Is it safe that appending files to running python zip file module itself?
I've written __main__.py as follows.
import sys, zipfile
w = zipfile.ZipFile(sys.argv[0], "w") # opening script self for writing.
w.write("newfile") # appending "newfile" to script self.
w.close()
r = zipfile.ZipFile(sys.argv[0], "r") # opening script self for reading.
print(r.open("newfile").read()) # print "newfile" content.
r.close()
and, executed as follows.
$ ls
__main__.py
$ zip -r test.zip * <<<=== creating python zip file module.
adding: __main__.py (deflated 35%)
$ echo "ABC" > newfile <<<=== creating a new file to be added to "test.zip"
$ ls
__main__.py newfile test.zip
$ python test.zip <<<=== running "test.zip" python zip file module.
b'ABC\n' <<<=== printed out "newfile" content.
from this result, it looks working well. but, I couldn't confirmed this selfmodying method and behavior result alongs with the python specifications or not.
asked 2 mins ago
python zip file module selfmodifying is safe?
Aucun commentaire:
Enregistrer un commentaire