Skip to content
Myr

Some tiny documentation fixes (unicode -> Unicode)

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 88dc32c · Browse files · 2 files+10 added−10 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+10 added−10 removed

  • other:+10 added−10 removed

2 files+10 added−10 removed

modified:docs/api.rst+9 added-9 removed
50 unmodified lines
5152Unicode53-------5455Jinja2 is using unicode internally which means that you have to pass unicode55Jinja2 is using Unicode internally which means that you have to pass Unicode56objects to the render function or bytestrings that only consist of ASCII57characters. Additionally newlines are normalized to one end of line58sequence which is per default UNIX style (``\n``).59
3 unmodified lines
63be used to store text based information unless only ASCII characters are64used. With Python 2.6 it is possible to make `unicode` the default on a per65module level and with Python 3 it will be the default.6667To explicitly use a unicode string you have to prefix the string literal67To explicitly use a Unicode string you have to prefix the string literal68with a `u`: ``u'Hänsel und Gretel sagen Hallo'``. That way Python will69store the string as unicode by decoding the string with the character69store the string as Unicode by decoding the string with the character70encoding from the current Python module. If no encoding is specified this71defaults to 'ASCII' which means that you can't use any non ASCII identifier.7273To set a better module encoding add the following comment to the first or74second line of the Python module using the unicode literal::74second line of the Python module using the Unicode literal::7576 # -*- coding: utf-8 -*-7778We recommend utf-8 as Encoding for Python modules and templates as it's79possible to represent every Unicode character in utf-8 and because it's80backwards compatible to ASCII. For Jinja2 the default encoding of templates81is assumed to be utf-8.8283It is not possible to use Jinja2 to process non unicode data. The reason83It is not possible to use Jinja2 to process non-Unicode data. The reason84for this is that Jinja2 uses Unicode already on the language level. For85example Jinja2 treats the non-breaking space as valid whitespace inside86expressions which requires knowledge of the encoding or operating on an87unicode string.87Unicode string.8889For more details about unicode in Python have a look at the excellent89For more details about Unicode in Python have a look at the excellent90`Unicode documentation`_.9192Another important thing is how Jinja2 is handling string literals in93templates. A naive implementation would be using unicode strings for93templates. A naive implementation would be using Unicode strings for94all string literals but it turned out in the past that this is problematic95as some libraries are typechecking against `str` explicitly. For example96`datetime.strftime` does not accept unicode arguments. To not break it96`datetime.strftime` does not accept Unicode arguments. To not break it97completely Jinja2 is returning `str` for strings that fit into ASCII and98for everything else `unicode`:99100>>> m = Template(u"{% set a, b = 'foo', 'föö' %}").module
584 unmodified lines
modified:docs/intro.rst+1 added-1 removed
35 unmodified lines
36that can create python extensions should be installed for the debugger. If no37C-compiler is available and you are using Python 2.4 the `ctypes`_ module38should be installed.3940If you don't have a working C compiler and you are trying to install the source40If you don't have a working C-compiler and you are trying to install the source41release with the speedups you will get a compiler error. This however can be42circumvented by passing the ``--without-speedups`` command line argument to the43setup script::44
109 unmodified lines