fixed another python2.4 bug
Before adoption: this commit came in with the history the project adopted, so no landing records it.
--HG-- branch : trunk
authored by Armin Ronacher · committed by Armin Ronacher · parent 371cb14 · Browse files · 2 files·+30 added−29 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+30 added−29 removed
- other:+30 added−29 removed
Provenance
- Commit
316157d- Tree
8d09a83- Author
Armin Ronacher <armin.ronacher@active-4.com>- Committer
Armin Ronacher <armin.ronacher@active-4.com>- Parent
371cb14
2 files changed+30 added−29 removed
modified:docs/templates.rst+25 added-25 removed
436 unmodified lines437 438 The simplest form of expressions are literals. Literals are representations439 for Python objects such as strings and numbers. The following literals exist:440 441-``"Hello World"``441+"Hello World":442 Everything between two double or single quotes is a string. They are443 useful whenever you need a string in the template (for example as444 arguments to function calls, filters or just to extend or include a445 template).446 447-``42`` / ``42.23``447+42 / 42.23:448 Integers and floating point numbers are created by just writing the449 number down. If a dot is present the number is a float, otherwise an450 integer. Keep in mind that for Python ``42`` and ``42.0`` is something451 different.452 453-``['list', 'of', 'objects']``453+['list', 'of', 'objects']:454 Everything between two brackets is a list. Lists are useful to store455 sequential data in or to iterate over them. For example you can easily456 create a list of links using lists and tuples with a for loop.457 5 unmodified lines463 <li><a href="{{ href }}">{{ caption }}</a></li>464 {% endfor %}465 </ul>466 467-``('tuple', 'of', 'values')``467+('tuple', 'of', 'values'):468 Tuples are like lists, just that you can't modify them. If the tuple469 only has one item you have to end it with a comma. Tuples are usually470 used to represent items of two or more elements. See the example above471 for more details.472 473-``{'dict': 'of', 'keys': 'and', 'value': 'pairs'}``473+{'dict': 'of', 'keys': 'and', 'value': 'pairs'}:474 A dict in Python is a structure that combines keys and values. Keys must475 be unique and always have exactly one value. Dicts are rarely used in476 templates, they are useful in some rare cases such as the :func:`xmlattr`477 filter.478 479-``true`` and ``false``479+true / false:480 true is always true and false is always false. Keep in mind that those481 literals are lowercase!482 483 Math1 unmodified line485 486 Jinja allows you to calculate with values. This is rarely useful in templates487 but exists for completeness sake. The following operators are supported:488 489-``+``489+\+490 Adds two objects with each other. Usually numbers but if both objects are491 strings or lists you can concatenate them this way. This however is not492 the preferred way to concatenate strings! For string concatenation have493 a look at the ``~`` operator. ``{{ 1 + 1 }}`` is ``2``.494 495-``-``495+\-496 Substract two numbers from each other. ``{{ 3 - 2 }}`` is ``1``.497 498-``/``498+/499 Divide two numbers. The return value will be a floating point number.500 ``{{ 1 / 2 }}`` is ``{{ 0.5 }}``.501 502-``//``502+//503 Divide two numbers and return the truncated integer result.504 ``{{ 20 / 7 }}`` is ``2``.505 506-``%``506+%507 Calculate the remainder of an integer division between the left and right508 operand. ``{{ 11 % 7 }}`` is ``4``.509 510-``*``510+\*511 Multiply the left operand with the right one. ``{{ 2 * 2 }}`` would512 return ``4``. This can also be used to repeat string multiple times.513 ``{{ '=' * 80 }}`` would print a bar of 80 equal signs.514 515-``**``515+\**516 Raise the left operand to the power of the right operand. ``{{ 2**3 }}``517 would return ``8``.518 519 Logic1 unmodified line521 522 For `if` statements / `for` filtering or `if` expressions it can be useful to523 combine group multiple expressions:524 525-``and``525+and526 Return true if the left and the right operand is true.527 528-``or``528+or529 Return true if the left or the right operand is true.530 531-``not``531+not532 negate a statement (see below).533 534-``()`` (group)534+(expr)535 group an expression.536 537 Note that there is no support for any bit operations or something similar.538 8 unmodified lines547 548 The following operators are very useful but don't fit into any of the other549 two categories:550 551-``in``551+in552 Perform sequence / mapping containment test. Returns true if the left553 operand is contained in the right. ``{{ 1 in [1, 2, 3] }}`` would for554 example return true.555 556-``is``557- Performs a :ref:`tests <test>`.556+is557+ Performs a :ref:`test <tests>`.558 559-``|``560- Applies a :ref:`filters <filter>`.559+\|560+ Applies a :ref:`filter <filters>`.561 562-``~``562+~563 Converts all operands into strings and concatenates them.564 ``{{ "Hello " ~ name ~ "!" }}`` would return (assuming `name` is565 ``'John'``) ``Hello John!``.566 567-``()`` (call)567+()568 Call a callable: ``{{ post.render() }}``. Inside of the parentheses you569 can use arguments and keyword arguments like in python:570 ``{{ post.render(user, full=true) }}``.571 572-``.`` / ``[]``572+. / []573 Get an attribute of an object. (See :ref:`variables`)574 575 576 .. _if-expression:21 unmodified linesmodified:jinja2/utils.py+5 added-4 removed
246 unmodified lines247 return func248 for method in '__getitem__', '__getslice__', 'capitalize', \249 'title', 'lower', 'upper', 'replace', 'ljust', \250 'rjust', 'lstrip', 'rstrip', 'center', 'strip', \251- 'translate', 'expandtabs', 'rpartition', 'swapcase', \252- 'zfill':251+ 'translate', 'expandtabs', 'swapcase', 'zfill':252 locals()[method] = make_wrapper(method)253 254 # new in python 2.5255 if hasattr(unicode, 'partition'):256+ locals().update(257- locals().update(partition=make_wrapper('partition'),258- rpartition=make_wrapper('rpartition'))257+ partition=make_wrapper('partition'),258+ rpartition=make_wrapper('rpartition')259+ )260 del method, make_wrapper261 262 263 class _MarkupEscapeHelper(object):164 unmodified lines