more filters made compatible with python3

This commit is contained in:
Jean-Francois Dockes
2015-11-07 16:59:17 +01:00
parent f344e8fedd
commit dfe00ab11f
18 changed files with 209 additions and 100 deletions
+28 -5
View File
@@ -1,6 +1,24 @@
#!/usr/bin/env python
# Copyright (C) 2014 J.F.Dockes
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the
# Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Zip file filter for Recoll
# Zip file extractor for Recoll
from __future__ import print_function
import os
import fnmatch
@@ -78,9 +96,7 @@ class ZipExtractor:
iseof = rclexecm.RclExecM.noteof
if self.currentindex >= len(self.zip.namelist()) -1:
iseof = rclexecm.RclExecM.eofnext
if isinstance(ipath, unicode):
ipath = ipath.encode("utf-8")
return (ok, docdata, ipath, iseof)
return (ok, docdata, rclexecm.makebytes(ipath), iseof)
###### File type handler api, used by rclexecm ---------->
def openfile(self, params):
@@ -96,7 +112,14 @@ class ZipExtractor:
self.skiplist = skipped.split(" ")
try:
self.zip = ZipFile(filename)
if rclexecm.PY3:
# Note: python3 ZipFile wants an str file name, which
# is wrong: file names are binary. But it accepts an
# open file, and open() has no such restriction
f = open(filename, 'rb')
self.zip = ZipFile(f)
else:
self.zip = ZipFile(filename)
return True
except Exception as err:
self.em.rclog("openfile: failed: [%s]" % err)