Commit ccee7d9e by Chris Jerdonek

Tweaks to the unicode section of the README.

parent cf2f05de
...@@ -31,6 +31,7 @@ Pystache currently works using the following versions of Python: ...@@ -31,6 +31,7 @@ Pystache currently works using the following versions of Python:
* Python 2.7 * Python 2.7
TODO: mention simplejson for earlier versions of Python and yaml. TODO: mention simplejson for earlier versions of Python and yaml.
TODO: try to replace yaml with json. TODO: try to replace yaml with json.
...@@ -76,31 +77,33 @@ Pull it together:: ...@@ -76,31 +77,33 @@ Pull it together::
u'Hello, Pizza!' u'Hello, Pizza!'
Unicode Unicode Handling
======= ================
This section describes Pystache's handling of unicode (e.g. strings and
encodings).
This section describes Pystache's handling of unicode, strings, and encodings. Internally Pystache uses only unicode strings. For input, Pystache accepts
Pystache's template rendering methods output only unicode. Moreover, both ``unicode`` and ``str`` strings. For output, Pystache's template
internally Pystache uses only unicode strings. For input, Pystache accepts rendering methods return only unicode.
both ``unicode`` and ``str`` strings.
The Renderer class supports a number of attributes that control how it The Renderer class supports a number of attributes that control how Pystache
converts ``str`` strings to unicode on input. These attributes include converts ``str`` strings to unicode on input. These include the
the file_encoding, string_encoding, and decode_errors attributes. file_encoding, string_encoding, and decode_errors attributes.
The file_encoding attribute is the encoding the renderer uses to convert The file_encoding attribute is the encoding the renderer uses to convert
to unicode any files read from the file system. Similarly, string_encoding any files read from the file system to unicode. Similarly, string_encoding
is the encoding the renderer uses to convert any other strings of type str is the encoding the renderer uses to convert any other strings of type str
to unicode (e.g. context values of type ``str``). The decode_errors to unicode (e.g. context values of type ``str``). The decode_errors
attribute is what the renderer passes as the ``errors`` argument to attribute is what the renderer passes as the ``errors`` argument to
Python's built-in `unicode()`_ function. The valid values are 'strict', Python's built-in `unicode()`_ function when converting. The valid values
'ignore', or 'replace'. are 'strict', 'ignore', or 'replace'.
Each of these attributes can be set via the Renderer class's constructor Each of these attributes can be set via the Renderer class's constructor
using a keyword argument of the same name. In addition, the file_encoding using a keyword argument of the same name. In addition, the file_encoding
attribute can be controlled on a per-view basis by subclassing the attribute can be controlled on a per-view basis by subclassing the class
`TemplateSpec` class. The attributes default to values set in Pystache's `TemplateSpec`. When not specified explicitly, these attributes default
``defaults`` module. to values set in Pystache's ``defaults`` module.
Test It Test It
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment