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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to