diff --git a/beets/dbcore/query.py b/beets/dbcore/query.py index 7dc897412..17a45341d 100644 --- a/beets/dbcore/query.py +++ b/beets/dbcore/query.py @@ -464,11 +464,7 @@ def _to_epoch_time(date): """ epoch = datetime.fromtimestamp(0) delta = date - epoch - try: - return int(delta.total_seconds()) - except AttributeError: - # datetime.timedelta.total_seconds() is not available on Python 2.6 - return delta.seconds + delta.days * 24 * 3600 + return int(delta.total_seconds()) def _parse_periods(pattern): diff --git a/beets/logging.py b/beets/logging.py index ae6c11211..dee5faf35 100644 --- a/beets/logging.py +++ b/beets/logging.py @@ -25,16 +25,10 @@ from __future__ import (division, absolute_import, print_function, from copy import copy from logging import * # noqa -import sys import subprocess import threading -# We need special hacks for Python 2.6 due to logging.Logger being an -# old- style class and having no loggerClass attribute. -PY26 = sys.version_info[:2] == (2, 6) - - def logsafe(val): """Coerce a potentially "problematic" value so it can be formatted in a Unicode log string. @@ -93,21 +87,8 @@ class StrFormatLogger(Logger): def _log(self, level, msg, args, exc_info=None, extra=None, **kwargs): """Log msg.format(*args, **kwargs)""" m = self._LogMessage(msg, args, kwargs) - return Logger._log(self, level, m, (), exc_info, extra) - # We cannot call super(StrFormatLogger, self) because it is not - # allowed on old-style classes (py2), which Logger is in python 2.6. - # Moreover, we cannot make StrFormatLogger a new-style class (by - # declaring 'class StrFormatLogger(Logger, object)' because the class- - # patching stmt 'logger.__class__ = StrFormatLogger' would not work: - # both prev & new __class__ values must be either old- or new- style; - # no mixing allowed. + return super(StrFormatLogger, self)._log(level, m, (), exc_info, extra) - if PY26: - def getChild(self, suffix): - """Shameless copy from cpython's Lib/logging/__init__.py""" - if self.root is not self: - suffix = '.'.join((self.name, suffix)) - return self.manager.getLogger(suffix) class ThreadLocalLevelLogger(Logger): """A version of `Logger` whose level is thread-local instead of shared. @@ -136,6 +117,7 @@ class ThreadLocalLevelLogger(Logger): self.default_level = level self.setLevel(level) + class BeetsLogger(ThreadLocalLevelLogger, StrFormatLogger): pass @@ -149,35 +131,3 @@ def getLogger(name=None): return my_manager.getLogger(name) else: return Logger.root - - -# On Python 2.6, there is no Manager.loggerClass so we dynamically -# change the logger class. We must be careful to do that on new loggers -# only to avoid side-effects. -if PY26: - # Wrap Manager.getLogger. - old_getLogger = my_manager.getLogger - - def new_getLogger(name): - change_its_type = not isinstance(my_manager.loggerDict.get(name), - Logger) - # it either does not exist or is a placeholder - logger = old_getLogger(name) - if change_its_type: - logger.__class__ = BeetsLogger - return logger - - my_manager.getLogger = new_getLogger - - -# Offer NullHandler in Python 2.6 to reduce the difference with never versions -if PY26: - class NullHandler(Handler): - def handle(self, record): - pass - - def emit(self, record): - pass - - def createLock(self): - self.lock = None diff --git a/beets/util/__init__.py b/beets/util/__init__.py index a3b57eea6..ff9192abb 100644 --- a/beets/util/__init__.py +++ b/beets/util/__init__.py @@ -649,9 +649,8 @@ def command_output(cmd, shell=False): ``subprocess.CalledProcessError`` is raised. May also raise ``OSError``. - This replaces `subprocess.check_output`, which isn't available in - Python 2.6 and which can have problems if lots of output is sent to - stderr. + This replaces `subprocess.check_output` which can have problems if lots of + output is sent to stderr. """ proc = subprocess.Popen( cmd,