From b8213181f22185f09206ad09dc231e4902b5be53 Mon Sep 17 00:00:00 2001 From: "nathdwek@laptop" Date: Wed, 16 Nov 2016 23:08:00 +0100 Subject: [PATCH] drop IdentityFallbackDict: Used by mediafile to determine the preferred extension of an image That solution looked cool for 2 days, but in hindsight it was pretty bad --- beets/mediafile.py | 6 +++--- beets/util/collections.py | 30 ------------------------------ 2 files changed, 3 insertions(+), 33 deletions(-) delete mode 100644 beets/util/collections.py diff --git a/beets/mediafile.py b/beets/mediafile.py index 784695c1a..87a9d10a6 100644 --- a/beets/mediafile.py +++ b/beets/mediafile.py @@ -59,7 +59,6 @@ import enum from beets import logging from beets.util import displayable_path, syspath, as_string -from beets.util.collections import IdentityFallbackDict import six @@ -82,7 +81,7 @@ TYPES = { 'aiff': 'AIFF', } -PREFERRED_IMAGE_EXTENSIONS = IdentityFallbackDict({'jpeg': 'jpg'}) +PREFERRED_IMAGE_EXTENSIONS = {'jpeg': 'jpg'} # Exceptions. @@ -355,7 +354,8 @@ def image_mime_type(data): def image_extension(data): - return PREFERRED_IMAGE_EXTENSIONS[_imghdr_what_wrapper(data)] + ext = _imghdr_what_wrapper(data) + return PREFERRED_IMAGE_EXTENSIONS.get(ext, ext) class ImageType(enum.Enum): diff --git a/beets/util/collections.py b/beets/util/collections.py deleted file mode 100644 index 696dc9a98..000000000 --- a/beets/util/collections.py +++ /dev/null @@ -1,30 +0,0 @@ -# -*- coding: utf-8 -*- -# This file is part of beets. -# Copyright 2016, Adrian Sampson. -# -# Permission is hereby granted, free of charge, to any person obtaining -# a copy of this software and associated documentation files (the -# "Software"), to deal in the Software without restriction, including -# without limitation the rights to use, copy, modify, merge, publish, -# distribute, sublicense, and/or sell copies of the Software, and to -# permit persons to whom the Software is furnished to do so, subject to -# the following conditions: -# -# The above copyright notice and this permission notice shall be -# included in all copies or substantial portions of the Software. - -"""Custom collections classes. -""" - -from __future__ import division, absolute_import, print_function - - -class IdentityFallbackDict(dict): - """A dictionary which is "transparent" (maps keys to themselves) for all - keys not in it. - """ - def __getitem__(self, key): - try: - return dict.__getitem__(self, key) - except KeyError: - return key