On Friday 14 December 2001 06:55, Geoffrey Talvola wrote:
> At 04:04 PM 12/13/01 -0800, Tavis Rudd wrote:
> >Here's a patch to implement ExtensionsToServe, FilesToHide, and
> >FilesToServe. They work as I documented yesterday, and will also
> > need to be added to the default config file.
>
> Excellent!  I'll check in the patch to CVS sometime in the next
> couple of days, unless Chuck gets to it before I do.

Before you do ... here's an update of that patch that also implements 
'ExtensionCascadeOrder', which is a list of extensions to cascade 
through when there are multiple files with different extensions found 
for a requested basename.  The first match from the list 
'ExtensionCascadeOrder' is used.  If no match is found a 404 error is 
returned.  The setting 'UseCascadingExtensions' turns the behaviour 
on and off.  The patch includes the changes to the default 
Configs/Application.config file.

Tavis
Index: Application.py
===================================================================
RCS file: /cvsroot/webware/Webware/WebKit/Application.py,v
retrieving revision 1.124
diff -r1.124 Application.py
16a17,18
> from fnmatch import fnmatch
> 
249a252,259
> 			'ExtensionsToServe':   None,
> 			'UseCascadingExtensions':1,
> 			'ExtensionCascadeOrder':['.py','.psp','.html',],
> 			
> 
> 			'FilesToHide': ['.*','*~', '*bak', '*.tmpl', '*.config' ],
> 			'FilesToServe': None,
> 			
348c358,373
< 				self.handleGoodURL(transaction)
---
> 				validFile = 1
> 				baseName = os.path.split(ssPath)[1]
> 				for patternToHide in self.setting('FilesToHide'):
> 					if fnmatch(baseName, patternToHide):
> 						validFile = 0
> 
> 				patternsToServe = self.setting('FilesToServe')
> 				if patternsToServe:
> 					validFile = 0
> 					for patternToServe in self.setting('FilesToServe'):
> 						if fnmatch(baseName, patternToServe):
> 							validFile = 1
> 				if not validFile:
> 					self.handleBadURL(transaction)
> 				else:
> 					self.handleGoodURL(transaction)
940,943c965,972
< 		'''
< 		Returns a list of all filenames with extensions existing for baseName, but not including extension found in the setting ExtensionsToIgnore. This utility method is used by serverSideInfoForRequest().
< 		Example: '/a/b/c' could yield ['/a/b/c.py', '/a/b/c.html'], but will never yield a '/a/b/c.pyc' filename since .pyc files are ignored.
< 		'''
---
> 		
> 		"""Returns a list of all filenames with extensions existing for
> 		baseName, but not including extension found in the setting
> 		ExtensionsToIgnore. This utility method is used by
> 		serverSideInfoForRequest().  Example: '/a/b/c' could yield
> 		['/a/b/c.py', '/a/b/c.html'], but will never yield a
> 		'/a/b/c.pyc' filename since .pyc files are ignored."""
> 		
947c976,977
< 			if os.path.splitext(filenames[i])[1] in ignoreExts: # @@ 2000-06-22 ce: linear search
---
> 			if os.path.splitext(filenames[i])[1] in ignoreExts:
> 				# @@ 2000-06-22 ce: linear search
949a980,987
> 
> 		extensionsToServe = self.setting('ExtensionsToServe')
> 		if extensionsToServe:
> 			for i in range(len(filenames)):
> 				if os.path.splitext(filenames[i])[1] not in extensionsToServe: 
> 					filenames[i] = None
> 			filenames = filter(None, filenames)
> 		
1103a1142,1153
> 			elif len(filenames) > 1:
> 				foundMatch = False
> 				if self.setting('UseCascadingExtensions'):
> 					for ext in self.setting('ExtensionCascadeOrder'):
> 						if (ssPath + ext) in filenames:
> 							fullPath = ssPath + ext
> 							foundMatch = True
> 							break
> 				if not foundMatch:
> 					print 'WARNING: For %s, did not get precisely 1 filename: %s' %\
> 					      (urlPath, filenames)
> 					return None, None, None
1105c1155,1156
< 				print 'WARNING: For %s, did not get precisely 1 filename: %s' % (urlPath, filenames)
---
> 				print 'WARNING: For %s, did not get precisely 1 filename: %s' % \
> 				      (urlPath, filenames)
1106a1158
> 					
Index: Configs/Application.config
===================================================================
RCS file: /cvsroot/webware/Webware/WebKit/Configs/Application.config,v
retrieving revision 1.38
diff -r1.38 Application.config
4c4
< 	'DirectoryFile':        ['index', 'Main'],
---
> 	'DirectoryFile':        ['index', 'Index','main','Main'],
5a6,10
> 	'ExtensionsToServe':  [], # if specified, only extensions in this list will be used
> 	'UseCascadingExtensions': 1,
> 	'ExtensionCascadeOrder':['.py','.psp','.html'],
> 	'FilesToHide': ['.*','*~', '*bak', '*.tmpl', '*.config' ],
> 	'FilesToServe': [], # if specified, only files matching these patterns will be served

Reply via email to