diff pylons_app/controllers/hg.py @ 32:f93b523c0be3

dirty fix for multiple file encodings,
author Marcin Kuzminski <marcin@python-blog.com>
date Fri, 05 Mar 2010 01:14:30 +0100
parents 2963f2894a7a
children 707dfdb1c7a8
line wrap: on
line diff
--- a/pylons_app/controllers/hg.py	Thu Mar 04 23:13:12 2010 +0100
+++ b/pylons_app/controllers/hg.py	Fri Mar 05 01:14:30 2010 +0100
@@ -24,11 +24,18 @@
         if request.environ['HTTP_ACCEPT'].find("mercurial") != -1 or \
         request.environ['PATH_INFO'].find('raw-file') != -1:
                     return response
-
-        tmpl = ''.join(response)
+        try:
+            tmpl = u''.join(response)
+            template = Template(tmpl, lookup=request.environ['pylons.pylons']\
+                            .config['pylons.g'].mako_lookup)
+                        
+        except (RuntimeError, UnicodeDecodeError):
+            log.info('disabling unicode due to encoding error')
+            response = g.hgapp(request.environ, self.start_response)
+            tmpl = ''.join(response)
+            template = Template(tmpl, lookup=request.environ['pylons.pylons']\
+                            .config['pylons.g'].mako_lookup, disable_unicode=True)
 
-        template = Template(tmpl, lookup=request.environ['pylons.pylons']\
-                            .config['pylons.g'].mako_lookup)
 
         return template.render(g=g, c=c, session=session, h=h)