Re: [pystache] unicode encoding
- From:
- Adam Suharja
- Date:
- 2012-04-03 @ 03:48
Hi Chris,
The Renderer class docs were very helpful. In my particular case, finding
render_path() was also useful.
Thanks!
Adam
On Apr 2, 2012, at 11:40 AM, Chris Jerdonek wrote:
> Hi Adam,
>
> Whenever you want to render one or more templates (or views), you
> should first construct an instance of the Renderer class. Then to
> render a template, you'll want to call that Renderer instance's
> render() method. The development branch's README has a couple simple
> examples of this:
>
> https://github.com/defunkt/pystache/tree/development
>
> The first thing to understand about unicode in this version of
> Pystache is that render() will always return a unicode string rather
> than an str string.
>
> The other thing to understand is that the Renderer class constructor
> accepts a number of arguments to control how it converts strings to
> unicode. For example, it supports the keyword arguments
> decode_errors, string_encoding, and file_encoding:
>
> https://github.com/defunkt/pystache/blob/development/pystache/renderer.py
>
> The decode_errors argument is what the Renderer instance will pass to
> Python's built-in unicode() function for the errors argument:
>
> http://docs.python.org/library/functions.html#unicode
>
> The file_encoding argument is the encoding it will use to convert any
> files read from the file system to unicode. And the string_encoding
> argument is the encoding it will use to convert to unicode any other
> strings of type str it encounters during the rendering process (e.g.
> string properties of a view). Both of these encodings default to
> sys.getdefaultencoding(), which is 'ascii' on my system. You'll
> probably want to use something like 'utf-8' for both of these.
>
> Does that answer your question?
>
> --Chris
>
>
>
>
>
> On Mon, Apr 2, 2012 at 5:31 AM, Adam Suharja <a@suharja.com> wrote:
>> Thanks, Chris.
>> I'll go with the development branch.
>> Adam
>>
>> On Apr 2, 2012, at 1:40 AM, Chris Jerdonek <chris.jerdonek@gmail.com> wrote:
>>
>>> Hi Adam,
>>>
>>> The treatment of unicode and encodings has been revamped and made more
>>> consistent in the next version of pystache which should be released
>>> from the development branch in the next couple weeks or so (v0.5.0):
>>> https://github.com/defunkt/pystache/tree/development
>>>
>>> Would you like to be helped from that version or from the last
>>> released version v0.4.1? I would recommend using the version in the
>>> development branch if possible because I'm more certain that it's
>>> likely to be working correctly there.
>>>
>>> --Chris
>>>
>>>
>>>
>>> On Sun, Apr 1, 2012 at 9:39 PM, Adam Suharja <a@suharja.com> wrote:
>>>> Hello,
>>>> I'm having a hard time understanding how to use unicode with
pystache. I see the examples folder and view subclass sample, but I'm
still unsure of how this works.
>>>>
>>>> Thanks
Re: [pystache] unicode encoding
- From:
- Chris Jerdonek
- Date:
- 2012-04-03 @ 02:26
FYI, I added to the README a section on unicode handling that now
contains the information below:
https://github.com/defunkt/pystache/tree/development
--Chris
On Mon, Apr 2, 2012 at 8:40 AM, Chris Jerdonek <chris.jerdonek@gmail.com> wrote:
> Hi Adam,
>
> Whenever you want to render one or more templates (or views), you
> should first construct an instance of the Renderer class. Then to
> render a template, you'll want to call that Renderer instance's
> render() method. The development branch's README has a couple simple
> examples of this:
>
> https://github.com/defunkt/pystache/tree/development
>
> The first thing to understand about unicode in this version of
> Pystache is that render() will always return a unicode string rather
> than an str string.
>
> The other thing to understand is that the Renderer class constructor
> accepts a number of arguments to control how it converts strings to
> unicode. For example, it supports the keyword arguments
> decode_errors, string_encoding, and file_encoding:
>
> https://github.com/defunkt/pystache/blob/development/pystache/renderer.py
>
> The decode_errors argument is what the Renderer instance will pass to
> Python's built-in unicode() function for the errors argument:
>
> http://docs.python.org/library/functions.html#unicode
>
> The file_encoding argument is the encoding it will use to convert any
> files read from the file system to unicode. And the string_encoding
> argument is the encoding it will use to convert to unicode any other
> strings of type str it encounters during the rendering process (e.g.
> string properties of a view). Both of these encodings default to
> sys.getdefaultencoding(), which is 'ascii' on my system. You'll
> probably want to use something like 'utf-8' for both of these.
>
> Does that answer your question?
>
> --Chris
>
>
>
>
>
> On Mon, Apr 2, 2012 at 5:31 AM, Adam Suharja <a@suharja.com> wrote:
>> Thanks, Chris.
>> I'll go with the development branch.
>> Adam
>>
>> On Apr 2, 2012, at 1:40 AM, Chris Jerdonek <chris.jerdonek@gmail.com> wrote:
>>
>>> Hi Adam,
>>>
>>> The treatment of unicode and encodings has been revamped and made more
>>> consistent in the next version of pystache which should be released
>>> from the development branch in the next couple weeks or so (v0.5.0):
>>> https://github.com/defunkt/pystache/tree/development
>>>
>>> Would you like to be helped from that version or from the last
>>> released version v0.4.1? I would recommend using the version in the
>>> development branch if possible because I'm more certain that it's
>>> likely to be working correctly there.
>>>
>>> --Chris
>>>
>>>
>>>
>>> On Sun, Apr 1, 2012 at 9:39 PM, Adam Suharja <a@suharja.com> wrote:
>>>> Hello,
>>>> I'm having a hard time understanding how to use unicode with
pystache. I see the examples folder and view subclass sample, but I'm
still unsure of how this works.
>>>>
>>>> Thanks