Skip to content

Commit 791c2b9

Browse files
committed
Supporting Python 2.6
1 parent d7a11f5 commit 791c2b9

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

source_py2/python_toolbox/logic_tools.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def get_equivalence_classes(iterable, key=None, container=set,
123123
key_function = comparison_tools.process_key_function_or_attribute_name(
124124
key
125125
)
126-
d = {key: key_function(key) for key in iterable}
126+
d = set((key, key_function(key)) for key in iterable)
127127
# #
128128
### Finished pre-processing input. ########################################
129129

source_py2/python_toolbox/zip_tools.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import cStringIO as string_io_module
99
import os
1010
import re
11+
import contextlib
1112
try:
1213
import pathlib
1314
except:
@@ -40,8 +41,8 @@ def zip_folder(source_folder, zip_path, ignored_patterns=()):
4041

4142
internal_pure_path = pathlib.PurePath(source_folder.name)
4243

43-
with zip_module.ZipFile(str(zip_path), 'w', zip_module.ZIP_DEFLATED) \
44-
as zip_file:
44+
with contextlib.closing(zip_module.ZipFile(str(zip_path), 'w',
45+
zip_module.ZIP_DEFLATED)) as zip_file:
4546

4647
for root, subfolders, files in os.walk(str(source_folder)):
4748
root = pathlib.Path(root)
@@ -70,8 +71,8 @@ def zip_in_memory(files):
7071
Files should be given as tuples of `(file_path, file_contents)`.
7172
'''
7273
zip_stream = string_io_module.StringIO()
73-
with zip_module.ZipFile(zip_stream, mode='w',
74-
compression=zip_module.ZIP_DEFLATED) as zip_file:
74+
with contextlib.closing(zip_module.ZipFile(zip_stream, mode='w',
75+
compression=zip_module.ZIP_DEFLATED)) as zip_file:
7576
assert isinstance(zip_file, zip_module.ZipFile)
7677
for file_name, file_data in files:
7778
zip_file.writestr(file_name, file_data)
@@ -85,8 +86,8 @@ def unzip_in_memory(zip_archive):
8586
Files are returned as tuples of `(file_path, file_contents)`.
8687
'''
8788
zip_stream = string_io_module.StringIO(zip_archive)
88-
with zip_module.ZipFile(zip_stream, mode='r',
89-
compression=zip_module.ZIP_DEFLATED) as zip_file:
89+
with contextlib.closing(zip_module.ZipFile(zip_stream, mode='r',
90+
compression=zip_module.ZIP_DEFLATED)) as zip_file:
9091
assert isinstance(zip_file, zip_module.ZipFile)
9192
return tuple((file_name, zip_file.read(file_name)) for file_name in
9293
zip_file.namelist())

source_py2/test_python_toolbox/test_dict_tools/test_devour_keys.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
def test():
1010
'''Test the basic workings of `devour_keys`.'''
1111
my_dict = {1: 2, 3: 4, 5: 6,}
12-
assert set(dict_tools.devour_keys(my_dict)) == {1, 3, 5}
12+
assert set(dict_tools.devour_keys(my_dict)) == set((1, 3, 5))
1313
assert not my_dict
1414

source_py2/test_python_toolbox/test_nifty_collections/test_frozen_ordered_dict.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,12 @@ def test():
2222
set('123')
2323
assert set(frozen_ordered_dict.values()) == set('abc')
2424
assert set(frozen_ordered_dict.items()) == \
25-
{('1', 'a'), ('2', 'b'), ('3', 'c'),}
25+
set((('1', 'a'), ('2', 'b'), ('3', 'c'),))
2626
assert frozen_ordered_dict['1'] == 'a'
2727
with cute_testing.RaiseAssertor(exception_type=LookupError):
2828
frozen_ordered_dict['missing value']
29-
assert {frozen_ordered_dict, frozen_ordered_dict} == {frozen_ordered_dict}
29+
assert set((frozen_ordered_dict, frozen_ordered_dict)) == \
30+
set((frozen_ordered_dict,))
3031
assert {frozen_ordered_dict: frozen_ordered_dict} == \
3132
{frozen_ordered_dict: frozen_ordered_dict}
3233
assert isinstance(hash(frozen_ordered_dict), int)

source_py2/test_python_toolbox/test_zip_tools/test_zip_folder.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@ def test():
3737
assert zip_file_path.is_file()
3838

3939
# Got two options here because of PyPy shenanigans:
40-
assert result == {
40+
assert result == set((
4141
('folder_to_zip/some_file.txt', b'hello there!'),
4242
('folder_to_zip/some_other_file.txt', b'hello there again!'),
43-
} or result == {
43+
)) or result == set((
4444
('folder_to_zip/some_file.txt', 'hello there!'),
4545
('folder_to_zip/some_other_file.txt', 'hello there again!'),
46-
}
46+
))
4747

4848
import gc; gc.collect() # Making PyPy happy.
4949

0 commit comments

Comments
 (0)