Changeset 896
- Timestamp:
- 12/29/05 17:03:46
- Files:
-
- trunk/cherrypy/filters/staticfilter.py (modified) (2 diffs)
- trunk/cherrypy/lib/cptools.py (modified) (1 diff)
- trunk/cherrypy/test/test_static_filter.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/cherrypy/filters/staticfilter.py
r895 r896 34 34 extraPath = extraPath.lstrip(r"\/") 35 35 extraPath = urllib.unquote(extraPath) 36 # If extraPath is "", filename will end in a slash 36 37 filename = os.path.join(staticDir, extraPath) 37 38 38 39 # If filename is relative, make absolute using "root". 40 # Note that, if "root" isn't defined, we still may send 41 # a relative path to serveFile. 39 42 if not os.path.isabs(filename): 40 43 root = config.get('static_filter.root', '').rstrip(r"\/") … … 46 49 request.execute_main = False 47 50 except cherrypy.NotFound: 48 # if we didn't find the static file, continue 49 # handling the request. we might find a dynamic 50 # handler instead. 51 pass 51 # If we didn't find the static file, continue handling the 52 # request. We might find a dynamic handler instead. 53 54 # But first check for an index file if a folder was requested. 55 if filename[-1:] in ("/", "\\"): 56 idx = config.get('static_filter.index', '') 57 if idx: 58 try: 59 cptools.serveFile(os.path.join(filename, idx)) 60 request.execute_main = False 61 except cherrypy.NotFound: 62 pass 52 63 trunk/cherrypy/lib/cptools.py
r856 r896 93 93 if cherrypy.config.get('server.log_file_not_found', False): 94 94 cherrypy.log(" NOT FOUND file: %s" % path, "DEBUG") 95 raise cherrypy.NotFound() 96 97 if os.path.isdir(path): 98 # Let the caller deal with it as they like. 95 99 raise cherrypy.NotFound() 96 100 trunk/cherrypy/test/test_static_filter.py
r895 r896 2 2 test.prefer_parent_path() 3 3 4 import os 5 curdir = os.path.join(os.getcwd(), os.path.dirname(__file__)) 6 4 7 import cherrypy 5 import os8 from cherrypy.lib import cptools 6 9 7 10 8 class Root: pass 11 class Root: 12 pass 9 13 10 14 class Static: 15 16 def index(self): 17 return 'You want the Baron? You can have the Baron!' 18 index.exposed = True 11 19 12 20 def dynamic(self): … … 34 42 '/docroot': { 35 43 'static_filter.on': True, 36 'static_filter.root': os.path.join(os.getcwd(), os.path.dirname(__file__)),44 'static_filter.root': curdir, 37 45 'static_filter.dir': 'static', 46 'static_filter.index': 'index.html', 38 47 }, 39 48 }) … … 71 80 self.assertMatchesBody('^Dummy stylesheet') 72 81 73 # Check a directory (should currently fail--no provision for it)74 ignore = helper.webtest.ignored_exceptions75 ignore.append(IOError)76 try:77 self.getPage("/static/")78 self.assertErrorPage(500)79 finally:80 ignore.pop()81 82 82 # Test that NotFound will then try dynamic handlers (see [878]). 83 83 self.getPage("/static/dynamic") 84 84 self.assertBody("This is a DYNAMIC page") 85 86 # Check a directory via fall-through to dynamic handler. 87 self.getPage("/static/") 88 self.assertStatus('200 OK') 89 self.assertHeader('Content-Type', 'text/html') 90 self.assertBody('You want the Baron? You can have the Baron!') 91 92 # Check a directory via "static_filter.index". 93 self.getPage("/docroot/") 94 self.assertStatus('200 OK') 95 self.assertHeader('Content-Type', 'text/html') 96 self.assertBody('Hello, world\r\n') 97 # The same page should be returned even if redirected. 98 self.getPage("/docroot") 99 self.assertStatus('200 OK') 100 self.assertHeader('Content-Type', 'text/html') 101 self.assertBody('Hello, world\r\n') 85 102 86 103

