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.  

IMHO,there's far too much coupling in there between the Application 
and Request classes, which makes it harder than it should be to grok, or 
implement new stuff like this.

Tavis


On Thursday 13 December 2001 11:59, Geoffrey Talvola wrote:
> 2 questions:
>
> - Can this be made backward-compatible by also allowing the name
> "ExtensionsToIgnore", perhaps emitting a deprecation warning
> message?
>
> - Now that you've done the work in your experimental version, could
> you adapt it to create a patch for Webware CVS?
>
> At 01:40 PM 12/12/01 -0800, Tavis Rudd wrote:
> >I've just done a little more work on this in the experimental
> > code. Here are the config settings I've implemented and tested so
> > far:
> >
> >DirectoryFiles = ['index','Index','main','Main',
> > 'default','Default',]
> >
> >## these 2 only affect requests with no extension specified
> ># same as before
> >ExtensionsToHide = ['.pyc','.pyo','.py~', '.bak', '.tmpl',
> > '.py_bak'] # only use if a list is given
> >ExtensionsToServe = None
> ># ExtensionsToServe = ['.py','.html']
> >
> >
> ># if multiple files are found for a URI without the ext specified
> ># cascade through this list in sequence till one is found.
> ># 404 if none match
> >UseCascadingExtensions = True
> >ExtensionCascadeOrder = ['.html', '.py', '.psp', '.tmpl']
> >
> ># a list of glob patterns to filter out after all the rest of the
> ># path matching is finished.  404 if matches
> >FilesToHide = ['.*','*~', '*bak', '*.tmpl', ]
> >
> ># a list glob patterns to serve from exclusively.
> ># if the file found for the URI doesn't match then 404
> ># done after FilesToHide
> >FilesToServe = None  # only used if a list is given
> >#FilesToServe = ['*.py', '*.jpg','*.gif']
> >
> >
> >Regardless of whether the rest of the experimental code is used I
> >feel this stuff should definitely make it in. What do you think
> > about the names I've given the settings?  ExtensionsToServe and
> > FilesToServe are a bit ambiguous.  I'm leaning towards
> >FilePatternsToServe.
> >
> >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,256
> 			'ExtensionsToServe':   None,
> 
> 			'FilesToHide': ['.*','*~', '*bak', '*.tmpl', '*.config' ],
> 			'FilesToServe': None,
> 			
348c355,370
< 				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,943c962,969
< 		'''
< 		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."""
> 		
947c973,974
< 			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
949a977,984
> 
> 		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)
> 		

Reply via email to