##// END OF EJS Templates
hgweb: return content iterator instead of using write() callable...
Dirkjan Ochtman -
r6945:2cfdabe2 default
parent child Browse files
Show More
@@ -174,24 +174,20 b' class hgweb(object):'
174 content = getattr(webcommands, cmd)(self, req, tmpl)
174 content = getattr(webcommands, cmd)(self, req, tmpl)
175 req.respond(HTTP_OK, ctype)
175 req.respond(HTTP_OK, ctype)
176
176
177 req.write(content)
177 return ''.join(content),
178 return []
179
178
180 except revlog.LookupError, err:
179 except revlog.LookupError, err:
181 req.respond(HTTP_NOT_FOUND, ctype)
180 req.respond(HTTP_NOT_FOUND, ctype)
182 msg = str(err)
181 msg = str(err)
183 if 'manifest' not in msg:
182 if 'manifest' not in msg:
184 msg = 'revision not found: %s' % err.name
183 msg = 'revision not found: %s' % err.name
185 req.write(tmpl('error', error=msg))
184 return ''.join(tmpl('error', error=msg)),
186 return []
187 except (RepoError, revlog.RevlogError), inst:
185 except (RepoError, revlog.RevlogError), inst:
188 req.respond(HTTP_SERVER_ERROR, ctype)
186 req.respond(HTTP_SERVER_ERROR, ctype)
189 req.write(tmpl('error', error=str(inst)))
187 return ''.join(tmpl('error', error=str(inst))),
190 return []
191 except ErrorResponse, inst:
188 except ErrorResponse, inst:
192 req.respond(inst.code, ctype)
189 req.respond(inst.code, ctype)
193 req.write(tmpl('error', error=inst.message))
190 return ''.join(tmpl('error', error=inst.message)),
194 return []
195
191
196 def templater(self, req):
192 def templater(self, req):
197
193
@@ -89,14 +89,12 b' class hgwebdir(object):'
89 fname = virtual[7:]
89 fname = virtual[7:]
90 else:
90 else:
91 fname = req.form['static'][0]
91 fname = req.form['static'][0]
92 req.write(staticfile(static, fname, req))
92 return staticfile(static, fname, req)
93 return []
94
93
95 # top-level index
94 # top-level index
96 elif not virtual:
95 elif not virtual:
97 req.respond(HTTP_OK, ctype)
96 req.respond(HTTP_OK, ctype)
98 req.write(self.makeindex(req, tmpl))
97 return ''.join(self.makeindex(req, tmpl)),
99 return []
100
98
101 # nested indexes and hgwebs
99 # nested indexes and hgwebs
102
100
@@ -118,8 +116,7 b' class hgwebdir(object):'
118 subdir = virtual + '/'
116 subdir = virtual + '/'
119 if [r for r in repos if r.startswith(subdir)]:
117 if [r for r in repos if r.startswith(subdir)]:
120 req.respond(HTTP_OK, ctype)
118 req.respond(HTTP_OK, ctype)
121 req.write(self.makeindex(req, tmpl, subdir))
119 return ''.join(self.makeindex(req, tmpl, subdir)),
122 return []
123
120
124 up = virtual.rfind('/')
121 up = virtual.rfind('/')
125 if up < 0:
122 if up < 0:
@@ -128,13 +125,11 b' class hgwebdir(object):'
128
125
129 # prefixes not found
126 # prefixes not found
130 req.respond(HTTP_NOT_FOUND, ctype)
127 req.respond(HTTP_NOT_FOUND, ctype)
131 req.write(tmpl("notfound", repo=virtual))
128 return ''.join(tmpl("notfound", repo=virtual)),
132 return []
133
129
134 except ErrorResponse, err:
130 except ErrorResponse, err:
135 req.respond(err.code, ctype)
131 req.respond(err.code, ctype)
136 req.write(tmpl('error', error=err.message or ''))
132 return ''.join(tmpl('error', error=err.message or '')),
137 return []
138 finally:
133 finally:
139 tmpl = None
134 tmpl = None
140
135
@@ -41,19 +41,20 b' env = {'
41 'SERVER_PROTOCOL': 'HTTP/1.0'
41 'SERVER_PROTOCOL': 'HTTP/1.0'
42 }
42 }
43
43
44 def process(app):
45 content = app(env, startrsp)
46 sys.stdout.write(output.getvalue())
47 sys.stdout.write(''.join(content))
48 print '---- ERRORS'
49 print errors.getvalue()
50
44 output = StringIO()
51 output = StringIO()
45 env['QUERY_STRING'] = 'style=atom'
52 env['QUERY_STRING'] = 'style=atom'
46 hgweb('.', name = 'repo')(env, startrsp)
53 process(hgweb('.', name='repo'))
47 print output.getvalue()
48 print '---- ERRORS'
49 print errors.getvalue()
50
54
51 output = StringIO()
55 output = StringIO()
52 env['QUERY_STRING'] = 'style=raw'
56 env['QUERY_STRING'] = 'style=raw'
53 hgwebdir({'repo': '.'})(env, startrsp)
57 process(hgwebdir({'repo': '.'}))
54 print output.getvalue()
55 print '---- ERRORS'
56 print errors.getvalue()
57 EOF
58 EOF
58
59
59 python request.py | sed "s/http:\/\/127\.0\.0\.1:[0-9]*\//http:\/\/127.0.0.1\//"
60 python request.py | sed "s/http:\/\/127\.0\.0\.1:[0-9]*\//http:\/\/127.0.0.1\//"
@@ -35,7 +35,6 b' 200 Script output follows'
35 </entry>
35 </entry>
36
36
37 </feed>
37 </feed>
38
39 ---- ERRORS
38 ---- ERRORS
40
39
41 ---- HEADERS
40 ---- HEADERS
@@ -45,6 +44,5 b' 200 Script output follows'
45
44
46 repo/
45 repo/
47
46
48
49 ---- ERRORS
47 ---- ERRORS
50
48
@@ -41,37 +41,33 b' env = {'
41 'SERVER_PROTOCOL': 'HTTP/1.0'
41 'SERVER_PROTOCOL': 'HTTP/1.0'
42 }
42 }
43
43
44 def process(app):
45 content = app(env, startrsp)
46 sys.stdout.write(output.getvalue())
47 sys.stdout.write(''.join(content))
48 print '---- ERRORS'
49 print errors.getvalue()
50
51
44 output = StringIO()
52 output = StringIO()
45 env['PATH_INFO'] = '/'
53 env['PATH_INFO'] = '/'
46 env['QUERY_STRING'] = 'style=atom'
54 env['QUERY_STRING'] = 'style=atom'
47 hgweb('.', name = 'repo')(env, startrsp)
55 process(hgweb('.', name = 'repo'))
48 print output.getvalue()
49 print '---- ERRORS'
50 print errors.getvalue()
51
56
52 output = StringIO()
57 output = StringIO()
53 env['PATH_INFO'] = '/file/tip/'
58 env['PATH_INFO'] = '/file/tip/'
54 env['QUERY_STRING'] = 'style=raw'
59 env['QUERY_STRING'] = 'style=raw'
55 hgweb('.', name = 'repo')(env, startrsp)
60 process(hgweb('.', name = 'repo'))
56 print output.getvalue()
57 print '---- ERRORS'
58 print errors.getvalue()
59
61
60 output = StringIO()
62 output = StringIO()
61 env['PATH_INFO'] = '/'
63 env['PATH_INFO'] = '/'
62 env['QUERY_STRING'] = 'style=raw'
64 env['QUERY_STRING'] = 'style=raw'
63 hgwebdir({'repo': '.'})(env, startrsp)
65 process(hgwebdir({'repo': '.'}))
64 print output.getvalue()
65 print '---- ERRORS'
66 print errors.getvalue()
67
66
68 output = StringIO()
67 output = StringIO()
69 env['PATH_INFO'] = '/repo/file/tip/'
68 env['PATH_INFO'] = '/repo/file/tip/'
70 env['QUERY_STRING'] = 'style=raw'
69 env['QUERY_STRING'] = 'style=raw'
71 hgwebdir({'repo': '.'})(env, startrsp)
70 process(hgwebdir({'repo': '.'}))
72 print output.getvalue()
73 print '---- ERRORS'
74 print errors.getvalue()
75 EOF
71 EOF
76
72
77 python request.py | sed "s/http:\/\/127\.0\.0\.1:[0-9]*\//http:\/\/127.0.0.1\//"
73 python request.py | sed "s/http:\/\/127\.0\.0\.1:[0-9]*\//http:\/\/127.0.0.1\//"
@@ -35,6 +35,24 b' 200 Script output follows'
35 </entry>
35 </entry>
36
36
37 </feed>
37 </feed>
38 ---- ERRORS
39
40 ---- HEADERS
41 200 Script output follows
42 ---- DATA
43 [('Content-Type', 'text/plain; charset=ascii')]
44
45 -rw-r--r-- 4 bar
46
47
48 ---- ERRORS
49
50 ---- HEADERS
51 200 Script output follows
52 ---- DATA
53 [('Content-Type', 'text/plain; charset=ascii')]
54
55 /repo/
38
56
39 ---- ERRORS
57 ---- ERRORS
40
58
@@ -46,27 +64,5 b' 200 Script output follows'
46 -rw-r--r-- 4 bar
64 -rw-r--r-- 4 bar
47
65
48
66
49
50 ---- ERRORS
67 ---- ERRORS
51
68
52 ---- HEADERS
53 200 Script output follows
54 ---- DATA
55 [('Content-Type', 'text/plain; charset=ascii')]
56
57 /repo/
58
59
60 ---- ERRORS
61
62 ---- HEADERS
63 200 Script output follows
64 ---- DATA
65 [('Content-Type', 'text/plain; charset=ascii')]
66
67 -rw-r--r-- 4 bar
68
69
70
71 ---- ERRORS
72
General Comments 0
You need to be logged in to leave comments. Login now