From 4444113414e09e8de4e359a70b62e97ecbf6a888 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Mon, 14 Dec 2015 23:07:06 +0100 Subject: [PATCH] remove misc. compat code not needed for py 3.4+ --- borg/compress.pyx | 2 +- borg/key.py | 9 +-------- borg/remote.py | 2 +- borg/repository.py | 2 +- borg/xattr.py | 3 --- 5 files changed, 4 insertions(+), 14 deletions(-) diff --git a/borg/compress.pyx b/borg/compress.pyx index 2285b55d8..3bb88def7 100644 --- a/borg/compress.pyx +++ b/borg/compress.pyx @@ -110,7 +110,7 @@ cdef class LZ4(CompressorBase): class LZMA(CompressorBase): """ - lzma compression / decompression (python 3.3+ stdlib) + lzma compression / decompression """ ID = b'\x02\x00' name = 'lzma' diff --git a/borg/key.py b/borg/key.py index a39b1e318..7ee6305fb 100644 --- a/borg/key.py +++ b/borg/key.py @@ -4,7 +4,7 @@ import getpass import os import sys import textwrap -import hmac +from hmac import HMAC from hashlib import sha256 from .helpers import IntegrityError, get_keys_dir, Error @@ -30,13 +30,6 @@ class RepoKeyNotFoundError(Error): """No key entry found in the config of repository {}.""" -class HMAC(hmac.HMAC): - """Workaround a bug in Python < 3.4 Where HMAC does not accept memoryviews - """ - def update(self, msg): - self.inner.update(msg) - - def key_creator(repository, args): if args.encryption == 'keyfile': return KeyfileKey.create(repository, args) diff --git a/borg/remote.py b/borg/remote.py index d8092ec71..1f05d35ee 100644 --- a/borg/remote.py +++ b/borg/remote.py @@ -268,7 +268,7 @@ class RemoteRepository: if not data: raise ConnectionClosed() data = data.decode('utf-8') - for line in data.splitlines(True): # keepends=True for py3.3+ + for line in data.splitlines(keepends=True): if line.startswith('$LOG '): _, level, msg = line.split(' ', 2) level = getattr(logging, level, logging.CRITICAL) # str -> int diff --git a/borg/repository.py b/borg/repository.py index 0789a0213..1e5902f2f 100644 --- a/borg/repository.py +++ b/borg/repository.py @@ -685,7 +685,7 @@ class LoggedIO: self.offset = 0 self._write_fd.flush() os.fsync(self._write_fd.fileno()) - if hasattr(os, 'posix_fadvise'): # python >= 3.3, only on UNIX + if hasattr(os, 'posix_fadvise'): # only on UNIX # tell the OS that it does not need to cache what we just wrote, # avoids spoiling the cache for the OS and other processes. os.posix_fadvise(self._write_fd.fileno(), 0, 0, os.POSIX_FADV_DONTNEED) diff --git a/borg/xattr.py b/borg/xattr.py index 7eafaa831..c3e854924 100644 --- a/borg/xattr.py +++ b/borg/xattr.py @@ -231,9 +231,6 @@ elif sys.platform.startswith('freebsd'): # pragma: freebsd only mv = memoryview(namebuf.raw) while mv: length = mv[0] - # Python < 3.3 returns bytes instead of int - if isinstance(length, bytes): - length = ord(length) names.append(os.fsdecode(bytes(mv[1:1+length]))) mv = mv[1+length:] return names