Py3 compatibility of FilePack plugin
This commit is contained in:
parent
2737425242
commit
2599e54fd0
1 changed files with 6 additions and 5 deletions
|
@ -21,10 +21,10 @@ def openArchive(archive_path, file_obj=None):
|
||||||
if archive_path not in archive_cache:
|
if archive_path not in archive_cache:
|
||||||
if archive_path.endswith("tar.gz"):
|
if archive_path.endswith("tar.gz"):
|
||||||
import tarfile
|
import tarfile
|
||||||
archive_cache[archive_path] = tarfile.open(file_obj or archive_path, "r:gz")
|
archive_cache[archive_path] = tarfile.open(archive_path, fileobj=file_obj, mode="r:gz")
|
||||||
elif archive_path.endswith("tar.bz2"):
|
elif archive_path.endswith("tar.bz2"):
|
||||||
import tarfile
|
import tarfile
|
||||||
archive_cache[archive_path] = tarfile.open(file_obj or archive_path, "r:bz2")
|
archive_cache[archive_path] = tarfile.open(archive_path, fileobj=file_obj, mode="r:bz2")
|
||||||
else:
|
else:
|
||||||
import zipfile
|
import zipfile
|
||||||
archive_cache[archive_path] = zipfile.ZipFile(file_obj or archive_path)
|
archive_cache[archive_path] = zipfile.ZipFile(file_obj or archive_path)
|
||||||
|
@ -39,7 +39,7 @@ def openArchiveFile(archive_path, path_within, file_obj=None):
|
||||||
if archive_path.endswith(".zip"):
|
if archive_path.endswith(".zip"):
|
||||||
return archive.open(path_within)
|
return archive.open(path_within)
|
||||||
else:
|
else:
|
||||||
return archive.extractfile(path_within.encode("utf8"))
|
return archive.extractfile(path_within)
|
||||||
|
|
||||||
|
|
||||||
@PluginManager.registerTo("UiRequest")
|
@PluginManager.registerTo("UiRequest")
|
||||||
|
@ -64,6 +64,8 @@ class UiRequestPlugin(object):
|
||||||
if not result:
|
if not result:
|
||||||
return self.error404(archive_inner_path)
|
return self.error404(archive_inner_path)
|
||||||
file_obj = site.storage.openBigfile(archive_inner_path)
|
file_obj = site.storage.openBigfile(archive_inner_path)
|
||||||
|
if file_obj == False:
|
||||||
|
file_obj = None
|
||||||
|
|
||||||
header_allow_ajax = False
|
header_allow_ajax = False
|
||||||
if self.get.get("ajax_key"):
|
if self.get.get("ajax_key"):
|
||||||
|
@ -176,13 +178,12 @@ class SiteStoragePlugin(object):
|
||||||
else:
|
else:
|
||||||
return super(SiteStoragePlugin, self).list(inner_path, *args, **kwags)
|
return super(SiteStoragePlugin, self).list(inner_path, *args, **kwags)
|
||||||
|
|
||||||
def read(self, inner_path, mode="r"):
|
def read(self, inner_path, mode="rb"):
|
||||||
if ".zip/" in inner_path or ".tar.gz/" in inner_path:
|
if ".zip/" in inner_path or ".tar.gz/" in inner_path:
|
||||||
match = re.match("^(.*\.(?:tar.gz|tar.bz2|zip))(.*)", inner_path)
|
match = re.match("^(.*\.(?:tar.gz|tar.bz2|zip))(.*)", inner_path)
|
||||||
archive_inner_path, path_within = match.groups()
|
archive_inner_path, path_within = match.groups()
|
||||||
archive = self.openArchive(archive_inner_path)
|
archive = self.openArchive(archive_inner_path)
|
||||||
path_within = path_within.lstrip("/")
|
path_within = path_within.lstrip("/")
|
||||||
print archive, archive_inner_path
|
|
||||||
|
|
||||||
if archive_inner_path.endswith(".zip"):
|
if archive_inner_path.endswith(".zip"):
|
||||||
return archive.open(path_within).read()
|
return archive.open(path_within).read()
|
||||||
|
|
Loading…
Reference in a new issue