|
View:
New views
6 Messages
—
Rating Filter:
Alert me
|
|
|
Serving files (mime-type determination failures), TG 2.0.1, a hack...I have code failing (again) with the "feature" where mime-type declarations are ignored and the system attempts to find a template engine for something that doesn't need a template based on file-name extensions. My code is explicitly setting the response's mime-type (correctly), but for some reason, in some bloody-hard-to-reproduce situations (i.e. one time in a thousand, with some unknown end-user's mobile device) I wind up with an error where the code that attempts to find the template engine shows up and tries to look up "" as a key. To try to get around it for now I'm doing this: # TODO: remove this *ridiculous* hack!!! dec = Decoration.get_decoration( DownloadController.raw ) lte = dec.lookup_template_engine def lookup_template_engine( request ): """Mask the broken TG mime-type stuff""" try: return lte( request ) except KeyError, err: log.error( """Caught low-level error for lookup-template-engine, ignoring""" ) return None,None,[] dec.lookup_template_engine = lookup_template_engine The code that uses it looks like this (simplified): @expose(content_type=CUSTOM_CONTENT_TYPE) def raw( self, *args, **named ): """Provide raw download of bytes...""" ... pylons.response.headers['Content-Type'] = 'application/octet-stream' pylons.response.headers['Content-Disposition'] = 'attachment;filename=%s'%(basename,) ... return file_data where the URL would look like /downloads/raw/somefile.cod (basically a binary application-specific data-file). Anyway, just in case anyone else is running into these tracebacks, there's the hack: File '.../lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py', line 221 in __call__ response = self._dispatch_call() File '.../lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py', line 172 in _dispatch_call response = self._inspect_call(func) File '.../lib/python2.5/site-packages/Pylons-0.9.7-py2.5.egg/pylons/controllers/core.py', line 107 in _inspect_call result = self._perform_call(func, args) File '.../lib/python2.5/site-packages/TurboGears2-2.0.1-py2.5.egg/tg/controllers.py', line 835 in _perform_call self, controller, params, remainder=remainder) File '.../lib/python2.5/site-packages/TurboGears2-2.0.1-py2.5.egg/tg/controllers.py', line 182 in _perform_call response = self._render_response(controller, output) File '.../lib/python2.5/site-packages/TurboGears2-2.0.1-py2.5.egg/tg/controllers.py', line 294 in _render_response controller.decoration.lookup_template_engine(pylons.request) File '.../lib/python2.5/site-packages/TurboGears2-2.0.1-py2.5.egg/tg/decorators.py', line 138 in lookup_template_engine engine, template, exclude_names = self.engines[content_type] KeyError: '' If someone has a real solution, I'd love to hear about it. Note, having apache serve the files is *not* an option, as the content needs to be altered in some instances and I need (complex) authorization to determine if the file is going to be provided. Take care, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@... To unsubscribe from this group, send email to turbogears+unsubscribe@... For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Serving files (mime-type determination failures), TG 2.0.1, a hack...Mike C. Fletcher wrote: Sigh, wrong copy of the hack-code: ... > dec = Decoration.get_decoration( DownloadController.raw ) > lte = dec.lookup_template_engine > def lookup_template_engine( request ): > """Mask the broken TG mime-type stuff""" > return pylons.response.headers['Content-Type'],None,None,[] > dec.lookup_template_engine = lookup_template_engine > Still would rather not have it at all, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@... To unsubscribe from this group, send email to turbogears+unsubscribe@... For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Serving files (mime-type determination failures), TG 2.0.1, a hack...-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Mike C. Fletcher a écrit : | If someone has a real solution, I'd love to hear about it. Note, having | apache serve the files is *not* an option, as the content needs to be | altered in some instances and I need (complex) authorization to | determine if the file is going to be provided. This is working fine for me on tg2.0: ~ @expose() ~ @allow_only(predicates.not_anonymous()) ~ def serve_file(self, date=None, file=None): ~ import paste.fileapp ~ f = paste.fileapp.FileApp('/usr/share/games/xmoto/Textures/Musics/speeditup.ogg', ~ **{'Content-Disposition': 'attachment; filename=' + 'test.ogg'}) ~ from tg import use_wsgi_app ~ return use_wsgi_app(f) Thanks, - -- Jean-Denis Girard SysNux Systèmes Linux en Polynésie française http://www.sysnux.pf/ Tél: +689 50 10 40 / GSM: +689 79 75 27 -----BEGIN PGP SIGNATURE----- iEYEARECAAYFAkrn52cACgkQuu7Rv+oOo/gw9ACgo06ItiOQpgyiv+dtmmc5n5qW iQYAnRt3qikLgeHVR5m2zOXv+TwHJPlr =isEM -----END PGP SIGNATURE----- --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@... To unsubscribe from this group, send email to turbogears+unsubscribe@... For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Serving files (mime-type determination failures), TG 2.0.1, a hack...Jean-Denis Girard wrote: ... > This is working fine for me on tg2.0: > > ~ @expose() > ~ @allow_only(predicates.not_anonymous()) > ~ def serve_file(self, date=None, file=None): > ~ import paste.fileapp > ~ f = > paste.fileapp.FileApp('/usr/share/games/xmoto/Textures/Musics/speeditup.ogg', > ~ **{'Content-Disposition': 'attachment; filename=' + > 'test.ogg'}) > ~ from tg import use_wsgi_app > ~ return use_wsgi_app(f) http://trac.turbogears.org/ticket/2385 that seems to suggest that use_wsgi_app has been removed for TurboGears 2.1 (i.e. it is deprecated). The replacement (WSGIAppController) doesn't seem to be appropriate, though I suppose I could try hooking into object dispatch to return a different controller for each file in the directory. Thanks for the pointer, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@... To unsubscribe from this group, send email to turbogears+unsubscribe@... For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Serving files (mime-type determination failures), TG 2.0.1, a hack...On Wed, Oct 28, 2009 at 9:03 AM, Mike C. Fletcher <mcfletch@...> wrote: > > Jean-Denis Girard wrote: > ... >> This is working fine for me on tg2.0: >> >> ~ @expose() >> ~ @allow_only(predicates.not_anonymous()) >> ~ def serve_file(self, date=None, file=None): >> ~ import paste.fileapp >> ~ f = >> paste.fileapp.FileApp('/usr/share/games/xmoto/Textures/Musics/speeditup.ogg', >> ~ **{'Content-Disposition': 'attachment; filename=' + >> 'test.ogg'}) >> ~ from tg import use_wsgi_app >> ~ return use_wsgi_app(f) > That seems to work fine for me. There's a note here: > > http://trac.turbogears.org/ticket/2385 > > that seems to suggest that use_wsgi_app has been removed for TurboGears > 2.1 (i.e. it is deprecated). The replacement (WSGIAppController) > doesn't seem to be appropriate, though I suppose I could try hooking > into object dispatch to return a different controller for each file in > the directory. > In theory it should support passing the app as a parameter. So you could simply do. return WSGIAppController(paste.fileapp.FileApp(....)).default() It's a little ugly which is why I suggest looking for a better solution. Also note that use_wsgi_app is a very thin rapper that only delegates to the parameter. It has a bug when mounted at a non-root URL, which is why WSGIAppController was born. Regarding the removal of use_wsgi_app it is still there, so we can keep it around until there is a better solution. I have updated the ticket to reflect this. As for the original content type issue I strongly suggest you use the 2.1 version of the code as we had a very hard to fix bug, please follow this documentation http://www.turbogears.org/2.1/docs/main/ResponseTypes.html#setting-the-content-type (the ticket is linked from there) > Thanks for the pointer, > Mike > -- > ________________________________________________ > Mike C. Fletcher > Designer, VR Plumber, Coder > http://www.vrplumber.com > http://blog.vrplumber.com > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@... To unsubscribe from this group, send email to turbogears+unsubscribe@... For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~--- |
|
|
Re: Serving files (mime-type determination failures), TG 2.0.1, a hack...Jorge Vargas wrote: > On Wed, Oct 28, 2009 at 9:03 AM, Mike C. Fletcher > <mcfletch@...> wrote: > ... > encourage you to upgrade WSGIAppController to support this usecase. > ... > As for the original content type issue I strongly suggest you use the > 2.1 version of the code as we had a very hard to fix bug, please > follow this documentation > http://www.turbogears.org/2.1/docs/main/ResponseTypes.html#setting-the-content-type > (the ticket is linked from there) > That fix is, in essence, what I did, but with a hack decorator that eliminates the template engine lookup in the decorators module. I can't update the production system to use 2.1 just yet (alpha isn't something they'll like :) ). I'm really not looking for the full FileApp support, so simply fixing the attempt to look up the templating engine is all *I* need. The fact that the fix is in 2.1 for this usage is sufficient for my clients needs, as we will eventually move to 2.1. Only thing I can imagine needing the full fileapp stuff for is serving up big media files (GBs) without needing to load into ram. Thanks, Mike -- ________________________________________________ Mike C. Fletcher Designer, VR Plumber, Coder http://www.vrplumber.com http://blog.vrplumber.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "TurboGears" group. To post to this group, send email to turbogears@... To unsubscribe from this group, send email to turbogears+unsubscribe@... For more options, visit this group at http://groups.google.com/group/turbogears?hl=en -~----------~----~----~----~------~----~------~--~--- |
| Free embeddable forum powered by Nabble | Forum Help |