Changeset - 707dfdb1c7a8
[Not reviewed]
default
0 1 0
marcink - 16 years ago 2010-03-18 14:37:05

Bugfix when client is using old mercurial version and not setting http accept
1 file changed with 7 insertions and 1 deletions:
0 comments (0 inline, 0 general)
pylons_app/controllers/hg.py
Show inline comments
 
@@ -2,35 +2,41 @@
 
# -*- coding: utf-8 -*-
 
import logging
 
from pylons_app.lib.base import BaseController, render
 
from pylons import c, g, session, request
 
from pylons_app.lib import helpers as h
 
from mako.template import Template
 
from pprint import pprint
 
import os
 
from mercurial import ui, hg
 
from mercurial.error import RepoError
 
from ConfigParser import ConfigParser
 
import encodings
 
from pylons.controllers.util import abort
 
log = logging.getLogger(__name__)
 

	
 
class HgController(BaseController):
 

	
 
    def __before__(self):
 
        c.repos_prefix = 'etelko'
 

	
 
    def view(self, *args, **kwargs):
 
        response = g.hgapp(request.environ, self.start_response)
 
        
 
        http_accept = request.environ.get('HTTP_ACCEPT', False)
 
        if not http_accept:
 
            return abort(status_code=400, detail='no http accept in header')
 
        
 
        #for mercurial protocols and raw files we can't wrap into mako
 
        if request.environ['HTTP_ACCEPT'].find("mercurial") != -1 or \
 
        if http_accept.find("mercurial") != -1 or \
 
        request.environ['PATH_INFO'].find('raw-file') != -1:
 
                    return 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']\
0 comments (0 inline, 0 general)