[Twisted-web] [PATCH] Make all file extentions case-insensitive.

Wilfredo Sánchez Vega wsanchez at wsanchez.net
Mon Jul 11 17:48:11 MDT 2005

   The current code in static.py has a special case for Windows in  
order to deal with possible confusion in matching file extensions on  
a case-insensitive filesystem.

   That's the wrong test; a correct test would be per-filesystem, not  
per-OS.  I assume it's possible to write a case-sensitive filesystem  
on Windows (dunno, really), and there exist both case-sensitive and  
case-insensitive filesystem on a few operating systems, most  
prominently Mac OS.  (eg. They exist on Linux as well, though not as  
widely used.)

   Anyway, so the test is wrong.  Unfortunately, a correct (and not  
complicated) test isn't really obvious to anyone.

   I propose we dodge the problem by making our handling of file  
extensions (not filenames) case-insensitive, which is pretty much  
what people expect anyway: foo.TXT is the same type of file as  
foo.txt, etc.

   We simply lowercase the extensions when they are registered and  
looked up.

   This patch also gets rid of our usage of InsensitiveDict(), which  
has its detractors.


Index: static.py
--- static.py   (revision 14132)
+++ static.py   (working copy)
@@ -14,8 +14,6 @@
# Twisted Imports
from twisted.python import filepath
-from twisted.python.util import InsensitiveDict
-from twisted.python.runtime import platformType
from zope.interface import implements
dangerousPathError = http.HTTPError(responsecode.NOT_FOUND) #"Invalid  
request URL."
@@ -140,7 +138,10 @@
          self.ignoredExts = list(ignoredExts)
          self.children = {}
          if processors is not None:
-            self.processors = processors
+            self.processors = dict([
+                (key.lower(), value)
+                for key, value in processors.items()
+            ])
          if indexNames is not None:
              self.indexNames = indexNames
@@ -189,12 +190,7 @@
          # Don't run processors on directories - if someone wants  
their own
          # customized directory rendering, subclass File instead.
          if fpath.isfile():
-            if platformType == "win32":
-                # don't want .RPY to be different than .rpy, since that
-                # would allow source disclosure.
-                processor = InsensitiveDict(self.processors).get 
-            else:
-                processor = self.processors.get(fpath.splitext()[1])
+            processor = self.processors.get(fpath.splitext()[1].lower 
              if processor:
                  return (

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 3057 bytes
Desc: not available
Url : http://twistedmatrix.com/pipermail/twisted-web/attachments/20050711/05afc42c/smime.bin

More information about the Twisted-web mailing list