diff --git a/src/filters/cmdtalk.py b/src/filters/cmdtalk.py index 66630d36..a41d1def 100644 --- a/src/filters/cmdtalk.py +++ b/src/filters/cmdtalk.py @@ -20,8 +20,6 @@ # All data is binary. This is important for Python3 # All parameter names are converted to and processed as str/unicode -from __future__ import print_function - import sys import os import tempfile diff --git a/src/filters/rclbasehandler.py b/src/filters/rclbasehandler.py index 904c30fb..a095b517 100644 --- a/src/filters/rclbasehandler.py +++ b/src/filters/rclbasehandler.py @@ -18,8 +18,6 @@ # Base for extractor classes. With some common generic implementations # for the boilerplate functions. -from __future__ import print_function - import os import sys import rclexecm diff --git a/src/filters/rcldia.py b/src/filters/rcldia.py index 45dbeb16..f0df5438 100755 --- a/src/filters/rcldia.py +++ b/src/filters/rcldia.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -from __future__ import print_function # dia (http://live.gnome.org/Dia) file filter for recoll # stefan.friedel@iwr.uni-heidelberg.de 2012 diff --git a/src/filters/rcldjvu.py b/src/filters/rcldjvu.py index 655d8de2..16e4a4b8 100755 --- a/src/filters/rcldjvu.py +++ b/src/filters/rcldjvu.py @@ -17,8 +17,6 @@ # Recoll DJVU extractor -from __future__ import print_function - import os import sys import re diff --git a/src/filters/rcldoc.py b/src/filters/rcldoc.py index dc303b40..c58240b5 100755 --- a/src/filters/rcldoc.py +++ b/src/filters/rcldoc.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -from __future__ import print_function import rclexecm import rclexec1 diff --git a/src/filters/rclepub.py b/src/filters/rclepub.py index 4775c5bd..11eaacca 100755 --- a/src/filters/rclepub.py +++ b/src/filters/rclepub.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 """Extract Html content from an EPUB file (.epub)""" -from __future__ import print_function rclepub_html_mtype = "text/html" diff --git a/src/filters/rclepub1.py b/src/filters/rclepub1.py index 2d087a63..b55e7ff0 100755 --- a/src/filters/rclepub1.py +++ b/src/filters/rclepub1.py @@ -1,6 +1,5 @@ #!/usr/bin/env python3 """Extract Html content from an EPUB file (.chm), concatenating all sections""" -from __future__ import print_function import sys import os diff --git a/src/filters/rclexec1.py b/src/filters/rclexec1.py index 03831e29..f7622b03 100644 --- a/src/filters/rclexec1.py +++ b/src/filters/rclexec1.py @@ -26,8 +26,6 @@ # this would be to slow. So this helps implementing a permanent script # to repeatedly execute single commands. -from __future__ import print_function - import subprocess import rclexecm from rclbasehandler import RclBaseHandler diff --git a/src/filters/rclexecm.py b/src/filters/rclexecm.py index f078b1e6..57d8c40a 100644 --- a/src/filters/rclexecm.py +++ b/src/filters/rclexecm.py @@ -20,8 +20,6 @@ # All data is binary. This is important for Python3 # All parameter names are converted to and processed as str/unicode -from __future__ import print_function - import sys import os import tempfile @@ -30,7 +28,6 @@ import getopt import rclconfig import cmdtalk -PY3 = (sys.version > '3') _g_mswindows = (sys.platform == "win32") _g_execdir = os.path.dirname(sys.argv[0]) @@ -62,12 +59,11 @@ def makebytes(data): # Possibly decode binary file name for use as subprocess argument, # depending on platform. def subprocfile(fn): - # On Windows PY3 the list2cmdline() method in subprocess assumes that - # all args are str, and we receive file names as UTF-8. So we need - # to convert. - # On Unix all list elements get converted to bytes in the C - # _posixsubprocess module, nothing to do. - if PY3 and _g_mswindows and type(fn) != type(''): + # On Windows Python 3 the list2cmdline() method in subprocess assumes that all args are str, and + # we receive file names as UTF-8. So we need to convert. + # On Unix all list elements get converted to bytes in the C _posixsubprocess module, nothing to + # do. + if _g_mswindows and type(fn) != type(''): return fn.decode('UTF-8') else: return fn @@ -383,10 +379,7 @@ def main(proto, extract): print("Open error", file=sys.stderr) sys.exit(1) - if PY3: - ioout = sys.stdout.buffer - else: - ioout = sys.stdout + ioout = sys.stdout.buffer if ipath != b"" or actAsSingle: params['ipath'] = ipath ok, data, ipath, eof = extract.getipath(params) diff --git a/src/filters/rclfb2.py b/src/filters/rclfb2.py index 6b39d80e..ec099732 100755 --- a/src/filters/rclfb2.py +++ b/src/filters/rclfb2.py @@ -16,8 +16,6 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ###################################### -from __future__ import print_function - import sys import rclexecm import rclxslt diff --git a/src/filters/rclgenxslt.py b/src/filters/rclgenxslt.py index ed44a2b3..4946abcb 100755 --- a/src/filters/rclgenxslt.py +++ b/src/filters/rclgenxslt.py @@ -18,8 +18,6 @@ # Base class for simple (one stylesheet) xslt-based handlers -from __future__ import print_function - import sys import rclxslt import gzip diff --git a/src/filters/rclics.py b/src/filters/rclics.py index 7512a862..218b3661 100755 --- a/src/filters/rclics.py +++ b/src/filters/rclics.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -from __future__ import print_function # Read an ICS file, break it into "documents" which are events, todos, # or journal entries, and interface with recoll execm diff --git a/src/filters/rclimg.py b/src/filters/rclimg.py index 783aa1d4..5c863dec 100755 --- a/src/filters/rclimg.py +++ b/src/filters/rclimg.py @@ -6,7 +6,6 @@ # # Uses pyexiv2. Also tried Pillow, found it useless for tags. # -from __future__ import print_function import sys import os diff --git a/src/filters/rclinfo.py b/src/filters/rclinfo.py index ff5d711d..2cc024f7 100755 --- a/src/filters/rclinfo.py +++ b/src/filters/rclinfo.py @@ -3,8 +3,6 @@ # Read a file in GNU info format and output its nodes as subdocs, # interfacing with recoll execm -from __future__ import print_function - import rclexecm import sys import os diff --git a/src/filters/rclipynb.py b/src/filters/rclipynb.py index d3815689..c21929f1 100755 --- a/src/filters/rclipynb.py +++ b/src/filters/rclipynb.py @@ -17,8 +17,6 @@ # Recoll handler for iPython / Jupyter notebook files. -from __future__ import print_function - import os import sys import json diff --git a/src/filters/rclkar.py b/src/filters/rclkar.py index b30865a9..4b545376 100755 --- a/src/filters/rclkar.py +++ b/src/filters/rclkar.py @@ -1,8 +1,6 @@ #!/usr/bin/env python3 # Read a .kar midi karaoke file and translate to recoll indexable format -# This does not work with Python3 yet because python:midi doesn't -from __future__ import print_function import rclexecm import sys @@ -46,11 +44,7 @@ htmltemplate = ''' nlbytes = b'\n' bsbytes = b'\\' -PY3 = sys.version > '3' -if PY3: - nullchar = 0 -else: - nullchar = chr(0) +nullchar = 0 class KarTextExtractor(RclBaseHandler): # Afaik, the only charset encodings with null bytes are variations on diff --git a/src/filters/rcllatinclass.py b/src/filters/rcllatinclass.py index e1b2aee0..473e3511 100755 --- a/src/filters/rcllatinclass.py +++ b/src/filters/rcllatinclass.py @@ -13,12 +13,7 @@ epsilon with dasia (in unicode but not iso). Can this be replaced by either epsi with acute accent ? """ -from __future__ import print_function - import sys -PY3 = sys.version > '3' -if not PY3: - import string import glob import os import os.path @@ -38,10 +33,7 @@ class European8859TextClassifier: # Table to translate from punctuation to spaces self.punct = b'''0123456789<>/*?[].@+-,#_$%&={};.,:!"''' + b"'\n\r" spaces = len(self.punct) * b' ' - if PY3: - self.spacetable = bytes.maketrans(self.punct, spaces) - else: - self.spacetable = string.maketrans(self.punct, spaces) + self.spacetable = bytes.maketrans(self.punct, spaces) def readlanguages(self, langzip): """Extract the stop words lists from the zip file. diff --git a/src/filters/rclmidi.py b/src/filters/rclmidi.py index f11a61ba..24067092 100644 --- a/src/filters/rclmidi.py +++ b/src/filters/rclmidi.py @@ -23,24 +23,15 @@ # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # -from __future__ import print_function import sys from struct import unpack, pack import six -PY3 = sys.version > '3' - -if PY3: - def next_byte_as_int(data): - return next(data) - def next_byte_as_char(data): - return bytes([next(data)]) -else: - def next_byte_as_int(data): - return ord(data.next()) - def next_byte_as_char(data): - return next(data) +def next_byte_as_int(data): + return next(data) +def next_byte_as_char(data): + return bytes([next(data)]) ## ## Constants @@ -270,12 +261,8 @@ class NoteEvent(Event): self.velocity) def decode_data(self): - if PY3: - self.pitch = self.data[0] - self.velocity = self.data[1] - else: - self.pitch = ord(self.data[0]) - self.velocity = ord(self.data[1]) + self.pitch = self.data[0] + self.velocity = self.data[1] class NoteOnEvent(NoteEvent): @@ -309,12 +296,8 @@ class ControlChangeEvent(Event): hex(ord(self.data[1]))) def decode_data(self): - if PY3: - self.control = self.data[0] - self.value = self.data[1] - else: - self.control = ord(self.data[0]) - self.value = ord(self.data[1]) + self.control = self.data[0] + self.value = self.data[1] class ProgramChangeEvent(Event): @@ -328,10 +311,7 @@ class ProgramChangeEvent(Event): hex(ord(self.data[0]))) def decode_data(self): - if PY3: - self.value = self.data[0] - else: - self.value = ord(self.data[0]) + self.value = self.data[0] class ChannelAfterTouchEvent(Event): @@ -356,12 +336,8 @@ class PitchWheelEvent(Event): hex(ord(self.data[1]))) def decode_data(self): - if PY3: - first = self.data[0] - second = self.data[1] - else: - first = ord(self.data[0]) - second = ord(self.data[1]) + first = self.data[0] + second = self.data[1] self.value = ((second << 7) | first) - 0x2000 @@ -461,10 +437,7 @@ class PortEvent(MetaEvent): def decode_data(self): assert(len(self.data) == 1) - if PY3: - self.port = self.data[0] - else: - self.port = ord(self.data[0]) + self.port = self.data[0] class TrackLoopEvent(MetaEvent): name = 'Track Loop' @@ -498,13 +471,7 @@ class SetTempoEvent(MetaEvent): def decode_data(self): assert(len(self.data) == 3) - if PY3: - self.mpqn = (self.data[0] << 16) + (self.data[1] << 8) \ - + self.data[2] - else: - self.mpqn = (ord(self.data[0]) << 16) + (ord(self.data[1]) << 8) \ - + ord(self.data[2]) - + self.mpqn = (self.data[0] << 16) + (self.data[1] << 8) + self.data[2] self.tempo = float(6e7) / self.mpqn @@ -523,22 +490,13 @@ class TimeSignatureEvent(MetaEvent): (super(TimeSignatureEvent, self).__str__(), self.numerator, self.denominator, self.metronome, self.thirtyseconds) - if PY3: - def decode_data(self): - assert(len(self.data) == 4) - self.numerator = self.data[0] - # Weird: the denominator is two to the power of the data variable - self.denominator = 2 ** self.data[1] - self.metronome = self.data[2] - self.thirtyseconds = self.data[3] - else: - def decode_data(self): - assert(len(self.data) == 4) - self.numerator = ord(self.data[0]) - # Weird: the denominator is two to the power of the data variable - self.denominator = 2 ** ord(self.data[1]) - self.metronome = ord(self.data[2]) - self.thirtyseconds = ord(self.data[3]) + def decode_data(self): + assert(len(self.data) == 4) + self.numerator = self.data[0] + # Weird: the denominator is two to the power of the data variable + self.denominator = 2 ** self.data[1] + self.metronome = self.data[2] + self.thirtyseconds = self.data[3] class KeySignatureEvent(MetaEvent): diff --git a/src/filters/rclppt.py b/src/filters/rclppt.py index d7b0b0a6..daca4807 100755 --- a/src/filters/rclppt.py +++ b/src/filters/rclppt.py @@ -2,8 +2,6 @@ # Recoll PPT text extractor -from __future__ import print_function - import rclexecm import rclexec1 import re diff --git a/src/filters/rclrar.py b/src/filters/rclrar.py index 4c3fa766..7b6fa15f 100755 --- a/src/filters/rclrar.py +++ b/src/filters/rclrar.py @@ -18,8 +18,6 @@ # Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -from __future__ import print_function - import sys import rclexecm import os diff --git a/src/filters/rclrtf.py b/src/filters/rclrtf.py index 25be690e..3b593b0c 100755 --- a/src/filters/rclrtf.py +++ b/src/filters/rclrtf.py @@ -1,5 +1,4 @@ #!/usr/bin/env python3 -from __future__ import print_function import rclexecm import rclexec1 diff --git a/src/filters/rcltar.py b/src/filters/rcltar.py index 1389c703..b3bd808a 100755 --- a/src/filters/rcltar.py +++ b/src/filters/rcltar.py @@ -6,8 +6,6 @@ # It works not only for tar-files, but automatically for gzipped and # bzipped tar-files at well. -from __future__ import print_function - import rclexecm try: diff --git a/src/filters/rcltext.py b/src/filters/rcltext.py index 91d8be13..76c86230 100755 --- a/src/filters/rcltext.py +++ b/src/filters/rcltext.py @@ -18,8 +18,6 @@ # Wrapping a text file. Recoll does it internally in most cases, but # this is for use by another filter. -from __future__ import print_function - import rclexecm import sys from rclbasehandler import RclBaseHandler diff --git a/src/filters/rcltxtlines.py b/src/filters/rcltxtlines.py index 05746c1d..93da938e 100755 --- a/src/filters/rcltxtlines.py +++ b/src/filters/rcltxtlines.py @@ -2,7 +2,6 @@ """Index text lines as document (execm handler sample). This exists to demonstrate the execm interface and is not meant to be useful or efficient""" -from __future__ import print_function import sys import os diff --git a/src/filters/rcluncomp.py b/src/filters/rcluncomp.py index 8bb9edc1..e6b37a30 100644 --- a/src/filters/rcluncomp.py +++ b/src/filters/rcluncomp.py @@ -1,5 +1,4 @@ # No shebang: this is only used on Windows. We use a shell script on Linux -from __future__ import print_function import rclexecm import sys diff --git a/src/filters/rclwar.py b/src/filters/rclwar.py index fa251bc3..a4e07089 100755 --- a/src/filters/rclwar.py +++ b/src/filters/rclwar.py @@ -2,8 +2,6 @@ # WAR web archive filter for recoll. War file are gzipped tar files -from __future__ import print_function - import rclexecm import tarfile diff --git a/src/filters/rclxmp.py b/src/filters/rclxmp.py index fecb37c1..334adca0 100755 --- a/src/filters/rclxmp.py +++ b/src/filters/rclxmp.py @@ -16,7 +16,6 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # Code to extract XMP tags using libexempi and python-xmp -from __future__ import print_function can_xmp = True try: diff --git a/src/filters/rclzip.py b/src/filters/rclzip.py index 116609db..a80a5f3f 100755 --- a/src/filters/rclzip.py +++ b/src/filters/rclzip.py @@ -18,8 +18,6 @@ # Zip file extractor for Recoll -from __future__ import print_function - import os import posixpath import fnmatch @@ -155,14 +153,11 @@ class ZipExtractor: if skipped is not None: self.skiplist += conftree.stringToStrings(skipped) try: - if rclexecm.PY3: - # Note: py3 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 - self.f = open(filename, 'rb') - self.zip = ZipFile(self.f) - else: - self.zip = ZipFile(filename) + # Note: py3 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 + self.f = open(filename, 'rb') + self.zip = ZipFile(self.f) return True except Exception as err: self.em.rclog("openfile: failed: [%s]" % err) diff --git a/src/filters/xlsxmltocsv.py b/src/filters/xlsxmltocsv.py index 094184fc..c7cf1ac0 100755 --- a/src/filters/xlsxmltocsv.py +++ b/src/filters/xlsxmltocsv.py @@ -23,8 +23,6 @@ # the minimum version supported. -from __future__ import print_function - import sys import xml.sax