Skip to content

Commit 8b52453

Browse files
committed
Use OrderedDict instead of plain dict
1 parent ccbedce commit 8b52453

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

bencoder.pyx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ __version__ = '1.0.0'
1717
import sys
1818
IS_PY2 = sys.version[0] == '2'
1919

20+
try:
21+
from collections import OrderedDict
22+
except ImportError:
23+
from ordereddict import OrderedDict
24+
2025
if IS_PY2:
2126
END_CHAR = 'e'
2227
else:
@@ -57,7 +62,7 @@ def decode_list(bytes x, int f):
5762

5863

5964
def decode_dict(bytes x, int f):
60-
r, f = {}, f + 1
65+
r, f = OrderedDict(), f + 1
6166
while x[f] != END_CHAR:
6267
k, f = decode_string(x, f)
6368
r[k], f = decode_func[x[f]](x, f)

setup.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
import sys
1+
import platform
22

33
from setuptools import setup
44
from setuptools.extension import Extension
55

6+
version = platform.python_version_tuple()
7+
install_requires = []
8+
if version < ('2', '7'):
9+
install_requires.append('ordereddict>=1.1')
10+
611
setup(
712
name='bencoder.pyx',
813
version='1.0.0',
@@ -35,6 +40,7 @@
3540
'Topic :: Software Development :: Libraries :: Python Modules',
3641
],
3742
ext_modules=[Extension('bencoder', ['bencoder.c'])],
43+
install_requires=install_requires,
3844
tests_require=['nose'],
3945
test_suite='nose.collector',
4046
)

0 commit comments

Comments
 (0)