Skip to content

Commit 23e050a

Browse files
committed
Fix imports for OrderedDict on Py2.6
1 parent 1ce5c98 commit 23e050a

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

future/backports/misc.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
"""
22
Miscellaneous function (re)definitions from the Py3.3 standard library for
33
Python 2.6/2.7.
4+
5+
math.ceil
6+
7+
collections.OrderedDict (for Python 2.6)
8+
collections.Counter (for Python 2.6)
49
"""
510

611
from math import ceil as oldceil
712

13+
from future.utils import iteritems, PY26
14+
815

916
def ceil(x):
1017
"""
@@ -14,7 +21,22 @@ def ceil(x):
1421
return int(oldceil(x))
1522

1623

17-
# Implementations of collections.OrderedDict and Counter for Python 2.6:
24+
# OrderedDict Shim from Raymond Hettinger, python core dev
25+
# http://code.activestate.com/recipes/576693-ordered-dictionary-for-py24/
26+
# here to support version 2.6.
27+
28+
if PY26:
29+
# don't need this except in 2.6
30+
try:
31+
from thread import get_ident
32+
except ImportError:
33+
from dummy_thread import get_ident
34+
35+
try:
36+
from _abcoll import KeysView, ValuesView, ItemsView
37+
except ImportError:
38+
pass
39+
1840

1941
class _OrderedDict(dict):
2042

@@ -203,7 +225,7 @@ def setdefault(self, key, default=None):
203225

204226
def __repr__(self, _repr_running={}):
205227
'od.__repr__() <==> repr(od)'
206-
call_key = id(self), _get_ident()
228+
call_key = id(self), get_ident()
207229
if call_key in _repr_running:
208230
return '...'
209231
_repr_running[call_key] = 1

0 commit comments

Comments
 (0)