Re: [Repoze-dev] bfg chameleon unicode crash with wrapper views

2010-12-16 Thread Iain Duncan
On Thu, Dec 16, 2010 at 12:47 PM, Chris McDonough  wrote:

> On Thu, 2010-12-16 at 12:42 -0800, Iain Duncan wrote:
> > Oops I copied a traceback from one of my attempts at fixing it.
> >
> >
> >
> > Tres, that worked, thanks. I'm curious why it's necessary though. It
> > seems to me it should "just work" right? Can anyone explain further
> > why that step is necessary once a view is wrapped?  ( related note,
> > wrapper views are awesome, the docs could totally use more wrapper
> > view examples! =)
>
> There's no particular justification here.  The feature was added hastily
> and is infrequently used.  Probably would have set
> "request.wrapped_body" to "response.unicode_body" instead of
> "response.body" if I had been thinking about it hard enough.  But you
> can get the same effect by doing
> "request.wrapped_response.unicode_body".
>

Got it, well register this as a request for more attention to wrapper views,
I think they're freaking awesome. But I have noticed some rough edges. ( My
wrapper view also killed the bfg stock url finding method and I had to make
a home rolled one and a url fixing layer ).

I'd also love to see wrapper view zcml declarations get easier, I'm doing
this:




Would be great to be able to put the wrapper arg directly on the route.

thanks for everything guys. I will be evangelizing Chameleon/Pyramid out in
the northwest! =)
iain
___
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev


Re: [Repoze-dev] bfg chameleon unicode crash with wrapper views

2010-12-16 Thread Chris McDonough
On Thu, 2010-12-16 at 12:42 -0800, Iain Duncan wrote:
> Oops I copied a traceback from one of my attempts at fixing it.
> 
> 
> 
> Tres, that worked, thanks. I'm curious why it's necessary though. It
> seems to me it should "just work" right? Can anyone explain further
> why that step is necessary once a view is wrapped?  ( related note,
> wrapper views are awesome, the docs could totally use more wrapper
> view examples! =) 

There's no particular justification here.  The feature was added hastily
and is infrequently used.  Probably would have set
"request.wrapped_body" to "response.unicode_body" instead of
"response.body" if I had been thinking about it hard enough.  But you
can get the same effect by doing
"request.wrapped_response.unicode_body".

- C



___
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev


Re: [Repoze-dev] bfg chameleon unicode crash with wrapper views

2010-12-16 Thread Iain Duncan
Oops I copied a traceback from one of my attempts at fixing it.

Tres, that worked, thanks. I'm curious why it's necessary though. It seems
to me it should "just work" right? Can anyone explain further why that step
is necessary once a view is wrapped?  ( related note, wrapper views are
awesome, the docs could totally use more wrapper view examples! =)

Malte, how do I do that? Is it possible to do that when I am using a
renderer argument to a view zcml registration? I am having problems when I
get unicode out of the db too but haven't figured out whether it's a
chameleon setting I'm missing or a mysql encoding setting that's off.

thanks guys
Iain

On Thu, Dec 16, 2010 at 5:58 AM, Malthe Borch  wrote:

