summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2020-08-25 16:39:00 +0200
committerMichał Górny <mgorny@gentoo.org>2020-08-25 16:39:00 +0200
commit992e6c972786a148ac3e5044a321772b7bae7fb1 (patch)
treeb0d7577e6d62e7dbc59d18aca10fcd2fae55f09d
parentbb29ed4e90facfa510af7685e0e658b501957620 (diff)
downloadgemato-992e6c972786a148ac3e5044a321772b7bae7fb1.tar.gz
Remove compatibility code for py<3.6 support
Signed-off-by: Michał Górny <mgorny@gentoo.org>
-rw-r--r--gemato/cli.py20
-rw-r--r--gemato/compression.py35
-rw-r--r--gemato/hash.py22
-rw-r--r--gemato/manifest.py9
-rw-r--r--tests/testutil.py14
5 files changed, 13 insertions, 87 deletions
diff --git a/gemato/cli.py b/gemato/cli.py
index 3b5786e..c8e1813 100644
--- a/gemato/cli.py
+++ b/gemato/cli.py
@@ -1,6 +1,6 @@
# gemato: CLI routines
# vim:fileencoding=utf-8
-# (c) 2017-2019 Michał Górny
+# (c) 2017-2020 Michał Górny
# Licensed under the terms of 2-clause BSD license
from __future__ import print_function
@@ -456,11 +456,8 @@ class HashCommand(GematoCommand):
for p in self.paths:
if p == '-':
- if sys.hexversion >= 0x03000000:
- f = sys.stdin.buffer
- else:
- f = sys.stdin
- h = gemato.hash.hash_file(f, hashlib_hashes)
+ h = gemato.hash.hash_file(sys.stdin.buffer,
+ hashlib_hashes)
else:
h = gemato.hash.hash_path(p, hashlib_hashes)
@@ -492,10 +489,7 @@ class OpenPGPVerifyCommand(VerifyingOpenPGPMixin, GematoCommand):
for p in self.paths:
if p == '-':
- if sys.hexversion >= 0x03000000:
- f = sys.stdin
- else:
- f = io.open(sys.stdin.fileno(), 'r')
+ f = sys.stdin
else:
f = io.open(p, 'r')
@@ -554,8 +548,4 @@ def main(argv):
def setuptools_main():
logging.getLogger().setLevel(logging.INFO)
- if sys.hexversion < 0x03000000:
- argv = [x.decode(sys.getfilesystemencoding()) for x in sys.argv]
- else:
- argv = sys.argv
- sys.exit(main(argv))
+ sys.exit(main(sys.argv))
diff --git a/gemato/compression.py b/gemato/compression.py
index 145c0bf..cf021cd 100644
--- a/gemato/compression.py
+++ b/gemato/compression.py
@@ -1,33 +1,13 @@
# gemato: compressed file support
# vim:fileencoding=utf-8
-# (c) 2017-2018 Michał Górny
+# (c) 2017-2020 Michał Górny
# Licensed under the terms of 2-clause BSD license
+import bz2
import gzip
import io
+import lzma
import os.path
-import sys
-
-if sys.hexversion >= 0x03030000:
- import bz2
-else:
- # older bz2 module versions do not handle multiple streams correctly
- # so use the backport instead
- try:
- import bz2file as bz2
- except ImportError:
- bz2 = None
-
-# Python 3.3+ has a built-in lzma module. Older versions may have
-# an incompatible external module of the same name, so explicitly
-# force using the backport there.
-if sys.hexversion >= 0x03030000:
- import lzma
-else:
- try:
- import backports.lzma as lzma
- except ImportError:
- lzma = None
import gemato.exceptions
@@ -46,15 +26,6 @@ def open_compressed_file(suffix, f, mode='rb'):
"""
if suffix == "gz":
- # work-around the deficiency in GzipFile class in py<3.3 causing
- # it to break with TextIOWrapper
- if sys.hexversion < 0x03030000:
- class FixedGzipFile(gzip.GzipFile):
- def read1(self, *args, **kwargs):
- return self.read(*args, **kwargs)
-
- return FixedGzipFile(fileobj=f, mode=mode, filename='', mtime=0)
-
return gzip.GzipFile(fileobj=f, mode=mode, filename='', mtime=0)
elif suffix == "bz2" and bz2 is not None:
return bz2.BZ2File(f, mode=mode)
diff --git a/gemato/hash.py b/gemato/hash.py
index d8691e1..515bfd9 100644
--- a/gemato/hash.py
+++ b/gemato/hash.py
@@ -42,28 +42,6 @@ def get_hash_by_name(name):
if name in hashlib.algorithms_available:
return hashlib.new(name)
- # fallback support
- if name.startswith('sha3_'):
- try:
- import sha3
- except ImportError:
- pass
- else:
- try:
- return getattr(sha3, name)()
- except AttributeError:
- pass
- elif name.startswith('blake2'):
- try:
- import pyblake2
- except ImportError:
- pass
- else:
- try:
- return getattr(pyblake2, name)()
- except AttributeError:
- pass
-
raise gemato.exceptions.UnsupportedHash(name)
diff --git a/gemato/manifest.py b/gemato/manifest.py
index 3886d0d..ae1eb68 100644
--- a/gemato/manifest.py
+++ b/gemato/manifest.py
@@ -1,13 +1,12 @@
# gemato: Manifest file objects
# vim:fileencoding=utf-8
-# (c) 2017-2018 Michał Górny
+# (c) 2017-2020 Michał Górny
# Licensed under the terms of 2-clause BSD license
import datetime
import io
import os.path
import re
-import sys
import gemato.exceptions
import gemato.util
@@ -49,10 +48,6 @@ class ManifestEntryTIMESTAMP(object):
or (self.tag == other.tag and self.ts < other.ts))
-if sys.hexversion >= 0x03000000:
- unichr = chr
-
-
class ManifestPathEntry(object):
"""
Base class for entries using a path.
@@ -71,7 +66,7 @@ class ManifestPathEntry(object):
if val is None:
raise gemato.exceptions.ManifestSyntaxError(
'Invalid escape sequence at pos {} of: {}'.format(m.start(), m.string))
- return unichr(int(val[1:], base=16))
+ return chr(int(val[1:], base=16))
@classmethod
def process_path(cls, l):
diff --git a/tests/testutil.py b/tests/testutil.py
index 46800b3..f39533a 100644
--- a/tests/testutil.py
+++ b/tests/testutil.py
@@ -11,27 +11,19 @@ import os
import os.path
import random
import shutil
-import sys
import tempfile
import threading
import unittest
-if sys.hexversion >= 0x03000000:
- from http.server import HTTPServer, BaseHTTPRequestHandler
- from urllib.parse import urlparse, parse_qs
-else:
- from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
- from urlparse import urlparse, parse_qs
+from http.server import HTTPServer, BaseHTTPRequestHandler
+from urllib.parse import urlparse, parse_qs
import gemato.openpgp
class LoggingTestCase(unittest.TestCase):
def setUp(self):
- if sys.hexversion < 0x03000000:
- self.log = io.BytesIO()
- else:
- self.log = io.StringIO()
+ self.log = io.StringIO()
self.log_handler = logging.getLogger().addHandler(
logging.StreamHandler(self.log))