##// END OF EJS Templates
hgweb: return content iterator instead of using write() callable
Dirkjan Ochtman -
r6785:4879468f default
parent child Browse files
Show More
@@ -169,20 +169,20 b' class hgweb(object):'
169
169
170 req.write(content)
170 req.write(content)
171 del tmpl
171 del tmpl
172 return req
172 return ''.join(content),
173
173
174 except revlog.LookupError, err:
174 except revlog.LookupError, err:
175 req.respond(HTTP_NOT_FOUND, ctype)
175 req.respond(HTTP_NOT_FOUND, ctype)
176 msg = str(err)
176 msg = str(err)
177 if 'manifest' not in msg:
177 if 'manifest' not in msg:
178 msg = 'revision not found: %s' % err.name
178 msg = 'revision not found: %s' % err.name
179 req.write(tmpl('error', error=msg))
179 return ''.join(tmpl('error', error=msg)),
180 except (RepoError, revlog.RevlogError), inst:
180 except (RepoError, revlog.RevlogError), inst:
181 req.respond(HTTP_SERVER_ERROR, ctype)
181 req.respond(HTTP_SERVER_ERROR, ctype)
182 req.write(tmpl('error', error=str(inst)))
182 return ''.join(tmpl('error', error=str(inst))),
183 except ErrorResponse, inst:
183 except ErrorResponse, inst:
184 req.respond(inst.code, ctype)
184 req.respond(inst.code, ctype)
185 req.write(tmpl('error', error=inst.message))
185 return ''.join(tmpl('error', error=inst.message)),
186
186
187 def templater(self, req):
187 def templater(self, req):
188
188
@@ -70,8 +70,7 b' class hgwebdir(object):'
70
70
71 def __call__(self, env, respond):
71 def __call__(self, env, respond):
72 req = wsgirequest(env, respond)
72 req = wsgirequest(env, respond)
73 self.run_wsgi(req)
73 return self.run_wsgi(req)
74 return req
75
74
76 def run_wsgi(self, req):
75 def run_wsgi(self, req):
77
76
@@ -90,14 +89,12 b' class hgwebdir(object):'
90 fname = virtual[7:]
89 fname = virtual[7:]
91 else:
90 else:
92 fname = req.form['static'][0]
91 fname = req.form['static'][0]
93 req.write(staticfile(static, fname, req))
92 return staticfile(static, fname, req),
94 return
95
93
96 # top-level index
94 # top-level index
97 elif not virtual:
95 elif not virtual:
98 req.respond(HTTP_OK, ctype)
96 req.respond(HTTP_OK, ctype)
99 req.write(self.makeindex(req, tmpl))
97 return ''.join(self.makeindex(req, tmpl)),
100 return
101
98
102 # nested indexes and hgwebs
99 # nested indexes and hgwebs
103
100
@@ -108,8 +105,7 b' class hgwebdir(object):'
108 req.env['REPO_NAME'] = virtual
105 req.env['REPO_NAME'] = virtual
109 try:
106 try:
110 repo = hg.repository(self.parentui, real)
107 repo = hg.repository(self.parentui, real)
111 hgweb(repo).run_wsgi(req)
108 return hgweb(repo).run_wsgi(req)
112 return
113 except IOError, inst:
109 except IOError, inst:
114 msg = inst.strerror
110 msg = inst.strerror
115 raise ErrorResponse(HTTP_SERVER_ERROR, msg)
111 raise ErrorResponse(HTTP_SERVER_ERROR, msg)
@@ -120,8 +116,7 b' class hgwebdir(object):'
120 subdir = virtual + '/'
116 subdir = virtual + '/'
121 if [r for r in repos if r.startswith(subdir)]:
117 if [r for r in repos if r.startswith(subdir)]:
122 req.respond(HTTP_OK, ctype)
118 req.respond(HTTP_OK, ctype)
123 req.write(self.makeindex(req, tmpl, subdir))
119 return ''.join(self.makeindex(req, tmpl, subdir)),
124 return
125
120
126 up = virtual.rfind('/')
121 up = virtual.rfind('/')
127 if up < 0:
122 if up < 0:
@@ -130,11 +125,11 b' class hgwebdir(object):'
130
125
131 # prefixes not found
126 # prefixes not found
132 req.respond(HTTP_NOT_FOUND, ctype)
127 req.respond(HTTP_NOT_FOUND, ctype)
133 req.write(tmpl("notfound", repo=virtual))
128 return ''.join(tmpl("notfound", repo=virtual)),
134
129
135 except ErrorResponse, err:
130 except ErrorResponse, err:
136 req.respond(err.code, ctype)
131 req.respond(err.code, ctype)
137 req.write(tmpl('error', error=err.message or ''))
132 return ''.join(tmpl('error', error=err.message or '')),
138 finally:
133 finally:
139 tmpl = None
134 tmpl = None
140
135
@@ -43,15 +43,17 b' env = {'
43
43
44 output = StringIO()
44 output = StringIO()
45 env['QUERY_STRING'] = 'style=atom'
45 env['QUERY_STRING'] = 'style=atom'
46 hgweb('.', name = 'repo')(env, startrsp)
46 content = hgweb('.', name = 'repo')(env, startrsp)
47 print output.getvalue()
47 sys.stdout.write(output.getvalue())
48 sys.stdout.write(''.join(content))
48 print '---- ERRORS'
49 print '---- ERRORS'
49 print errors.getvalue()
50 print errors.getvalue()
50
51
51 output = StringIO()
52 output = StringIO()
52 env['QUERY_STRING'] = 'style=raw'
53 env['QUERY_STRING'] = 'style=raw'
53 hgwebdir({'repo': '.'})(env, startrsp)
54 content = hgwebdir({'repo': '.'})(env, startrsp)
54 print output.getvalue()
55 sys.stdout.write(output.getvalue())
56 sys.stdout.write(''.join(content))
55 print '---- ERRORS'
57 print '---- ERRORS'
56 print errors.getvalue()
58 print errors.getvalue()
57 EOF
59 EOF
@@ -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
@@ -44,32 +44,36 b' env = {'
44 output = StringIO()
44 output = StringIO()
45 env['PATH_INFO'] = '/'
45 env['PATH_INFO'] = '/'
46 env['QUERY_STRING'] = 'style=atom'
46 env['QUERY_STRING'] = 'style=atom'
47 hgweb('.', name = 'repo')(env, startrsp)
47 content = hgweb('.', name = 'repo')(env, startrsp)
48 print output.getvalue()
48 sys.stdout.write(output.getvalue())
49 sys.stdout.write(''.join(content))
49 print '---- ERRORS'
50 print '---- ERRORS'
50 print errors.getvalue()
51 print errors.getvalue()
51
52
52 output = StringIO()
53 output = StringIO()
53 env['PATH_INFO'] = '/file/tip/'
54 env['PATH_INFO'] = '/file/tip/'
54 env['QUERY_STRING'] = 'style=raw'
55 env['QUERY_STRING'] = 'style=raw'
55 hgweb('.', name = 'repo')(env, startrsp)
56 content = hgweb('.', name = 'repo')(env, startrsp)
56 print output.getvalue()
57 sys.stdout.write(output.getvalue())
58 sys.stdout.write(''.join(content))
57 print '---- ERRORS'
59 print '---- ERRORS'
58 print errors.getvalue()
60 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 content = hgwebdir({'repo': '.'})(env, startrsp)
64 print output.getvalue()
66 sys.stdout.write(output.getvalue())
67 sys.stdout.write(''.join(content))
65 print '---- ERRORS'
68 print '---- ERRORS'
66 print errors.getvalue()
69 print errors.getvalue()
67
70
68 output = StringIO()
71 output = StringIO()
69 env['PATH_INFO'] = '/repo/file/tip/'
72 env['PATH_INFO'] = '/repo/file/tip/'
70 env['QUERY_STRING'] = 'style=raw'
73 env['QUERY_STRING'] = 'style=raw'
71 hgwebdir({'repo': '.'})(env, startrsp)
74 content = hgwebdir({'repo': '.'})(env, startrsp)
72 print output.getvalue()
75 sys.stdout.write(output.getvalue())
76 sys.stdout.write(''.join(content))
73 print '---- ERRORS'
77 print '---- ERRORS'
74 print errors.getvalue()
78 print errors.getvalue()
75 EOF
79 EOF
@@ -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