> Alternatively, enable implicit decoding using
> ``default_encoding="utf-8"`` (in the template constructor). This is
> enabled on Plone, for instance.
>
> \malthe
>
> On 16 December 2010 14:47, Tres Seaver  wrote:
> > -BEGIN PGP SIGNED MESSAGE-
> > Hash: SHA1
> >
> > On 12/15/2010 10:18 PM, Iain Duncan wrote:
> >> Not sure where I'm supposed to ask this now, here? Pyramid list?
> >>
> >> I have  view with a chameleon template that contains utf-8 unicode
> special
> >> chars. It renders fine when rendered on it's own from a view. As soon as
> I
> >> wrap that view with a wrapper view, I get errors with the wrapper
> choking on
> >> the unicode.
> >>
> >> My master views call method is like this:
> >>
> >> def __call__(self):
> >> tmpl_dict = {}
> >> tmpl_dict['inner_content'] = self.request.wrapped_body
> >> return tmpl_dict
> >>
> >>
> >> I get the following traceback ( snipped ):
> >> File
> >>
> "/home/jordans/Jordans/eggs/repoze.bfg-1.2.2-py2.6.egg/repoze/bfg/router.py",
> >> line 130, in __call__
> >> response = view_callable(context, request)
> >> File
> >>
> "/home/jordans/Jordans/eggs/repoze.bfg-1.2.2-py2.6.egg/repoze/bfg/configuration.py",
> >> line 1724, in _owrapped_view
> >> wrapper_viewname)
> >> File
> >>
> "/home/jordans/Jordans/eggs/repoze.bfg-1.2.2-py2.6.egg/repoze/bfg/view.py",
> >> line 90, in render_view_to_response
> >> return view(context, request)
> >> File
> >>
> "/home/jordans/Jordans/eggs/repoze.bfg-1.2.2-py2.6.egg/repoze/bfg/configuration.py",
> >> line 1663, in _bfg_class_view
> >> response = inst()
> >> File "/home/jordans/Jordans/jordans/views/master_view.py", line 22, in
> >> __call__
> >> tmpl_dict['inner_content'] = u"%s" % self.request.wrapped_body
> >> UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position
> 4090:
> >> ordinal not in range(128)
> >>
> >>
> >> Any clues?
> >
> > The code in the traceback doesn't match the sample you showed above:
> > the 'wrapped_body' is an encoded string (WebOb responses always encode
> > the body with the supplied charset) which the view is trying to decode
> > (back?) to unicode without supplying the encoding.  The default encoding
> > used by WebOb is 'UTF-8', so I would try:
> >
> >def __call__(self):
> >tmpl_dict = {}
> >body = self.request.wrapped_body
> >tmpl_dict['inner_content'] = body.decode('UTF-8')
> >return tmpl_dict
> >
> >
> >
> > Tres.
> > - --
> > ===
> > Tres Seaver  +1 540-429-0999  tsea...@palladion.com
> > Palladion Software   "Excellence by Design"http://palladion.com
> > -BEGIN PGP SIGNATURE-
> > Version: GnuPG v1.4.10 (GNU/Linux)
> > Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
> >
> > iEYEARECAAYFAk0KGHEACgkQ+gerLs4ltQ7FZQCgzIl5cIsJbt1viMO8KKAre97j
> > ne8An1T4tFdxXHTQzOcSJyWpP7hGiBcq
> > =Ty1s
> > -END PGP SIGNATURE-
> > ___
> > Repoze-dev mailing list
> > Repoze-dev@lists.repoze.org
> > http://lists.repoze.org/listinfo/repoze-dev
> >
>
___
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev


Re: [Repoze-dev] bfg chameleon unicode crash with wrapper views

2010-12-16 Thread Malthe Borch
Alternatively, enable implicit decoding using
``default_encoding="utf-8"`` (in the template constructor). This is
enabled on Plone, for instance.

\malthe

On 16 December 2010 14:47, Tres Seaver  wrote:
> -BEGIN PGP SIGNED MESSAGE-
> Hash: SHA1
>
> On 12/15/2010 10:18 PM, Iain Duncan wrote:
>> Not sure where I'm supposed to ask this now, here? Pyramid list?
>>
>> I have  view with a chameleon template that contains utf-8 unicode special
>> chars. It renders fine when rendered on it's own from a view. As soon as I
>> wrap that view with a wrapper view, I get errors with the wrapper choking on
>> the unicode.
>>
>> My master views call method is like this:
>>
>> def __call__(self):
>>     tmpl_dict = {}
>>     tmpl_dict['inner_content'] = self.request.wrapped_body
>>     return tmpl_dict
>>
>>
>> I get the following traceback ( snipped ):
>> File
>> "/home/jordans/Jordans/eggs/repoze.bfg-1.2.2-py2.6.egg/repoze/bfg/router.py",
>> line 130, in __call__
>> response = view_callable(context, request)
>> File
>> "/home/jordans/Jordans/eggs/repoze.bfg-1.2.2-py2.6.egg/repoze/bfg/configuration.py",
>> line 1724, in _owrapped_view
>> wrapper_viewname)
>> File
>> "/home/jordans/Jordans/eggs/repoze.bfg-1.2.2-py2.6.egg/repoze/bfg/view.py",
>> line 90, in render_view_to_response
>> return view(context, request)
>> File
>> "/home/jordans/Jordans/eggs/repoze.bfg-1.2.2-py2.6.egg/repoze/bfg/configuration.py",
>> line 1663, in _bfg_class_view
>> response = inst()
>> File "/home/jordans/Jordans/jordans/views/master_view.py", line 22, in
>> __call__
>> tmpl_dict['inner_content'] = u"%s" % self.request.wrapped_body
>> UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 4090:
>> ordinal not in range(128)
>>
>>
>> Any clues?
>
> The code in the traceback doesn't match the sample you showed above:
> the 'wrapped_body' is an encoded string (WebOb responses always encode
> the body with the supplied charset) which the view is trying to decode
> (back?) to unicode without supplying the encoding.  The default encoding
> used by WebOb is 'UTF-8', so I would try:
>
>    def __call__(self):
>        tmpl_dict = {}
>        body = self.request.wrapped_body
>        tmpl_dict['inner_content'] = body.decode('UTF-8')
>        return tmpl_dict
>
>
>
> Tres.
> - --
> ===
> Tres Seaver          +1 540-429-0999          tsea...@palladion.com
> Palladion Software   "Excellence by Design"    http://palladion.com
> -BEGIN PGP SIGNATURE-
> Version: GnuPG v1.4.10 (GNU/Linux)
> Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
>
> iEYEARECAAYFAk0KGHEACgkQ+gerLs4ltQ7FZQCgzIl5cIsJbt1viMO8KKAre97j
> ne8An1T4tFdxXHTQzOcSJyWpP7hGiBcq
> =Ty1s
> -END PGP SIGNATURE-
> ___
> Repoze-dev mailing list
> Repoze-dev@lists.repoze.org
> http://lists.repoze.org/listinfo/repoze-dev
>
___
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev


