~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/__init__.py

  • Committer: Michael Hudson
  • Date: 2008-06-25 00:00:19 UTC
  • mto: This revision was merged to the branch mainline in revision 176.
  • Revision ID: michael.hudson@canonical.com-20080625000019-ryd8963fhgp8ix2h
twiddle things around so we can stream our output

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
        self._branch = branch
33
33
        self.log = branch.log
34
34
 
35
 
    def default(self, request, response):
 
35
    def default(self, request, start_response):
36
36
        z = time.time()
37
37
        h = self._branch.history
38
38
        kw = request.GET
54
54
                'url': self._branch.context_url,
55
55
            }
56
56
            vals.update(templatefunctions)
57
 
            del response.headers['Content-Type']
58
 
            vals.update(self.get_values(h, args, kw, response))
 
57
            headers = {}
 
58
            vals.update(self.get_values(h, args, kw, headers))
59
59
 
60
60
            self.log.info('Getting information for %s: %r secs' % (
61
61
                self.__class__.__name__, time.time() - z,))
62
 
            if 'Content-Type' not in response.headers:
63
 
                response.headers['Content-Type'] = 'text/html'
 
62
            if 'Content-Type' not in headers:
 
63
                headers['Content-Type'] = 'text/html'
 
64
            writer = start_response("200 OK", headers.items())
64
65
            template = load_template(self.template_path)
65
66
            z = time.time()
66
 
            template.expand_into(response, **vals)
67
 
            self.log.info('Rendering %s: %r secs' % (
68
 
                self.__class__.__name__, time.time() - z,))
 
67
            class W:
 
68
                def __init__(self):
 
69
                    self.bytes = 0
 
70
                def write(self, data):
 
71
                    self.bytes += len(data)
 
72
                    writer(data)
 
73
            w = W()
 
74
            template.expand_into(w, **vals)
 
75
            self.log.info('Rendering %s: %r secs, %s bytes' % (
 
76
                self.__class__.__name__, time.time() - z, w.bytes))
69
77
        finally:
70
78
            h._branch.unlock()
71
79