diff options
author | Anton Khirnov <anton@khirnov.net> | 2021-01-16 10:32:48 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2021-01-16 10:32:48 +0100 |
commit | b1d0512f0e20b709858151818ddc508fd00dfe4a (patch) | |
tree | 92b8d774376184c0d6f1e91484a63c85be563153 | |
parent | f0b24807e42ad95395a3885775cb1ee3322571a6 (diff) |
helper: move humanize_size to the only place where it is used
-rw-r--r-- | alot/db/attachment.py | 24 | ||||
-rw-r--r-- | alot/helper.py | 20 |
2 files changed, 22 insertions, 22 deletions
diff --git a/alot/db/attachment.py b/alot/db/attachment.py index fb6523e1..0ebe6fc9 100644 --- a/alot/db/attachment.py +++ b/alot/db/attachment.py @@ -7,10 +7,30 @@ import tempfile import email.charset as charset from copy import deepcopy -from ..helper import humanize_size, guess_mimetype +from ..helper import guess_mimetype charset.add_charset('utf-8', charset.QP, charset.QP, 'utf-8') +def _humanize_size(size): + """Create a nice human readable representation of the given number + (understood as bytes) using the "KiB" and "MiB" suffixes to indicate + kibibytes and mebibytes. A kibibyte is defined as 1024 bytes (as opposed to + a kilobyte which is 1000 bytes) and a mibibyte is 1024**2 bytes (as opposed + to a megabyte which is 1000**2 bytes). + + :param size: the number to convert + :type size: int + :returns: the human readable representation of size + :rtype: str + """ + for factor, format_string in ((1, '%i'), + (1024, '%iKiB'), + (1024 * 1024, '%.1fMiB')): + if size / factor < 1024: + return format_string % (size / factor) + return format_string % (size / factor) + + class Attachment: """represents a mail attachment""" @@ -25,7 +45,7 @@ class Attachment: def __str__(self): return '%s:%s (%s)' % (self.get_content_type(), self.get_filename(), - humanize_size(self.get_size())) + _humanize_size(self.get_size())) def get_filename(self): """ diff --git a/alot/helper.py b/alot/helper.py index b7c4f5a1..5800841d 100644 --- a/alot/helper.py +++ b/alot/helper.py @@ -406,26 +406,6 @@ def shell_quote(text): return "'%s'" % text.replace("'", """'"'"'""") -def humanize_size(size): - """Create a nice human readable representation of the given number - (understood as bytes) using the "KiB" and "MiB" suffixes to indicate - kibibytes and mebibytes. A kibibyte is defined as 1024 bytes (as opposed to - a kilobyte which is 1000 bytes) and a mibibyte is 1024**2 bytes (as opposed - to a megabyte which is 1000**2 bytes). - - :param size: the number to convert - :type size: int - :returns: the human readable representation of size - :rtype: str - """ - for factor, format_string in ((1, '%i'), - (1024, '%iKiB'), - (1024 * 1024, '%.1fMiB')): - if size / factor < 1024: - return format_string % (size / factor) - return format_string % (size / factor) - - def parse_mailcap_nametemplate(tmplate='%s'): """this returns a prefix and suffix to be used in the tempfile module for a given mailcap nametemplate string""" |