Skip to content

Commit 944d306

Browse files
author
Alexander Smishlajev
committed
support STATIC_FILES directory in addition to TEMPLATES
1 parent dd4d1ca commit 944d306

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

roundup/cgi/client.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
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 $
22

33
"""WWW request handler (also used in the stand-alone server).
44
"""
@@ -540,15 +540,18 @@ def serve_file(self, designator, dre=re.compile(r'([^\d]+)(\d+)')):
540540
def serve_static_file(self, file):
541541
''' Serve up the file named from the templates dir
542542
'''
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:
552555
raise NotFound, file
553556

554557
# last-modified time

0 commit comments

Comments
 (0)