Re: [Repoze-dev] bfg chameleon unicode crash with wrapper views

2010-12-16 Thread Tres Seaver
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 12/15/2010 10:18 PM, Iain Duncan wrote:
> Not sure where I'm supposed to ask this now, here? Pyramid list?
> 
> I have  view with a chameleon template that contains utf-8 unicode special
> chars. It renders fine when rendered on it's own from a view. As soon as I
> wrap that view with a wrapper view, I get errors with the wrapper choking on
> the unicode.
> 
> My master views call method is like this:
> 
> def __call__(self):
> tmpl_dict = {}
> tmpl_dict['inner_content'] = self.request.wrapped_body
> return tmpl_dict
> 
> 
> I get the following traceback ( snipped ):
> File
> "/home/jordans/Jordans/eggs/repoze.bfg-1.2.2-py2.6.egg/repoze/bfg/router.py",
> line 130, in __call__
> response = view_callable(context, request)
> File
> "/home/jordans/Jordans/eggs/repoze.bfg-1.2.2-py2.6.egg/repoze/bfg/configuration.py",
> line 1724, in _owrapped_view
> wrapper_viewname)
> File
> "/home/jordans/Jordans/eggs/repoze.bfg-1.2.2-py2.6.egg/repoze/bfg/view.py",
> line 90, in render_view_to_response
> return view(context, request)
> File
> "/home/jordans/Jordans/eggs/repoze.bfg-1.2.2-py2.6.egg/repoze/bfg/configuration.py",
> line 1663, in _bfg_class_view
> response = inst()
> File "/home/jordans/Jordans/jordans/views/master_view.py", line 22, in
> __call__
> tmpl_dict['inner_content'] = u"%s" % self.request.wrapped_body
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 4090:
> ordinal not in range(128)
> 
> 
> Any clues?

The code in the traceback doesn't match the sample you showed above:
the 'wrapped_body' is an encoded string (WebOb responses always encode
the body with the supplied charset) which the view is trying to decode
(back?) to unicode without supplying the encoding.  The default encoding
used by WebOb is 'UTF-8', so I would try:

def __call__(self):
tmpl_dict = {}
body = self.request.wrapped_body
tmpl_dict['inner_content'] = body.decode('UTF-8')
return tmpl_dict



Tres.
- -- 
===
Tres Seaver  +1 540-429-0999  tsea...@palladion.com
Palladion Software   "Excellence by Design"http://palladion.com
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk0KGHEACgkQ+gerLs4ltQ7FZQCgzIl5cIsJbt1viMO8KKAre97j
ne8An1T4tFdxXHTQzOcSJyWpP7hGiBcq
=Ty1s
-END PGP SIGNATURE-
___
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev


[Repoze-dev] bfg chameleon unicode crash with wrapper views

2010-12-15 Thread Iain Duncan
Not sure where I'm supposed to ask this now, here? Pyramid list?

I have  view with a chameleon template that contains utf-8 unicode special
chars. It renders fine when rendered on it's own from a view. As soon as I
wrap that view with a wrapper view, I get errors with the wrapper choking on
the unicode.

My master views call method is like this:

def __call__(self):
tmpl_dict = {}
tmpl_dict['inner_content'] = self.request.wrapped_body
return tmpl_dict


I get the following traceback ( snipped ):
File
"/home/jordans/Jordans/eggs/repoze.bfg-1.2.2-py2.6.egg/repoze/bfg/router.py",
line 130, in __call__
response = view_callable(context, request)
File
"/home/jordans/Jordans/eggs/repoze.bfg-1.2.2-py2.6.egg/repoze/bfg/configuration.py",
line 1724, in _owrapped_view
wrapper_viewname)
File
"/home/jordans/Jordans/eggs/repoze.bfg-1.2.2-py2.6.egg/repoze/bfg/view.py",
line 90, in render_view_to_response
return view(context, request)
File
"/home/jordans/Jordans/eggs/repoze.bfg-1.2.2-py2.6.egg/repoze/bfg/configuration.py",
line 1663, in _bfg_class_view
response = inst()
File "/home/jordans/Jordans/jordans/views/master_view.py", line 22, in
__call__
tmpl_dict['inner_content'] = u"%s" % self.request.wrapped_body
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe2 in position 4090:
ordinal not in range(128)


Any clues?

thanks
___
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev