List Info

Thread: Re: Error with myghty request processing unicode




Re: Error with myghty request processing unicode
country flaguser name
United States
2007-05-16 19:06:40

On May 15, 2007, at 3:22 PM, Victor Kryukov wrote:

>
> Hi group,
>
> I've just installed pylons yesterday, so I apologize if
the question
> I'm asking is too trivial.
>
> Here it is: I tried to redefine TemplateController as
suggested in
> it's documentation string:
>
> from ljeye.lib.base import *
> import myghty.exception
>
> class TemplateController(BaseController):
>     def view(self, url):
>         try:
>             return render_response('/'+url)
>         except myghty.exception.ComponentNotFound:
>             return Response(code=404)
>
> I also placed file called 'help.myt' under /templates.
>
> Now, when I'm trying to access localhost:5000/help.myt,
I'm getting
> the following error:
>
> Error(AttributeError): 'unicode' object has no
attribute
> 'is_file_component'
>
> The reason for this error lies in the way Myghty
handles unicode
> components:
>
> Error:
> Error(AttributeError): 'unicode' object has no
attribute
> 'is_file_component'
> File:
>
/usr/lib/python2.5/site-packages/Myghty-1.1-py2.5.egg/myghty
/
> request.py line 227
> Context:
> 224:             try:
> 225:                 if type(component) ==
types.StringType:
> 226:                     component =
> self.fetch_lead_component(component)
> 227:                 elif
component.is_file_component():
> 228:                     self.request_path =
component.path
> 229:
> 230:                 self.request_component =
component
>
> For some reason, component in my case is u'help.myt',
and hence the
> type(component)==types.StringType comparison failes.
>
> Note that I'm using freshly downloaded 0.9.5 Pylons,
python2.5 etc.,
> and I'm just playing with freshly created pylons
project.
>
> I would appreciate if you could clarify that for me.
>

This is a funny new bug with the TemplateController and the
latest  
version of routes required by Pylons 0.9.5. Routes now gives
you back  
unicode values -- in this case the url passed to the  
TemplateController's action is unicode. And unfortunately
Myghty has  
trouble with a component name in unicode.

There's a few ways to solve this:

o (the easiest) convert the url back to a string yourself:
             return render_response('/'+str(url))

or even:

             return
render_response('/'+url.encode('utf-8'))

o upgrade to the experimental routes trunk that offers a
couple ways  
of turning off unicode:
  - switch the encoding setting to None in your mapper:
     mapper = Mapper()
     mapper.encoding = None

  - switch the encoding off for the particular route:
         map.connect('*url', controller='template',
action='view',  
_encoding=None)

I've logged a ticket for it here: http://pylonshq.com/proj
ect/ 
pylonshq/ticket/242

--
Philip Jenvey



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


[1]

about | contact  Other archives ( Real Estate discussion Medical topics )