Skip to content
Myr

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

2 files+30 added−29 removed

modified:docs/templates.rst+25 added-25 removed
436 unmodified lines
437438The simplest form of expressions are literals. Literals are representations439for Python objects such as strings and numbers. The following literals exist:440441``"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).446447``42`` / ``42.23``44742 / 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.452453``['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 lines
463 <li><a href="{{ href }}">{{ caption }}</a></li>464 {% endfor %}465 </ul>466467``('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.472473``{'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.478479``true`` and ``false``479true / false:480 true is always true and false is always false. Keep in mind that those481 literals are lowercase!482483Math
1 unmodified line
485486Jinja allows you to calculate with values. This is rarely useful in templates487but exists for completeness sake. The following operators are supported:488489``+``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``.494495``-``495\-496 Substract two numbers from each other. ``{{ 3 - 2 }}`` is ``1``.497498``/``498/499 Divide two numbers. The return value will be a floating point number.500 ``{{ 1 / 2 }}`` is ``{{ 0.5 }}``.501502``//``502//503 Divide two numbers and return the truncated integer result.504 ``{{ 20 / 7 }}`` is ``2``.505506``%``506%507 Calculate the remainder of an integer division between the left and right508 operand. ``{{ 11 % 7 }}`` is ``4``.509510``*``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.514515``**``515\**516 Raise the left operand to the power of the right operand. ``{{ 2**3 }}``517 would return ``8``.518519Logic
1 unmodified line
521522For `if` statements / `for` filtering or `if` expressions it can be useful to523combine group multiple expressions:524525``and``525and526 Return true if the left and the right operand is true.527528``or``528or529 Return true if the left or the right operand is true.530531``not``531not532 negate a statement (see below).533534``()`` (group)534(expr)535 group an expression.536537Note that there is no support for any bit operations or something similar.538
8 unmodified lines
547548The following operators are very useful but don't fit into any of the other549two categories:550551``in``551in552 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.555556``is``557 Performs a :ref:`tests <test>`.556is557 Performs a :ref:`test <tests>`.558559``|``560 Applies a :ref:`filters <filter>`.559\|560 Applies a :ref:`filter <filters>`.561562``~``562~563 Converts all operands into strings and concatenates them.564 ``{{ "Hello " ~ name ~ "!" }}`` would return (assuming `name` is565 ``'John'``) ``Hello John!``.566567``()`` (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) }}``.571572``.`` / ``[]``572. / []573 Get an attribute of an object. (See :ref:`variables`)574575576.. _if-expression:
21 unmodified lines
modified:jinja2/utils.py+5 added-4 removed
246 unmodified lines
247 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)253254 # 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_wrapper261262263class _MarkupEscapeHelper(object):
164 unmodified lines