~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/__init__.py

  • Committer: Michael Hudson
  • Date: 2009-01-22 22:14:47 UTC
  • mto: This revision was merged to the branch mainline in revision 262.
  • Revision ID: michael.hudson@canonical.com-20090122221447-0q02kfg2qfe3tfqy
put the line numbers back

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# along with this program; if not, write to the Free Software
18
18
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19
19
 
 
20
import re
20
21
import time
21
22
 
22
23
from paste.request import path_info_pop, parse_querystring
33
34
        self.buf = []
34
35
        self.buflen = 0
35
36
        self.writefunc = writefunc
 
37
        self.bytes_saved = 0
36
38
        self.buf_limit = buf_limit
37
39
 
38
40
    def flush(self):
39
 
        self.writefunc(''.join(self.buf))
 
41
        chunk = ''.join(self.buf)
 
42
        chunk = re.sub(r'\s*\n\s*', '\n', chunk)
 
43
        chunk = re.sub(r'[ \t]+', ' ', chunk)
 
44
        self.bytes_saved += self.buflen - len(chunk)
 
45
        self.writefunc(chunk)
40
46
        self.buf = []
41
47
        self.buflen = 0
42
48
 
78
84
 
79
85
        path = None
80
86
        if len(args) > 1:
81
 
            path = unicode('/'.join(args[1:]), 'utf-8')
 
87
            path = '/'.join(args[1:])
82
88
        self.args = args
83
89
 
84
90
        vals = {
103
109
        template.expand_into(w, **vals)
104
110
        w.flush()
105
111
        self.log.info(
106
 
            'Rendering %s: %r secs, %s bytes' % (
107
 
                self.__class__.__name__, time.time() - z, w.bytes))
 
112
            'Rendering %s: %r secs, %s bytes, %s (%2.1f%%) bytes saved' % (
 
113
                self.__class__.__name__,
 
114
                time.time() - z,
 
115
                w.bytes,
 
116
                w.bytes_saved,
 
117
                100.0*w.bytes_saved/w.bytes))
108
118
        return []
109
119
 
110
120
    def get_revid(self):
111
121
        h = self._history
112
122
        if h is None:
113
123
            return None
114
 
        if len(self.args) > 0 and self.args != ['']:
 
124
        if len(self.args) > 0:
115
125
            return h.fix_revid(self.args[0])
116
126
        else:
117
127
            return h.last_revid