Show More
@@ -324,7 +324,7 b' class templatefilter(_templateregistrarb' | |||||
324 |
|
324 | |||
325 | templatefilter = registrar.templatefilter() |
|
325 | templatefilter = registrar.templatefilter() | |
326 |
|
326 | |||
327 | @templatefilter('myfilter') |
|
327 | @templatefilter('myfilter', intype=bytes) | |
328 | def myfilterfunc(text): |
|
328 | def myfilterfunc(text): | |
329 | '''Explanation of this template filter .... |
|
329 | '''Explanation of this template filter .... | |
330 | ''' |
|
330 | ''' | |
@@ -332,6 +332,9 b' class templatefilter(_templateregistrarb' | |||||
332 |
|
332 | |||
333 | The first string argument is used also in online help. |
|
333 | The first string argument is used also in online help. | |
334 |
|
334 | |||
|
335 | Optional argument 'intype' defines the type of the input argument, | |||
|
336 | which should be (bytes, int, or None for any.) | |||
|
337 | ||||
335 | 'templatefilter' instance in example above can be used to |
|
338 | 'templatefilter' instance in example above can be used to | |
336 | decorate multiple functions. |
|
339 | decorate multiple functions. | |
337 |
|
340 | |||
@@ -342,6 +345,9 b' class templatefilter(_templateregistrarb' | |||||
342 | Otherwise, explicit 'templatefilters.loadkeyword()' is needed. |
|
345 | Otherwise, explicit 'templatefilters.loadkeyword()' is needed. | |
343 | """ |
|
346 | """ | |
344 |
|
347 | |||
|
348 | def _extrasetup(self, name, func, intype=None): | |||
|
349 | func._intype = intype | |||
|
350 | ||||
345 | class templatefunc(_templateregistrarbase): |
|
351 | class templatefunc(_templateregistrarbase): | |
346 | """Decorator to register template function |
|
352 | """Decorator to register template function | |
347 |
|
353 |
@@ -354,12 +354,12 b' def splitlines(text):' | |||||
354 | def stringescape(text): |
|
354 | def stringescape(text): | |
355 | return stringutil.escapestr(text) |
|
355 | return stringutil.escapestr(text) | |
356 |
|
356 | |||
357 | @templatefilter('stringify') |
|
357 | @templatefilter('stringify', intype=bytes) | |
358 | def stringify(thing): |
|
358 | def stringify(thing): | |
359 | """Any type. Turns the value into text by converting values into |
|
359 | """Any type. Turns the value into text by converting values into | |
360 | text and concatenating them. |
|
360 | text and concatenating them. | |
361 | """ |
|
361 | """ | |
362 | return templateutil.stringify(thing) |
|
362 | return thing # coerced by the intype | |
363 |
|
363 | |||
364 | @templatefilter('stripdir') |
|
364 | @templatefilter('stripdir') | |
365 | def stripdir(text): |
|
365 | def stripdir(text): |
@@ -342,6 +342,7 b' def evalstringliteral(context, mapping, ' | |||||
342 | return stringify(thing) |
|
342 | return stringify(thing) | |
343 |
|
343 | |||
344 | _unwrapfuncbytype = { |
|
344 | _unwrapfuncbytype = { | |
|
345 | None: _unwrapvalue, | |||
345 | bytes: stringify, |
|
346 | bytes: stringify, | |
346 | int: unwrapinteger, |
|
347 | int: unwrapinteger, | |
347 | } |
|
348 | } | |
@@ -400,8 +401,9 b' def runtemplate(context, mapping, templa' | |||||
400 |
|
401 | |||
401 | def runfilter(context, mapping, data): |
|
402 | def runfilter(context, mapping, data): | |
402 | arg, filt = data |
|
403 | arg, filt = data | |
403 |
thing = eval |
|
404 | thing = evalrawexp(context, mapping, arg) | |
404 | try: |
|
405 | try: | |
|
406 | thing = unwrapastype(thing, getattr(filt, '_intype', None)) | |||
405 | return filt(thing) |
|
407 | return filt(thing) | |
406 | except (ValueError, AttributeError, TypeError): |
|
408 | except (ValueError, AttributeError, TypeError): | |
407 | sym = findsymbolicname(arg) |
|
409 | sym = findsymbolicname(arg) |
General Comments 0
You need to be logged in to leave comments.
Login now