Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/common.py @ 18645:76ff3a715cf2
hgweb: simplify internal staticfile return codes
author | Mads Kiilerich <mads@kiilerich.com> |
---|---|
date | Sun, 10 Feb 2013 18:24:29 +0100 |
parents | e33b9b92a200 |
children | 7d31f2e42a8a |
comparison
equal
deleted
inserted
replaced
18644:3e92772d5383 | 18645:76ff3a715cf2 |
---|---|
127 """ | 127 """ |
128 parts = fname.split('/') | 128 parts = fname.split('/') |
129 for part in parts: | 129 for part in parts: |
130 if (part in ('', os.curdir, os.pardir) or | 130 if (part in ('', os.curdir, os.pardir) or |
131 os.sep in part or os.altsep is not None and os.altsep in part): | 131 os.sep in part or os.altsep is not None and os.altsep in part): |
132 return "" | 132 return |
133 fpath = os.path.join(*parts) | 133 fpath = os.path.join(*parts) |
134 if isinstance(directory, str): | 134 if isinstance(directory, str): |
135 directory = [directory] | 135 directory = [directory] |
136 for d in directory: | 136 for d in directory: |
137 path = os.path.join(d, fpath) | 137 path = os.path.join(d, fpath) |
142 ct = mimetypes.guess_type(path)[0] or "text/plain" | 142 ct = mimetypes.guess_type(path)[0] or "text/plain" |
143 fp = open(path, 'rb') | 143 fp = open(path, 'rb') |
144 data = fp.read() | 144 data = fp.read() |
145 fp.close() | 145 fp.close() |
146 req.respond(HTTP_OK, ct, body=data) | 146 req.respond(HTTP_OK, ct, body=data) |
147 return "" | |
148 except TypeError: | 147 except TypeError: |
149 raise ErrorResponse(HTTP_SERVER_ERROR, 'illegal filename') | 148 raise ErrorResponse(HTTP_SERVER_ERROR, 'illegal filename') |
150 except OSError, err: | 149 except OSError, err: |
151 if err.errno == errno.ENOENT: | 150 if err.errno == errno.ENOENT: |
152 raise ErrorResponse(HTTP_NOT_FOUND) | 151 raise ErrorResponse(HTTP_NOT_FOUND) |