Ticket #539: efficient_slice.patch

File efficient_slice.patch, 877 bytes (added by Esaj, 19 years ago)

A more efficient implementation of slice supporting strides.

  • django/core/defaultfilters.py

     
    245245    for an introduction.
    246246    """
    247247    try:
    248         start, finish = arg.split(':')
    249     except ValueError: # unpack list of wrong size
    250         return value # fail silently but nicely
    251     try:
    252         if start and finish:
    253             return value[int(start):int(finish)]
    254         if start:
    255             return value[int(start):]
    256         if finish:
    257             return value[:int(finish)]
     248        return value[slice(*[x and int(x) or None for x in arg.split(':')])]
     249    except ValueError:
     250        pass
    258251    except TypeError:
    259252        pass
    260     return value
     253    return value # fail silently but nicely
    261254
    262255def unordered_list(value, _):
    263256    """
Back to Top