Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/hgweb/common.py @ 7288:9c399c53469d
Allow per-file shadowing of static directory in templatepath
author | Brendan Cully <brendan@kublai.com> |
---|---|
date | Tue, 28 Oct 2008 22:24:17 -0700 |
parents | 125c8fedcbe0 |
children | bd522d09d5e3 |
comparison
equal
deleted
inserted
replaced
7287:6e9fe4ff9c54 | 7288:9c399c53469d |
---|---|
51 Content-Type is guessed using the mimetypes module. | 51 Content-Type is guessed using the mimetypes module. |
52 Return an empty string if fname is illegal or file not found. | 52 Return an empty string if fname is illegal or file not found. |
53 | 53 |
54 """ | 54 """ |
55 parts = fname.split('/') | 55 parts = fname.split('/') |
56 path = directory | |
57 for part in parts: | 56 for part in parts: |
58 if (part in ('', os.curdir, os.pardir) or | 57 if (part in ('', os.curdir, os.pardir) or |
59 os.sep in part or os.altsep is not None and os.altsep in part): | 58 os.sep in part or os.altsep is not None and os.altsep in part): |
60 return "" | 59 return "" |
61 path = os.path.join(path, part) | 60 fpath = os.path.join(*parts) |
61 if isinstance(directory, str): | |
62 directory = [directory] | |
63 for d in directory: | |
64 path = os.path.join(d, fpath) | |
65 if os.path.exists(path): | |
66 break | |
62 try: | 67 try: |
63 os.stat(path) | 68 os.stat(path) |
64 ct = mimetypes.guess_type(path)[0] or "text/plain" | 69 ct = mimetypes.guess_type(path)[0] or "text/plain" |
65 req.respond(HTTP_OK, ct, length = os.path.getsize(path)) | 70 req.respond(HTTP_OK, ct, length = os.path.getsize(path)) |
66 return file(path, 'rb').read() | 71 return file(path, 'rb').read() |