Skip to content

Commit b46b9e6

Browse files
committed
-
1 parent 6ddd02c commit b46b9e6

File tree

9 files changed

+17
-26
lines changed

9 files changed

+17
-26
lines changed

source_py2/python_toolbox/sequence_tools.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import types
88
import itertools
99

10-
from python_toolbox.nifty_collections import Counter
1110
from python_toolbox import math_tools
1211

1312

@@ -22,7 +21,7 @@ def are_equal_regardless_of_order(seq1, seq2):
2221
2322
Currently will fail for items that have problems with comparing.
2423
'''
25-
return Counter(seq1) == Counter(seq2)
24+
return collections.Counter(seq1) == collections.Counter(seq2)
2625

2726

2827
def flatten(iterable):
@@ -281,7 +280,7 @@ def get_recurrences(sequence):
281280
The values of the dict are the numbers of repititions of each item.
282281
'''
283282
return {item: n_recurrences for item, n_recurrences in
284-
Counter(sequence).most_common() if n_recurrences >= 2}
283+
collections.Counter(sequence).most_common() if n_recurrences >= 2}
285284

286285
### Not using now, might want in future:
287286

source_py2/python_toolbox/sys_tools.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
'''Defines various `sys`-related tools.'''
55

66

7-
87
import sys
9-
import cStringIO
8+
import cStringIO as string_io_module
109

1110
from python_toolbox.context_management import (ContextManager,
1211
BlankContextManager)
@@ -30,7 +29,7 @@ class OutputCapturer(ContextManager):
3029
captured.
3130
'''
3231
def __init__(self, stdout=True, stderr=True):
33-
self.string_io = cStringIO.StringIO()
32+
self.string_io = string_io_module.StringIO()
3433

3534
if stdout:
3635
self._stdout_temp_setter = \
@@ -46,9 +45,8 @@ def __init__(self, stdout=True, stderr=True):
4645

4746
def manage_context(self):
4847
'''Manage the `OutputCapturer`'s context.'''
49-
with self._stdout_temp_setter:
50-
with self._stderr_temp_setter:
51-
yield self
48+
with self._stdout_temp_setter, self._stderr_temp_setter:
49+
yield self
5250

5351
output = property(lambda self: self.string_io.getvalue(),
5452
doc='''The string of output that was captured.''')

source_py2/python_toolbox/version_info.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def _asdict(self):
5757
'''
5858
Return a new `OrderedDict` which maps field names to their values.
5959
'''
60-
return OrderedDict(zip(self._fields, self))
60+
return OrderedDict(zip(self._fields, self))
6161

6262

6363
def _replace(self, **kwargs):

source_py2/python_toolbox/zip_tools.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,8 @@ def zip_folder(folder, zip_path, ignored_patterns=()):
3434
zip_name = os.path.splitext(os.path.split(zip_path)[1])[0]
3535
source_folder_name = os.path.split(source_folder)[1]
3636

37-
with contextlib.closing(
38-
zip_module.ZipFile(zip_path, 'w', zip_module.ZIP_DEFLATED)
39-
) as zip_file:
37+
with zip_module.ZipFile(zip_path, 'w', zip_module.ZIP_DEFLATED) \
38+
as zip_file:
4039

4140
for root, subfolders, files in os.walk(source_folder):
4241

@@ -63,8 +62,8 @@ def zip_in_memory(files):
6362
Files should be given as tuples of `(file_path, file_contents)`.
6463
'''
6564
zip_stream = string_io_module.StringIO()
66-
with contextlib.closing(zip_module.ZipFile(zip_stream, mode='w',
67-
compression=zip_module.ZIP_DEFLATED)) as zip_file:
65+
with zip_module.ZipFile(zip_stream, mode='w',
66+
compression=zip_module.ZIP_DEFLATED) as zip_file:
6867
assert isinstance(zip_file, zip_module.ZipFile)
6968
for file_name, file_data in files:
7069
zip_file.writestr(file_name, file_data)
@@ -78,8 +77,8 @@ def unzip_in_memory(zip_archive):
7877
Files are returned as tuples of `(file_path, file_contents)`.
7978
'''
8079
zip_stream = string_io_module.StringIO(zip_archive)
81-
with contextlib.closing(zip_module.ZipFile(zip_stream, mode='r',
82-
compression=zip_module.ZIP_DEFLATED)) as zip_file:
80+
with zip_module.ZipFile(zip_stream, mode='r',
81+
compression=zip_module.ZIP_DEFLATED) as zip_file:
8382
assert isinstance(zip_file, zip_module.ZipFile)
8483
return tuple((file_name, zip_file.read(file_name)) for file_name in
8584
zip_file.namelist())

source_py3/python_toolbox/queue_tools.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
'''Defines various functions for working with queues.'''
55

66

7-
87
import queue as queue_module
98
import sys
109

source_py3/python_toolbox/sys_tools.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
'''Defines various `sys`-related tools.'''
55

66

7-
8-
97
import sys
108
import io
119

source_py3/python_toolbox/temp_file_tools.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
'''Defines various tools related to temporary files.'''
55

66

7-
87
import tempfile
98
import shutil
109
import os

source_py3/python_toolbox/version_info.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,18 @@ def _asdict(self):
5757
'''
5858
Return a new `OrderedDict` which maps field names to their values.
5959
'''
60-
return OrderedDict(list(zip(self._fields, self)))
60+
return OrderedDict(zip(self._fields, self))
6161

6262

6363
def _replace(self, **kwargs):
6464
'''
6565
Make a `VersionInfo` object replacing specified fields with new values.
6666
'''
6767
result = \
68-
self._make(list(map(kwargs.pop, ('major', 'minor', 'micro', 'modifier'),
69-
self)))
68+
self._make(map(kwargs.pop, ('major', 'minor', 'micro', 'modifier'),
69+
self))
7070
if kwargs:
71-
raise ValueError('Got unexpected field names: %r' % list(kwargs.keys()))
71+
raise ValueError('Got unexpected field names: %r' % kwargs.keys())
7272
return result
7373

7474

source_py3/python_toolbox/zip_tools.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
'''Various zip-related tools.'''
55

66

7-
87
import contextlib
98
import zipfile as zip_module
109
import os.path

0 commit comments

Comments
 (0)