handlers: remove remnant bits of python2 compat

This commit is contained in:
Jean-Francois Dockes 2022-09-05 10:43:50 +02:00
parent 27f4d1f321
commit c86cb9438b
29 changed files with 33 additions and 139 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -17,8 +17,6 @@
# Recoll DJVU extractor
from __future__ import print_function
import os
import sys
import re

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python3
from __future__ import print_function
import rclexecm
import rclexec1

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -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
if ipath != b"" or actAsSingle:
params['ipath'] = ipath
ok, data, ipath, eof = extract.getipath(params)

View File

@ -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

View File

@ -18,8 +18,6 @@
# Base class for simple (one stylesheet) xslt-based handlers
from __future__ import print_function
import sys
import rclxslt
import gzip

View File

@ -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

View File

@ -6,7 +6,6 @@
#
# Uses pyexiv2. Also tried Pillow, found it useless for tags.
#
from __future__ import print_function
import sys
import os

View File

@ -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

View File

@ -17,8 +17,6 @@
# Recoll handler for iPython / Jupyter notebook files.
from __future__ import print_function
import os
import sys
import json

View File

@ -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

View File

@ -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)
def readlanguages(self, langzip):
"""Extract the stop words lists from the zip file.

View File

@ -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):
def next_byte_as_int(data):
return next(data)
def next_byte_as_char(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)
##
## 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])
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])
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])
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])
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])
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,7 +490,6 @@ 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]
@ -531,14 +497,6 @@ class TimeSignatureEvent(MetaEvent):
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])
class KeySignatureEvent(MetaEvent):

View File

@ -2,8 +2,6 @@
# Recoll PPT text extractor
from __future__ import print_function
import rclexecm
import rclexec1
import re

View File

@ -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

View File

@ -1,5 +1,4 @@
#!/usr/bin/env python3
from __future__ import print_function
import rclexecm
import rclexec1

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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:

View File

@ -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)
return True
except Exception as err:
self.em.rclog("openfile: failed: [%s]" % err)

View File

@ -23,8 +23,6 @@
# the minimum version supported.
from __future__ import print_function
import sys
import xml.sax