|
1 | | -# $Id: client.py,v 1.194 2004-11-02 10:04:00 a1s Exp $ |
| 1 | +# $Id: client.py,v 1.195 2004-11-03 09:49:14 a1s Exp $ |
2 | 2 |
|
3 | 3 | """WWW request handler (also used in the stand-alone server). |
4 | 4 | """ |
@@ -540,15 +540,18 @@ def serve_file(self, designator, dre=re.compile(r'([^\d]+)(\d+)')): |
540 | 540 | def serve_static_file(self, file): |
541 | 541 | ''' Serve up the file named from the templates dir |
542 | 542 | ''' |
543 | | - # figure the filename - ensure the load doesn't try to poke |
544 | | - # outside of the static files dir |
545 | | - prefix = getattr(self.instance.config, 'STATIC_FILES', |
546 | | - self.instance.config.TEMPLATES) |
547 | | - |
548 | | - # normalise the prefix and filename for the startswith comparison |
549 | | - prefix = os.path.normpath(prefix) |
550 | | - filename = os.path.normpath(os.path.join(prefix, file)) |
551 | | - if not filename.startswith(prefix): |
| 543 | + # figure the filename - try STATIC_FILES, then TEMPLATES dir |
| 544 | + for dir_option in ('STATIC_FILES', 'TEMPLATES'): |
| 545 | + prefix = self.instance.config[dir_option] |
| 546 | + if not prefix: |
| 547 | + continue |
| 548 | + # ensure the load doesn't try to poke outside |
| 549 | + # of the static files directory |
| 550 | + prefix = os.path.normpath(prefix) |
| 551 | + filename = os.path.normpath(os.path.join(prefix, file)) |
| 552 | + if os.path.isfile(filename) and filename.startswith(prefix): |
| 553 | + break |
| 554 | + else: |
552 | 555 | raise NotFound, file |
553 | 556 |
|
554 | 557 | # last-modified time |
|
0 commit comments