diff --git a/src/calibre/ebooks/oeb/transforms/structure.py b/src/calibre/ebooks/oeb/transforms/structure.py index 0d8bdcdf2e..613429c3ec 100644 --- a/src/calibre/ebooks/oeb/transforms/structure.py +++ b/src/calibre/ebooks/oeb/transforms/structure.py @@ -10,10 +10,10 @@ import re from lxml import etree from urlparse import urlparse +from collections import OrderedDict from calibre.ebooks.oeb.base import XPNSMAP, TOC, XHTML, xml2text from calibre.ebooks import ConversionError -from calibre.utils.ordered_dict import OrderedDict def XPath(x): try: diff --git a/src/calibre/gui2/dialogs/scheduler.py b/src/calibre/gui2/dialogs/scheduler.py index 347eeb7019..9b1fe67f29 100644 --- a/src/calibre/gui2/dialogs/scheduler.py +++ b/src/calibre/gui2/dialogs/scheduler.py @@ -9,6 +9,7 @@ Scheduler for automated recipe downloads from datetime import timedelta import calendar, textwrap +from collections import OrderedDict from PyQt4.Qt import QDialog, Qt, QTime, QObject, QMenu, QHBoxLayout, \ QAction, QIcon, QMutex, QTimer, pyqtSignal, QWidget, QGridLayout, \ @@ -20,7 +21,6 @@ from calibre.web.feeds.recipes.model import RecipeModel from calibre.ptempfile import PersistentTemporaryFile from calibre.utils.date import utcnow from calibre.utils.network import internet_connected -from calibre.utils.ordered_dict import OrderedDict from calibre import force_unicode def convert_day_time_schedule(val): diff --git a/src/calibre/gui2/preferences/main.py b/src/calibre/gui2/preferences/main.py index f25cc85dce..699087c4bb 100644 --- a/src/calibre/gui2/preferences/main.py +++ b/src/calibre/gui2/preferences/main.py @@ -7,6 +7,7 @@ __docformat__ = 'restructuredtext en' import textwrap from functools import partial +from collections import OrderedDict from PyQt4.Qt import QMainWindow, Qt, QIcon, QStatusBar, QFont, QWidget, \ QScrollArea, QStackedWidget, QVBoxLayout, QLabel, QFrame, QKeySequence, \ @@ -18,7 +19,6 @@ from calibre.gui2 import gprefs, min_available_height, available_width, \ warning_dialog from calibre.gui2.preferences import init_gui, AbortCommit, get_plugin from calibre.customize.ui import preferences_plugins -from calibre.utils.ordered_dict import OrderedDict ICON_SIZE = 32 diff --git a/src/calibre/gui2/preferences/plugins.py b/src/calibre/gui2/preferences/plugins.py index 85221766f2..8151fe6021 100644 --- a/src/calibre/gui2/preferences/plugins.py +++ b/src/calibre/gui2/preferences/plugins.py @@ -6,6 +6,7 @@ __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' import textwrap, os +from collections import OrderedDict from PyQt4.Qt import Qt, QModelIndex, QAbstractItemModel, QVariant, QIcon, \ QBrush @@ -19,7 +20,6 @@ from calibre.gui2 import NONE, error_dialog, info_dialog, choose_files, \ question_dialog, gprefs from calibre.utils.search_query_parser import SearchQueryParser from calibre.utils.icu import lower -from calibre.utils.ordered_dict import OrderedDict class PluginModel(QAbstractItemModel, SearchQueryParser): # {{{ diff --git a/src/calibre/gui2/ui.py b/src/calibre/gui2/ui.py index 54f0bd3517..03aae37883 100644 --- a/src/calibre/gui2/ui.py +++ b/src/calibre/gui2/ui.py @@ -12,6 +12,8 @@ __docformat__ = 'restructuredtext en' import collections, os, sys, textwrap, time, gc from Queue import Queue, Empty from threading import Thread +from collections import OrderedDict + from PyQt4.Qt import (Qt, SIGNAL, QTimer, QHelpEvent, QAction, QMenu, QIcon, pyqtSignal, QUrl, QDialog, QSystemTrayIcon, QApplication, QKeySequence) @@ -37,7 +39,6 @@ from calibre.gui2.init import LibraryViewMixin, LayoutMixin from calibre.gui2.search_box import SearchBoxMixin, SavedSearchBoxMixin from calibre.gui2.search_restriction_mixin import SearchRestrictionMixin from calibre.gui2.tag_view import TagBrowserMixin -from calibre.utils.ordered_dict import OrderedDict class Listener(Thread): # {{{ diff --git a/src/calibre/library/field_metadata.py b/src/calibre/library/field_metadata.py index b8180f9f39..ae91283523 100644 --- a/src/calibre/library/field_metadata.py +++ b/src/calibre/library/field_metadata.py @@ -4,8 +4,8 @@ Created on 25 May 2010 @author: charles ''' import copy, traceback +from collections import OrderedDict -from calibre.utils.ordered_dict import OrderedDict from calibre.utils.config import tweaks class TagsIcons(dict): diff --git a/src/calibre/library/server/browse.py b/src/calibre/library/server/browse.py index 895fbb06e9..139e2b3ef9 100644 --- a/src/calibre/library/server/browse.py +++ b/src/calibre/library/server/browse.py @@ -7,13 +7,13 @@ __docformat__ = 'restructuredtext en' import operator, os, json, re from binascii import hexlify, unhexlify +from collections import OrderedDict import cherrypy from calibre.constants import filesystem_encoding from calibre import isbytestring, force_unicode, fit_image, \ prepare_string_for_xml -from calibre.utils.ordered_dict import OrderedDict from calibre.utils.filenames import ascii_filename from calibre.utils.config import prefs from calibre.utils.icu import sort_key diff --git a/src/calibre/library/server/cache.py b/src/calibre/library/server/cache.py index cc4f7a3886..2ad7b543cb 100644 --- a/src/calibre/library/server/cache.py +++ b/src/calibre/library/server/cache.py @@ -5,8 +5,9 @@ __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' +from collections import OrderedDict + from calibre.utils.date import utcnow -from calibre.utils.ordered_dict import OrderedDict class Cache(object): diff --git a/src/calibre/library/server/opds.py b/src/calibre/library/server/opds.py index bdd35c16f1..5f6180e68a 100644 --- a/src/calibre/library/server/opds.py +++ b/src/calibre/library/server/opds.py @@ -8,6 +8,7 @@ __docformat__ = 'restructuredtext en' import hashlib, binascii from functools import partial from itertools import repeat +from collections import OrderedDict from lxml import etree, html from lxml.builder import ElementMaker @@ -21,7 +22,6 @@ from calibre.library.server import custom_fields_to_display from calibre.library.server.utils import format_tag_string, Offsets from calibre import guess_type, prepare_string_for_xml as xml from calibre.utils.icu import sort_key -from calibre.utils.ordered_dict import OrderedDict BASE_HREFS = { 0 : '/stanza', diff --git a/src/calibre/utils/ordered_dict.py b/src/calibre/utils/ordered_dict.py deleted file mode 100644 index 8e0f267c89..0000000000 --- a/src/calibre/utils/ordered_dict.py +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env python - -__license__ = 'GPL v3' -__copyright__ = '2008, Kovid Goyal ' - -''' -A ordered dictionary. Use the builtin type on python >= 2.7 -''' - - -try: - from collections import OrderedDict - OrderedDict -except ImportError: - from UserDict import DictMixin - - class OrderedDict(dict, DictMixin): - - def __init__(self, *args, **kwds): - if len(args) > 1: - raise TypeError('expected at most 1 arguments, got %d' % len(args)) - try: - self.__end - except AttributeError: - self.clear() - self.update(*args, **kwds) - - def clear(self): - self.__end = end = [] - end += [None, end, end] # sentinel node for doubly linked list - self.__map = {} # key --> [key, prev, next] - dict.clear(self) - - def __setitem__(self, key, value): - if key not in self: - end = self.__end - curr = end[1] - curr[2] = end[1] = self.__map[key] = [key, curr, end] - dict.__setitem__(self, key, value) - - def __delitem__(self, key): - dict.__delitem__(self, key) - key, prev, next = self.__map.pop(key) - prev[2] = next - next[1] = prev - - def __iter__(self): - end = self.__end - curr = end[2] - while curr is not end: - yield curr[0] - curr = curr[2] - - def __reversed__(self): - end = self.__end - curr = end[1] - while curr is not end: - yield curr[0] - curr = curr[1] - - def popitem(self, last=True): - if not self: - raise KeyError('dictionary is empty') - if last: - key = reversed(self).next() - else: - key = iter(self).next() - value = self.pop(key) - return key, value - - def __reduce__(self): - items = [[k, self[k]] for k in self] - tmp = self.__map, self.__end - del self.__map, self.__end - inst_dict = vars(self).copy() - self.__map, self.__end = tmp - if inst_dict: - return (self.__class__, (items,), inst_dict) - return self.__class__, (items,) - - def keys(self): - return list(self) - - setdefault = DictMixin.setdefault - update = DictMixin.update - pop = DictMixin.pop - values = DictMixin.values - items = DictMixin.items - iterkeys = DictMixin.iterkeys - itervalues = DictMixin.itervalues - iteritems = DictMixin.iteritems - - def __repr__(self): - if not self: - return '%s()' % (self.__class__.__name__,) - return '%s(%r)' % (self.__class__.__name__, self.items()) - - def copy(self): - return self.__class__(self) - - @classmethod - def fromkeys(cls, iterable, value=None): - d = cls() - for key in iterable: - d[key] = value - return d - - def __eq__(self, other): - if isinstance(other, OrderedDict): - return len(self)==len(other) and self.items() == other.items() - return dict.__eq__(self, other) - - def __ne__(self, other): - return not self == other