Show More
@@ -333,8 +333,9 b' def join(context, mapping, args):' | |||||
333 | joiner = evalstring(context, mapping, args[1]) |
|
333 | joiner = evalstring(context, mapping, args[1]) | |
334 | if isinstance(joinset, templateutil.wrapped): |
|
334 | if isinstance(joinset, templateutil.wrapped): | |
335 | return joinset.join(context, mapping, joiner) |
|
335 | return joinset.join(context, mapping, joiner) | |
336 | # TODO: perhaps a generator should be stringify()-ed here, but we can't |
|
336 | # TODO: rethink about join() of a byte string, which had no defined | |
337 | # because hgweb abuses it as a keyword that returns a list of dicts. |
|
337 | # behavior since a string may be either a bytes or a generator. | |
|
338 | # TODO: fix type error on join() of non-iterable | |||
338 | joinset = templateutil.unwrapvalue(context, mapping, joinset) |
|
339 | joinset = templateutil.unwrapvalue(context, mapping, joinset) | |
339 | return templateutil.joinitems(pycompat.maybebytestr(joinset), joiner) |
|
340 | return templateutil.joinitems(pycompat.maybebytestr(joinset), joiner) | |
340 |
|
341 |
@@ -26,9 +26,6 b' generator' | |||||
26 | values of any printable types, and will be folded by ``stringify()`` |
|
26 | values of any printable types, and will be folded by ``stringify()`` | |
27 | or ``flatten()``. |
|
27 | or ``flatten()``. | |
28 |
|
28 | |||
29 | BUG: hgweb overloads this type for mappings (i.e. some hgweb keywords |
|
|||
30 | returns a generator of dicts.) |
|
|||
31 |
|
||||
32 | None |
|
29 | None | |
33 | sometimes represents an empty value, which can be stringified to ''. |
|
30 | sometimes represents an empty value, which can be stringified to ''. | |
34 |
|
31 |
@@ -285,12 +285,6 b' def unwraphybrid(context, mapping, thing' | |||||
285 | return thing |
|
285 | return thing | |
286 | return thing.show(context, mapping) |
|
286 | return thing.show(context, mapping) | |
287 |
|
287 | |||
288 | def unwrapvalue(context, mapping, thing): |
|
|||
289 | """Move the inner value object out of the wrapper""" |
|
|||
290 | if not isinstance(thing, wrapped): |
|
|||
291 | return thing |
|
|||
292 | return thing.tovalue(context, mapping) |
|
|||
293 |
|
||||
294 | def wraphybridvalue(container, key, value): |
|
288 | def wraphybridvalue(container, key, value): | |
295 | """Wrap an element of hybrid container to be mappable |
|
289 | """Wrap an element of hybrid container to be mappable | |
296 |
|
290 | |||
@@ -455,12 +449,10 b' def evalrawexp(context, mapping, arg):' | |||||
455 |
|
449 | |||
456 | def evalfuncarg(context, mapping, arg): |
|
450 | def evalfuncarg(context, mapping, arg): | |
457 | """Evaluate given argument as value type""" |
|
451 | """Evaluate given argument as value type""" | |
458 |
return |
|
452 | return unwrapvalue(context, mapping, evalrawexp(context, mapping, arg)) | |
459 |
|
453 | |||
460 | # TODO: unify this with unwrapvalue() once the bug of templatefunc.join() |
|
454 | def unwrapvalue(context, mapping, thing): | |
461 | # is fixed. we can't do that right now because join() has to take a generator |
|
455 | """Move the inner value object out of the wrapper""" | |
462 | # of byte strings as it is, not a lazy byte string. |
|
|||
463 | def _unwrapvalue(context, mapping, thing): |
|
|||
464 | if isinstance(thing, wrapped): |
|
456 | if isinstance(thing, wrapped): | |
465 | return thing.tovalue(context, mapping) |
|
457 | return thing.tovalue(context, mapping) | |
466 | # evalrawexp() may return string, generator of strings or arbitrary object |
|
458 | # evalrawexp() may return string, generator of strings or arbitrary object | |
@@ -492,7 +484,7 b' def evaldate(context, mapping, arg, err=' | |||||
492 | return unwrapdate(context, mapping, thing, err) |
|
484 | return unwrapdate(context, mapping, thing, err) | |
493 |
|
485 | |||
494 | def unwrapdate(context, mapping, thing, err=None): |
|
486 | def unwrapdate(context, mapping, thing, err=None): | |
495 |
thing = |
|
487 | thing = unwrapvalue(context, mapping, thing) | |
496 | try: |
|
488 | try: | |
497 | return dateutil.parsedate(thing) |
|
489 | return dateutil.parsedate(thing) | |
498 | except AttributeError: |
|
490 | except AttributeError: | |
@@ -507,7 +499,7 b' def evalinteger(context, mapping, arg, e' | |||||
507 | return unwrapinteger(context, mapping, thing, err) |
|
499 | return unwrapinteger(context, mapping, thing, err) | |
508 |
|
500 | |||
509 | def unwrapinteger(context, mapping, thing, err=None): |
|
501 | def unwrapinteger(context, mapping, thing, err=None): | |
510 |
thing = |
|
502 | thing = unwrapvalue(context, mapping, thing) | |
511 | try: |
|
503 | try: | |
512 | return int(thing) |
|
504 | return int(thing) | |
513 | except (TypeError, ValueError): |
|
505 | except (TypeError, ValueError): | |
@@ -527,7 +519,7 b' def evalstringliteral(context, mapping, ' | |||||
527 | return stringify(context, mapping, thing) |
|
519 | return stringify(context, mapping, thing) | |
528 |
|
520 | |||
529 | _unwrapfuncbytype = { |
|
521 | _unwrapfuncbytype = { | |
530 |
None: |
|
522 | None: unwrapvalue, | |
531 | bytes: stringify, |
|
523 | bytes: stringify, | |
532 | date: unwrapdate, |
|
524 | date: unwrapdate, | |
533 | int: unwrapinteger, |
|
525 | int: unwrapinteger, |
General Comments 0
You need to be logged in to leave comments.
Login now