Remove the custom OrderedDict implementation since we no longer support python < 2.7

This commit is contained in:
Kovid Goyal 2011-03-24 13:01:43 -06:00
parent d8d83e6475
commit 78fbab07a7
10 changed files with 11 additions and 123 deletions

View File

@ -10,10 +10,10 @@ import re
from lxml import etree from lxml import etree
from urlparse import urlparse from urlparse import urlparse
from collections import OrderedDict
from calibre.ebooks.oeb.base import XPNSMAP, TOC, XHTML, xml2text from calibre.ebooks.oeb.base import XPNSMAP, TOC, XHTML, xml2text
from calibre.ebooks import ConversionError from calibre.ebooks import ConversionError
from calibre.utils.ordered_dict import OrderedDict
def XPath(x): def XPath(x):
try: try:

View File

@ -9,6 +9,7 @@ Scheduler for automated recipe downloads
from datetime import timedelta from datetime import timedelta
import calendar, textwrap import calendar, textwrap
from collections import OrderedDict
from PyQt4.Qt import QDialog, Qt, QTime, QObject, QMenu, QHBoxLayout, \ from PyQt4.Qt import QDialog, Qt, QTime, QObject, QMenu, QHBoxLayout, \
QAction, QIcon, QMutex, QTimer, pyqtSignal, QWidget, QGridLayout, \ 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.ptempfile import PersistentTemporaryFile
from calibre.utils.date import utcnow from calibre.utils.date import utcnow
from calibre.utils.network import internet_connected from calibre.utils.network import internet_connected
from calibre.utils.ordered_dict import OrderedDict
from calibre import force_unicode from calibre import force_unicode
def convert_day_time_schedule(val): def convert_day_time_schedule(val):

View File

@ -7,6 +7,7 @@ __docformat__ = 'restructuredtext en'
import textwrap import textwrap
from functools import partial from functools import partial
from collections import OrderedDict
from PyQt4.Qt import QMainWindow, Qt, QIcon, QStatusBar, QFont, QWidget, \ from PyQt4.Qt import QMainWindow, Qt, QIcon, QStatusBar, QFont, QWidget, \
QScrollArea, QStackedWidget, QVBoxLayout, QLabel, QFrame, QKeySequence, \ QScrollArea, QStackedWidget, QVBoxLayout, QLabel, QFrame, QKeySequence, \
@ -18,7 +19,6 @@ from calibre.gui2 import gprefs, min_available_height, available_width, \
warning_dialog warning_dialog
from calibre.gui2.preferences import init_gui, AbortCommit, get_plugin from calibre.gui2.preferences import init_gui, AbortCommit, get_plugin
from calibre.customize.ui import preferences_plugins from calibre.customize.ui import preferences_plugins
from calibre.utils.ordered_dict import OrderedDict
ICON_SIZE = 32 ICON_SIZE = 32

View File

@ -6,6 +6,7 @@ __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
import textwrap, os import textwrap, os
from collections import OrderedDict
from PyQt4.Qt import Qt, QModelIndex, QAbstractItemModel, QVariant, QIcon, \ from PyQt4.Qt import Qt, QModelIndex, QAbstractItemModel, QVariant, QIcon, \
QBrush QBrush
@ -19,7 +20,6 @@ from calibre.gui2 import NONE, error_dialog, info_dialog, choose_files, \
question_dialog, gprefs question_dialog, gprefs
from calibre.utils.search_query_parser import SearchQueryParser from calibre.utils.search_query_parser import SearchQueryParser
from calibre.utils.icu import lower from calibre.utils.icu import lower
from calibre.utils.ordered_dict import OrderedDict
class PluginModel(QAbstractItemModel, SearchQueryParser): # {{{ class PluginModel(QAbstractItemModel, SearchQueryParser): # {{{

View File

@ -12,6 +12,8 @@ __docformat__ = 'restructuredtext en'
import collections, os, sys, textwrap, time, gc import collections, os, sys, textwrap, time, gc
from Queue import Queue, Empty from Queue import Queue, Empty
from threading import Thread from threading import Thread
from collections import OrderedDict
from PyQt4.Qt import (Qt, SIGNAL, QTimer, QHelpEvent, QAction, from PyQt4.Qt import (Qt, SIGNAL, QTimer, QHelpEvent, QAction,
QMenu, QIcon, pyqtSignal, QUrl, QMenu, QIcon, pyqtSignal, QUrl,
QDialog, QSystemTrayIcon, QApplication, QKeySequence) 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_box import SearchBoxMixin, SavedSearchBoxMixin
from calibre.gui2.search_restriction_mixin import SearchRestrictionMixin from calibre.gui2.search_restriction_mixin import SearchRestrictionMixin
from calibre.gui2.tag_view import TagBrowserMixin from calibre.gui2.tag_view import TagBrowserMixin
from calibre.utils.ordered_dict import OrderedDict
class Listener(Thread): # {{{ class Listener(Thread): # {{{

View File

@ -4,8 +4,8 @@ Created on 25 May 2010
@author: charles @author: charles
''' '''
import copy, traceback import copy, traceback
from collections import OrderedDict
from calibre.utils.ordered_dict import OrderedDict
from calibre.utils.config import tweaks from calibre.utils.config import tweaks
class TagsIcons(dict): class TagsIcons(dict):

View File

@ -7,13 +7,13 @@ __docformat__ = 'restructuredtext en'
import operator, os, json, re import operator, os, json, re
from binascii import hexlify, unhexlify from binascii import hexlify, unhexlify
from collections import OrderedDict
import cherrypy import cherrypy
from calibre.constants import filesystem_encoding from calibre.constants import filesystem_encoding
from calibre import isbytestring, force_unicode, fit_image, \ from calibre import isbytestring, force_unicode, fit_image, \
prepare_string_for_xml prepare_string_for_xml
from calibre.utils.ordered_dict import OrderedDict
from calibre.utils.filenames import ascii_filename from calibre.utils.filenames import ascii_filename
from calibre.utils.config import prefs from calibre.utils.config import prefs
from calibre.utils.icu import sort_key from calibre.utils.icu import sort_key

View File

@ -5,8 +5,9 @@ __license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>' __copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en' __docformat__ = 'restructuredtext en'
from collections import OrderedDict
from calibre.utils.date import utcnow from calibre.utils.date import utcnow
from calibre.utils.ordered_dict import OrderedDict
class Cache(object): class Cache(object):

View File

@ -8,6 +8,7 @@ __docformat__ = 'restructuredtext en'
import hashlib, binascii import hashlib, binascii
from functools import partial from functools import partial
from itertools import repeat from itertools import repeat
from collections import OrderedDict
from lxml import etree, html from lxml import etree, html
from lxml.builder import ElementMaker 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.library.server.utils import format_tag_string, Offsets
from calibre import guess_type, prepare_string_for_xml as xml from calibre import guess_type, prepare_string_for_xml as xml
from calibre.utils.icu import sort_key from calibre.utils.icu import sort_key
from calibre.utils.ordered_dict import OrderedDict
BASE_HREFS = { BASE_HREFS = {
0 : '/stanza', 0 : '/stanza',

View File

@ -1,114 +0,0 @@
#!/usr/bin/env python
__license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
'''
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