diff --git a/linkcheck/strformat.py b/linkcheck/strformat.py index 28b78e74..efdc34ec 100644 --- a/linkcheck/strformat.py +++ b/linkcheck/strformat.py @@ -1,5 +1,5 @@ # -*- coding: iso-8859-1 -*- -# Copyright (C) 2000-2012 Bastian Kleineidam +# Copyright (C) 2000-2013 Bastian Kleineidam # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -179,24 +179,24 @@ def remove_markup (s): return s -def strsize (b): +def strsize (b, grouping=True): """Return human representation of bytes b. A negative number of bytes raises a value error.""" if b < 0: raise ValueError("Invalid negative byte number") if b < 1024: - return u"%sB" % locale.format("%d", b, True) + return u"%sB" % locale.format("%d", b, grouping) if b < 1024 * 10: - return u"%sKB" % locale.format("%d", (b // 1024), True) + return u"%sKB" % locale.format("%d", (b // 1024), grouping) if b < 1024 * 1024: - return u"%sKB" % locale.format("%.2f", (float(b) / 1024), True) + return u"%sKB" % locale.format("%.2f", (float(b) / 1024), grouping) if b < 1024 * 1024 * 10: - return u"%sMB" % locale.format("%.2f", (float(b) / (1024*1024)), True) + return u"%sMB" % locale.format("%.2f", (float(b) / (1024*1024)), grouping) if b < 1024 * 1024 * 1024: - return u"%sMB" % locale.format("%.1f", (float(b) / (1024*1024)), True) + return u"%sMB" % locale.format("%.1f", (float(b) / (1024*1024)), grouping) if b < 1024 * 1024 * 1024 * 10: - return u"%sGB" % locale.format("%.2f", (float(b) / (1024*1024*1024)), True) - return u"%sGB" % locale.format("%.1f", (float(b) / (1024*1024*1024)), True) + return u"%sGB" % locale.format("%.2f", (float(b) / (1024*1024*1024)), grouping) + return u"%sGB" % locale.format("%.1f", (float(b) / (1024*1024*1024)), grouping) def strtime (t): diff --git a/tests/test_strformat.py b/tests/test_strformat.py index 049e8542..460ec32b 100644 --- a/tests/test_strformat.py +++ b/tests/test_strformat.py @@ -1,5 +1,5 @@ # -*- coding: iso-8859-1 -*- -# Copyright (C) 2004-2012 Bastian Kleineidam +# Copyright (C) 2004-2013 Bastian Kleineidam # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -85,7 +85,7 @@ class TestStrFormat (unittest.TestCase): self.assertEqual(linkcheck.strformat.strsize(0), "0B") self.assertEqual(linkcheck.strformat.strsize(1), "1B") self.assertEqual(linkcheck.strformat.strsize(2), "2B") - self.assertEqual(linkcheck.strformat.strsize(1023), "1023B") + self.assertEqual(linkcheck.strformat.strsize(1023, grouping=False), "1023B") self.assertEqual(linkcheck.strformat.strsize(1024), "1KB") self.assertEqual(linkcheck.strformat.strsize(1024*25), "25.00KB") self.assertEqual(linkcheck.strformat.strsize(1024*1024), "1.00MB")