Mercurial > public > mercurial-scm > hg
comparison mercurial/hgweb/hgwebdir_mod.py @ 6785:4879468fa28f
hgweb: return content iterator instead of using write() callable
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Sun, 29 Jun 2008 22:36:18 +0200 |
parents | f67d1468ac50 |
children | 943f066c0d58 |
comparison
equal
deleted
inserted
replaced
6784:18c429ea3a0e | 6785:4879468fa28f |
---|---|
68 import mercurial.hgweb.wsgicgi as wsgicgi | 68 import mercurial.hgweb.wsgicgi as wsgicgi |
69 wsgicgi.launch(self) | 69 wsgicgi.launch(self) |
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 |
78 try: | 77 try: |
79 try: | 78 try: |
88 static = os.path.join(templater.templatepath(), 'static') | 87 static = os.path.join(templater.templatepath(), 'static') |
89 if virtual.startswith('static/'): | 88 if virtual.startswith('static/'): |
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 |
104 repos = dict(self.repos) | 101 repos = dict(self.repos) |
105 while virtual: | 102 while virtual: |
106 real = repos.get(virtual) | 103 real = repos.get(virtual) |
107 if real: | 104 if real: |
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) |
116 except RepoError, inst: | 112 except RepoError, inst: |
117 raise ErrorResponse(HTTP_SERVER_ERROR, str(inst)) | 113 raise ErrorResponse(HTTP_SERVER_ERROR, str(inst)) |
118 | 114 |
119 # browse subdirectories | 115 # browse subdirectories |
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: |
128 break | 123 break |
129 virtual = virtual[:up] | 124 virtual = virtual[:up] |
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 |
141 def makeindex(self, req, tmpl, subdir=""): | 136 def makeindex(self, req, tmpl, subdir=""): |
142 | 137 |