Show More
@@ -34,7 +34,6 b' evalboolean = templateutil.evalboolean' | |||||
34 | evalinteger = templateutil.evalinteger |
|
34 | evalinteger = templateutil.evalinteger | |
35 | evalstring = templateutil.evalstring |
|
35 | evalstring = templateutil.evalstring | |
36 | evalstringliteral = templateutil.evalstringliteral |
|
36 | evalstringliteral = templateutil.evalstringliteral | |
37 | evalastype = templateutil.evalastype |
|
|||
38 |
|
37 | |||
39 | # dict of template built-in functions |
|
38 | # dict of template built-in functions | |
40 | funcs = {} |
|
39 | funcs = {} | |
@@ -261,9 +260,10 b' def ifcontains(context, mapping, args):' | |||||
261 | raise error.ParseError(_("ifcontains expects three or four arguments")) |
|
260 | raise error.ParseError(_("ifcontains expects three or four arguments")) | |
262 |
|
261 | |||
263 | haystack = evalfuncarg(context, mapping, args[1]) |
|
262 | haystack = evalfuncarg(context, mapping, args[1]) | |
|
263 | keytype = getattr(haystack, 'keytype', None) | |||
264 | try: |
|
264 | try: | |
265 |
needle = eval |
|
265 | needle = evalrawexp(context, mapping, args[0]) | |
266 | getattr(haystack, 'keytype', None) or bytes) |
|
266 | needle = templateutil.unwrapastype(needle, keytype or bytes) | |
267 | found = (needle in haystack) |
|
267 | found = (needle in haystack) | |
268 | except error.ParseError: |
|
268 | except error.ParseError: | |
269 | found = False |
|
269 | found = False |
@@ -77,7 +77,8 b' class mappable(object):' | |||||
77 | - "{manifest.rev}" |
|
77 | - "{manifest.rev}" | |
78 |
|
78 | |||
79 | Unlike a hybrid, this does not simulate the behavior of the underling |
|
79 | Unlike a hybrid, this does not simulate the behavior of the underling | |
80 |
value. Use unwrapvalue() or unwraphybrid() to obtain |
|
80 | value. Use unwrapvalue(), unwrapastype(), or unwraphybrid() to obtain | |
|
81 | the inner object. | |||
81 | """ |
|
82 | """ | |
82 |
|
83 | |||
83 | def __init__(self, gen, key, value, makemap): |
|
84 | def __init__(self, gen, key, value, makemap): | |
@@ -340,18 +341,18 b' def evalstringliteral(context, mapping, ' | |||||
340 | thing = func(context, mapping, data) |
|
341 | thing = func(context, mapping, data) | |
341 | return stringify(thing) |
|
342 | return stringify(thing) | |
342 |
|
343 | |||
343 |
_ |
|
344 | _unwrapfuncbytype = { | |
344 |
bytes: |
|
345 | bytes: stringify, | |
345 |
int: |
|
346 | int: unwrapinteger, | |
346 | } |
|
347 | } | |
347 |
|
348 | |||
348 |
def |
|
349 | def unwrapastype(thing, typ): | |
349 |
""" |
|
350 | """Move the inner value object out of the wrapper and coerce its type""" | |
350 | try: |
|
351 | try: | |
351 |
f = _ |
|
352 | f = _unwrapfuncbytype[typ] | |
352 | except KeyError: |
|
353 | except KeyError: | |
353 | raise error.ProgrammingError('invalid type specified: %r' % typ) |
|
354 | raise error.ProgrammingError('invalid type specified: %r' % typ) | |
354 |
return f( |
|
355 | return f(thing) | |
355 |
|
356 | |||
356 | def runinteger(context, mapping, data): |
|
357 | def runinteger(context, mapping, data): | |
357 | return int(data) |
|
358 | return int(data) |
General Comments 0
You need to be logged in to leave comments.
Login now