Skip to content

Commit 654956f

Browse files
committed
-
1 parent 4205295 commit 654956f

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

python_toolbox/monkeypatch_envelopes.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Copyright 2009-2013 Ram Rachum.
22
# This program is distributed under the MIT license.
33

4+
'''Module for monkeypatching our own copy of `envelopes`.'''
45

56
### Monkeypatching envelopes: #################################################
67
# #

python_toolbox/monkeypatching_tools.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
@decorator_tools.helpful_decorator_builder
1515
def monkeypatch_method(monkeypatchee, name=None):
1616
'''
17-
blocktododoc
18-
Monkeypatch a method into a class.
17+
Monkeypatch a method into a class (or an object).
1918
2019
Example:
2120
@@ -33,7 +32,8 @@ def my_method(a):
3332
You may use the `name` argument to specify a method name different from the
3433
function's name.
3534
36-
You can also use this to monkeypatch a `CachedProperty` into a class.
35+
You can also use this to monkeypatch a `CachedProperty`, a `classmethod`
36+
and a `staticmethod` into a class.
3737
'''
3838

3939
monkeypatchee_is_a_class = misc_tools.is_type(monkeypatchee)
@@ -49,8 +49,6 @@ def decorator(function):
4949
new_method = types.MethodType(function, None, monkeypatchee) if \
5050
monkeypatchee_is_a_class else types.MethodType(function,
5151
monkeypatchee, class_of_monkeypatchee)
52-
# todo: Last line was: `new_method = types.MethodType(function,
53-
# class_)`, is subtly wrong, make tests to prove
5452
setattr(monkeypatchee, name_, new_method)
5553
return function
5654
else:

python_toolbox/pickle_tools.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ def persistent_load(self, id_string):
188188

189189

190190
def compickle(thing):
191+
'''Pickle `thing` and compress it using `zlib`.'''
191192
return zlib.compress(pickle_module.dumps(thing, protocol=2))
192193

193194
def decompickle(thing):
195+
'''Unpickle `thing` after decompressing it using `zlib`.'''
194196
return pickle_module.loads(zlib.decompress(thing))

python_toolbox/sequence_tools.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@
1616

1717
def are_equal_regardless_of_order(seq1, seq2):
1818
'''
19-
blocktododoc
20-
Return whether the two sequences are equal in the elements they contain,
21-
regardless of the order of the elements.
19+
Do `seq1` and `seq2` contain the same elements, same number of times?
20+
21+
Disregards order of elements.
2222
2323
Currently will fail for items that have problems with comparing.
2424
'''
@@ -264,9 +264,9 @@ def to_tuple(single_or_sequence, item_type=None, item_test=None):
264264

265265
def pop_until(sequence, condition=bool):
266266
'''
267-
blocktododoc
267+
Look for item in `sequence` that passes `condition`, popping away others.
268268
269-
Propagates whatever error is raised on popping the sequence.
269+
When sequence is empty, propagates the `IndexError`.
270270
'''
271271
while True:
272272
item = sequence.pop()
@@ -275,6 +275,11 @@ def pop_until(sequence, condition=bool):
275275

276276

277277
def get_recurrences(sequence):
278+
'''
279+
Get a `dict` of all items that repeat at least twice.
280+
281+
The values of the dict are the numbers of repititions of each item.
282+
'''
278283
# Use when ditching Python 2.6:
279284
#return {item: n_recurrences for item, n_recurrences in
280285
#Counter(sequence).most_common() if n_recurrences >= 2}

python_toolbox/zip_tools.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ def zip_folder(folder, zip_path, ignored_patterns=()):
5858

5959

6060
def zip_in_memory(files):
61+
'''
62+
Zip files in memory and return zip archive as a string.
63+
64+
Files should be given as tuples of `(file_path, file_contents)`.
65+
'''
6166
zip_stream = string_io_module.StringIO()
6267
with contextlib.closing(zip_module.ZipFile(zip_stream, mode='w',
6368
compression=zip_module.ZIP_DEFLATED)) as zip_file:
@@ -68,6 +73,11 @@ def zip_in_memory(files):
6873
return zip_stream.getvalue()
6974

7075
def unzip_in_memory(zip_archive):
76+
'''
77+
Unzip a zip archive given as string, returning files
78+
79+
Files are returned as tuples of `(file_path, file_contents)`.
80+
'''
7181
zip_stream = string_io_module.StringIO(zip_archive)
7282
with contextlib.closing(zip_module.ZipFile(zip_stream, mode='r',
7383
compression=zip_module.ZIP_DEFLATED)) as zip_file:

0 commit comments

Comments
 (0)