Ticket #11944: filesizeformat.diff

File filesizeformat.diff, 921 bytes (added by Ryan Kelly, 15 years ago)
  • django/template/defaultfilters.py

    diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
    index 47e116c..0fabe84 100644
    a b def filesizeformat(bytes):  
    791791    """
    792792    try:
    793793        bytes = float(bytes)
    794     except TypeError:
     794    except (TypeError,ValueError,UnicodeDecodeError):
    795795        return u"0 bytes"
    796796
    797797    if bytes < 1024:
  • tests/regressiontests/defaultfilters/tests.py

    diff --git a/tests/regressiontests/defaultfilters/tests.py b/tests/regressiontests/defaultfilters/tests.py
    index 4343586..0fe4673 100644
    a b u'1024.0 MB'  
    476476>>> filesizeformat(1024*1024*1024)
    477477u'1.0 GB'
    478478
     479>>> filesizeformat(complex(1,-1))
     480u'0 bytes'
     481
     482>>> filesizeformat("")
     483u'0 bytes'
     484
     485>>> filesizeformat(u"\N{GREEK SMALL LETTER ALPHA}")
     486u'0 bytes'
     487
    479488>>> pluralize(1)
    480489u''
    481490
Back to Top