Hello sorry for the delay, was away from the computer (yeah I should not do 
that:) )

It worked

To be more specific it does not work if I prefix the string as "unicode" 
(u"....") but it does work with my accentuated string straight in the file, 
that make sense since my file has the # -*- coding: utf-8 -*- stance at the top.
One day I'll wrap my head for good around that python - unicode stuff, probably 
right before the python ecosystem is ready for python 3 ;).

for reference Error message with the u"mesure de la complexité relative de la 
fiche" string is 
File 
"C:\Dev\Sources\TimeCards\lib\site-packages\chameleon-1.1.1-py2.5.egg\chameleon\core\template.py",
 line 180, in cook_and_render
    return func(econtext, rcontext)
  File "<string>", line 160, in render
  File "<string>", line 1, in __str__
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 
22: ordinal not in range(128)

position 22 is the 'é' of course ;)



Thanks a lot ChrisM.



----- Mail Original -----
De: "Chris McDonough" <chr...@plope.com>
À: duncanid...@vectorball.com
Cc: repoze-dev@lists.repoze.org
Envoyé: Vendredi 2 Avril 2010 20h24:23 GMT +01:00 Amsterdam / Berlin / Berne / 
Rome / Stockholm / Vienne
Objet: Re: [Repoze-dev] Trouble with unicode through formish in repoze.bfg and  
"form" attribute in the request

Hi Duncan,

Can you try applying the following patch to repoze.bfg.formish?

Index: repoze/bfg/formish/__init__.py
===================================================================
--- repoze/bfg/formish/__init__.py      (revision 8819)
+++ repoze/bfg/formish/__init__.py      (working copy)
@@ -48,7 +48,8 @@
                      "Can not find template %s" % filename)
              try:
                  return PageTemplateFile(path, parser=self.parser,
-                                        auto_reload=self.auto_reload)
+                                        auto_reload=self.auto_reload,
+                                        encoding='utf-8')
              except OSError:
                  self.notexists[path] = True

(IOW, add the argument "encoding='utf-8'" to the call to PageTemplateFile 
within the "load" method of the TemplateLoader in 
repoze/bfg/formish/__init__.py).

- C


On 4/2/10 12:17 PM, duncanid...@vectorball.com wrote:
> Hello all.
>
> I am exploring repoze.bfg and trying to get a feeling of the whole framework 
> and past through the "so many things to know so little brain and time" wall :)
> I read the book from cover to cover and wanted to take the opportunity to 
> thank the people at Repoze for the documentation and the book.
>
> I wanted to use formish to evaluate form creation and after much fight was 
> able to display my form.
> But when I try to put an unicode string in the description I have a  
> traceback at runtime like so
> "
> C:\Dev\Sources\TimeCards\lib\site-packages\chameleon-1.1.1-py2.5.egg\chameleon\core\template.py",
>  line 180, in cook_and_render
>      return func(econtext, rcontext)
>    File "<string>", line 160, in render
>    File "<string>", line 1, in __str__
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 
> 22: ordinal not in range(128)
> "
>
> My code is
> pointValue_field=schemaish.Integer(description=(u"mesure de la complexité 
> relative de la fiche"),
>                                         
> validator=validator.All(validator.Range(min=0), validator.Required())
>                                     )
>
> of course removing the u"..." brings at runtime and expected
> "File"<string>", line 185, in render
>    File 
> "C:\Dev\Sources\TimeCards\lib\site-packages\chameleon-1.1.1-py2.5.egg\chameleon\core\generation.py",
>  line 42, in getvalue
>      return ''.join(self)
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 22: 
> ordinal not in range(128)
> "
>
> all my files have the # -*- coding: utf-8 -*- stance at the top of course.
>
> I know unicode is a very complex beast so I wanted to know if people here 
> could point me at some basic obvious thing in my way of doing things or if 
> some parts of bfg/formish were known to have trouble with unicode string, or 
> if it is a formish problem entirely that I should bring to the formish 
> developers.
>
> I am willing to do tests as suggested.
>
>
>
> thanks a lot for your time.
> _______________________________________________
> Repoze-dev mailing list
> Repoze-dev@lists.repoze.org
> http://lists.repoze.org/listinfo/repoze-dev


-- 
Chris McDonough
Agendaless Consulting, Fredericksburg VA
The repoze.bfg Web Application Framework Book: http://bfg.repoze.org/book
_______________________________________________
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev

Reply via email to