Ticket #539: defaultfilters.py.diff
File defaultfilters.py.diff, 1.3 KB (added by , 19 years ago) |
---|
-
defaultfilters.py
245 245 for an introduction. 246 246 """ 247 247 try: 248 start, finish = arg.split(':') 248 pieces = arg.split(':') 249 if len(pieces) == 2: 250 (start, finish), stride = pieces, None 251 else: 252 start, finish, stride = pieces 249 253 except ValueError: # unpack list of wrong size 250 254 return value # fail silently but nicely 251 255 try: 252 256 if start and finish: 253 return value[int(start):int(finish)] 257 if stride: 258 return value[int(start):int(finish):int(stride)] 259 else: 260 return value[int(start):int(finish)] 254 261 if start: 255 return value[int(start):] 262 if stride: 263 return value[int(start)::int(stride)] 264 else: 265 return value[int(start):] 256 266 if finish: 257 return value[:int(finish)] 267 if stride: 268 return value[:int(finish)] 269 else: 270 return value[:int(finish):int(stride)] 271 if stride: 272 return value[::int(stride)] 258 273 except TypeError: 259 274 pass 260 275 return value