Sfoglia il codice sorgente

Remove compatibility code for collections.defaultdict, in preparation of
dropping support for Python < 2.6.

Jelmer Vernooij 11 anni fa
parent
commit
1dabfc2542
4 ha cambiato i file con 3 aggiunte e 56 eliminazioni
  1. 0 44
      dulwich/_compat.py
  2. 1 4
      dulwich/diff_tree.py
  3. 1 4
      dulwich/pack.py
  4. 1 4
      dulwich/walk.py

+ 0 - 44
dulwich/_compat.py

@@ -40,50 +40,6 @@ except ImportError:
 import struct
 
 
-class defaultdict(dict):
-    """A python 2.4 equivalent of collections.defaultdict."""
-
-    def __init__(self, default_factory=None, *a, **kw):
-        if (default_factory is not None and
-            not hasattr(default_factory, '__call__')):
-            raise TypeError('first argument must be callable')
-        dict.__init__(self, *a, **kw)
-        self.default_factory = default_factory
-
-    def __getitem__(self, key):
-        try:
-            return dict.__getitem__(self, key)
-        except KeyError:
-            return self.__missing__(key)
-
-    def __missing__(self, key):
-        if self.default_factory is None:
-            raise KeyError(key)
-        self[key] = value = self.default_factory()
-        return value
-
-    def __reduce__(self):
-        if self.default_factory is None:
-            args = tuple()
-        else:
-            args = self.default_factory,
-        return type(self), args, None, None, self.items()
-
-    def copy(self):
-        return self.__copy__()
-
-    def __copy__(self):
-        return type(self)(self.default_factory, self)
-
-    def __deepcopy__(self, memo):
-        import copy
-        return type(self)(self.default_factory,
-                          copy.deepcopy(self.items()))
-    def __repr__(self):
-        return 'defaultdict(%s, %s)' % (self.default_factory,
-                                        dict.__repr__(self))
-
-
 def make_sha(source=''):
     """A python2.4 workaround for the sha/hashlib module fiasco."""
     try:

+ 1 - 4
dulwich/diff_tree.py

@@ -18,10 +18,7 @@
 
 """Utilities for diffing files and trees."""
 
-try:
-    from collections import defaultdict
-except ImportError:
-    from dulwich._compat import defaultdict
+from collections import defaultdict
 
 from cStringIO import StringIO
 import itertools

+ 1 - 4
dulwich/pack.py

@@ -30,10 +30,7 @@ match for the object name. You then use the pointer got from this as
 a pointer in to the corresponding packfile.
 """
 
-try:
-    from collections import defaultdict
-except ImportError:
-    from dulwich._compat import defaultdict
+from collections import defaultdict
 
 import binascii
 from cStringIO import (

+ 1 - 4
dulwich/walk.py

@@ -19,10 +19,7 @@
 """General implementation of walking commits and their contents."""
 
 
-try:
-    from collections import defaultdict
-except ImportError:
-    from _compat import defaultdict
+from collections import defaultdict
 
 import collections
 import heapq