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