i just have some hints for you:

* i have import sys; reload( sys ); sys.setdefaultencoding( 'utf-8' )
near the top of my config/environment.py; this should make utf-8 the
vm-wide default encoding and replace us ascii;

* further down in the same file, i have:

  templating_options = {
    ...
    'mako.input_encoding':        'UTF-8',
    'mako.output_encoding':       'UTF-8',
    'mako.default_filters':       [ 'decode.utf8', ],
    }

however, the line with the 'default_filters' is deprecated according
to http://wiki.pylonshq.com/pages/viewpage.action?pageId=5439551 ('
Why do I get a UnicodeDecodeError when using Mako?', which you should
probably give a quick glance). my understanding of this doc is that
probably i should simply leave out the default_filters line.

* i start each mako template with

  # -*- coding: utf-8 -*-

as the very first line.

whether you use an ORM or work directly with a python DB API 2
compliant driver for your database, the texts you get out of the
database *should* be already unicode objects *if* they are
appropriately stored. however, in the general case a textual value in
a DB row can potentially be *any* sequence of bytes in *any* encoding,
which you may want to check.

hope this helps,

_wolf



On Oct 29, 2:14 am, SamDonaldson <[EMAIL PROTECTED]> wrote:
> Could somebody seriously help me out here?  I got through the Unicode
> issue and wrote some of my own validator code in formencode to except
> strings in a more lenient way.  I'm storing this away in MySQL with
> the charset set to utf-8 with the default collation.  Upon trying to
> render this field in a Mako template, I get the following:
>
> Module mako.runtime:91 in call_wno_caller
> <<              try:
>                     self.__stack.append(None)
>                     return callable_(*args, **kwargs)
>                 finally:
>                     self.__stack.pop()>>  return callable_(*args,
> **kwargs)
> Module _web_base_tmpl:77 in body
> <<                  # SOURCE LINE 45
>                     context.write(u'    <title>')
>                     context.write(unicode(title))
>                     context.write(u' | BLAH</title>\r\n')
>                     # SOURCE LINE 46
>     >>  context.write(unicode(title))
> exceptions.UnicodeDecodeError: 'utf8' codec can't decode bytes in
> position 14-18: unsupported Unicode code range
>
> How do I get the string from the db to be unicode?  Please help
> thanks.  Note that I added the following to my base controller:
>
> import sys
> reload(sys)
> sys.setdefaulttype('utf-8')
>
> So I'm wondering if Mako is requiring this setting but is not picking
> it up.
>
> Thanks,
>
> Sam.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to