Show More
@@ -182,20 +182,20 b' class hgweb(object):' | |||||
182 | content = getattr(webcommands, cmd)(self, req, tmpl) |
|
182 | content = getattr(webcommands, cmd)(self, req, tmpl) | |
183 | req.respond(HTTP_OK, ctype) |
|
183 | req.respond(HTTP_OK, ctype) | |
184 |
|
184 | |||
185 |
return |
|
185 | return content | |
186 |
|
186 | |||
187 | except revlog.LookupError, err: |
|
187 | except revlog.LookupError, err: | |
188 | req.respond(HTTP_NOT_FOUND, ctype) |
|
188 | req.respond(HTTP_NOT_FOUND, ctype) | |
189 | msg = str(err) |
|
189 | msg = str(err) | |
190 | if 'manifest' not in msg: |
|
190 | if 'manifest' not in msg: | |
191 | msg = 'revision not found: %s' % err.name |
|
191 | msg = 'revision not found: %s' % err.name | |
192 |
return |
|
192 | return tmpl('error', error=msg) | |
193 | except (RepoError, revlog.RevlogError), inst: |
|
193 | except (RepoError, revlog.RevlogError), inst: | |
194 | req.respond(HTTP_SERVER_ERROR, ctype) |
|
194 | req.respond(HTTP_SERVER_ERROR, ctype) | |
195 |
return |
|
195 | return tmpl('error', error=str(inst)) | |
196 | except ErrorResponse, inst: |
|
196 | except ErrorResponse, inst: | |
197 | req.respond(inst.code, ctype) |
|
197 | req.respond(inst.code, ctype) | |
198 |
return |
|
198 | return tmpl('error', error=inst.message) | |
199 |
|
199 | |||
200 | def templater(self, req): |
|
200 | def templater(self, req): | |
201 |
|
201 |
@@ -116,7 +116,7 b' class hgwebdir(object):' | |||||
116 | # top-level index |
|
116 | # top-level index | |
117 | elif not virtual: |
|
117 | elif not virtual: | |
118 | req.respond(HTTP_OK, ctype) |
|
118 | req.respond(HTTP_OK, ctype) | |
119 |
return |
|
119 | return self.makeindex(req, tmpl) | |
120 |
|
120 | |||
121 | # nested indexes and hgwebs |
|
121 | # nested indexes and hgwebs | |
122 |
|
122 | |||
@@ -138,7 +138,7 b' class hgwebdir(object):' | |||||
138 | subdir = virtual + '/' |
|
138 | subdir = virtual + '/' | |
139 | if [r for r in repos if r.startswith(subdir)]: |
|
139 | if [r for r in repos if r.startswith(subdir)]: | |
140 | req.respond(HTTP_OK, ctype) |
|
140 | req.respond(HTTP_OK, ctype) | |
141 |
return |
|
141 | return self.makeindex(req, tmpl, subdir) | |
142 |
|
142 | |||
143 | up = virtual.rfind('/') |
|
143 | up = virtual.rfind('/') | |
144 | if up < 0: |
|
144 | if up < 0: | |
@@ -147,11 +147,11 b' class hgwebdir(object):' | |||||
147 |
|
147 | |||
148 | # prefixes not found |
|
148 | # prefixes not found | |
149 | req.respond(HTTP_NOT_FOUND, ctype) |
|
149 | req.respond(HTTP_NOT_FOUND, ctype) | |
150 |
return |
|
150 | return tmpl("notfound", repo=virtual) | |
151 |
|
151 | |||
152 | except ErrorResponse, err: |
|
152 | except ErrorResponse, err: | |
153 | req.respond(err.code, ctype) |
|
153 | req.respond(err.code, ctype) | |
154 |
return |
|
154 | return tmpl('error', error=err.message or '') | |
155 | finally: |
|
155 | finally: | |
156 | tmpl = None |
|
156 | tmpl = None | |
157 |
|
157 |
@@ -44,7 +44,8 b' class templater(object):' | |||||
44 | template_re = re.compile(r"(?:(?:#(?=[\w\|%]+#))|(?:{(?=[\w\|%]+})))" |
|
44 | template_re = re.compile(r"(?:(?:#(?=[\w\|%]+#))|(?:{(?=[\w\|%]+})))" | |
45 | r"(\w+)(?:(?:%(\w+))|((?:\|\w+)*))[#}]") |
|
45 | r"(\w+)(?:(?:%(\w+))|((?:\|\w+)*))[#}]") | |
46 |
|
46 | |||
47 |
def __init__(self, mapfile, filters={}, defaults={}, cache={} |
|
47 | def __init__(self, mapfile, filters={}, defaults={}, cache={}, | |
|
48 | minchunk=1024, maxchunk=65536): | |||
48 | '''set up template engine. |
|
49 | '''set up template engine. | |
49 | mapfile is name of file to read map definitions from. |
|
50 | mapfile is name of file to read map definitions from. | |
50 | filters is dict of functions. each transforms a value into another. |
|
51 | filters is dict of functions. each transforms a value into another. | |
@@ -55,6 +56,7 b' class templater(object):' | |||||
55 | self.base = (mapfile and os.path.dirname(mapfile)) or '' |
|
56 | self.base = (mapfile and os.path.dirname(mapfile)) or '' | |
56 | self.filters = filters |
|
57 | self.filters = filters | |
57 | self.defaults = defaults |
|
58 | self.defaults = defaults | |
|
59 | self.minchunk, self.maxchunk = minchunk, maxchunk | |||
58 |
|
60 | |||
59 | if not mapfile: |
|
61 | if not mapfile: | |
60 | return |
|
62 | return | |
@@ -130,6 +132,13 b' class templater(object):' | |||||
130 | yield v |
|
132 | yield v | |
131 |
|
133 | |||
132 | def __call__(self, t, **map): |
|
134 | def __call__(self, t, **map): | |
|
135 | stream = self.expand(t, **map) | |||
|
136 | if self.minchunk: | |||
|
137 | stream = util.increasingchunks(stream, min=self.minchunk, | |||
|
138 | max=self.maxchunk) | |||
|
139 | return stream | |||
|
140 | ||||
|
141 | def expand(self, t, **map): | |||
133 | '''Perform expansion. t is name of map element to expand. map contains |
|
142 | '''Perform expansion. t is name of map element to expand. map contains | |
134 | added elements for use during expansion. Is a generator.''' |
|
143 | added elements for use during expansion. Is a generator.''' | |
135 | tmpl = self._template(t) |
|
144 | tmpl = self._template(t) |
@@ -290,6 +290,37 b' def sort(l):' | |||||
290 | l.sort() |
|
290 | l.sort() | |
291 | return l |
|
291 | return l | |
292 |
|
292 | |||
|
293 | def increasingchunks(source, min=1024, max=65536): | |||
|
294 | '''return no less than min bytes per chunk while data remains, | |||
|
295 | doubling min after each chunk until it reaches max''' | |||
|
296 | def log2(x): | |||
|
297 | if not x: | |||
|
298 | return 0 | |||
|
299 | i = 0 | |||
|
300 | while x: | |||
|
301 | x >>= 1 | |||
|
302 | i += 1 | |||
|
303 | return i - 1 | |||
|
304 | ||||
|
305 | buf = [] | |||
|
306 | blen = 0 | |||
|
307 | for chunk in source: | |||
|
308 | buf.append(chunk) | |||
|
309 | blen += len(chunk) | |||
|
310 | if blen >= min: | |||
|
311 | if min < max: | |||
|
312 | min = min << 1 | |||
|
313 | nmin = 1 << log2(blen) | |||
|
314 | if nmin > min: | |||
|
315 | min = nmin | |||
|
316 | if min > max: | |||
|
317 | min = max | |||
|
318 | yield ''.join(buf) | |||
|
319 | blen = 0 | |||
|
320 | buf = [] | |||
|
321 | if buf: | |||
|
322 | yield ''.join(buf) | |||
|
323 | ||||
293 | class Abort(Exception): |
|
324 | class Abort(Exception): | |
294 | """Raised if a command needs to print an error and exit.""" |
|
325 | """Raised if a command needs to print an error and exit.""" | |
295 |
|
326 |
General Comments 0
You need to be logged in to leave comments.
Login now