[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/publisher/browser/
Fix obscure case of files without extensions in resource
directories.
Fred L. Drake, Jr.
fdrake at gmail.com
Fri Aug 6 14:55:23 EDT 2004
Log message for revision 26941:
Fix obscure case of files without extensions in resource directories.
Files with names that matched the extensions being checked for could
have the wrong kind of resource created for them; imparticular, files
named simply "png" or "gif" (a really weird case) would have image
resources created for them rather than simple file resources. Fixed,
added a test case.
Use a instance of object for the marker value, since that's a simpler,
immutable object with a smaller memory requirement.
Changed:
U Zope3/trunk/src/zope/app/publisher/browser/directoryresource.py
U Zope3/trunk/src/zope/app/publisher/browser/tests/test_directoryresource.py
A Zope3/trunk/src/zope/app/publisher/browser/tests/testfiles/png
-=-
Modified: Zope3/trunk/src/zope/app/publisher/browser/directoryresource.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/directoryresource.py 2004-08-06 18:22:17 UTC (rev 26940)
+++ Zope3/trunk/src/zope/app/publisher/browser/directoryresource.py 2004-08-06 18:55:23 UTC (rev 26941)
@@ -29,7 +29,7 @@
from pagetemplateresource import PageTemplateResourceFactory
from resources import empty
-_marker = []
+_marker = object()
# we only need this class as a context for DirectoryResource
class Directory(object):
@@ -43,12 +43,12 @@
implements(IBrowserPublisher)
resource_factories = {
- 'gif': ImageResourceFactory,
- 'png': ImageResourceFactory,
- 'jpg': ImageResourceFactory,
- 'pt': PageTemplateResourceFactory,
- 'zpt': PageTemplateResourceFactory,
- 'html': PageTemplateResourceFactory,
+ '.gif': ImageResourceFactory,
+ '.png': ImageResourceFactory,
+ '.jpg': ImageResourceFactory,
+ '.pt': PageTemplateResourceFactory,
+ '.zpt': PageTemplateResourceFactory,
+ '.html': PageTemplateResourceFactory,
}
default_factory = FileResourceFactory
@@ -74,7 +74,7 @@
if default is _marker:
raise NotFoundError(name)
return default
- ext = name.split('.')[-1]
+ ext = os.path.splitext(os.path.normcase(name))[1]
factory = self.resource_factories.get(ext, self.default_factory)
resource = factory(filename, self.context.checker)(self.request)
resource.__parent__ = self
Modified: Zope3/trunk/src/zope/app/publisher/browser/tests/test_directoryresource.py
===================================================================
--- Zope3/trunk/src/zope/app/publisher/browser/tests/test_directoryresource.py 2004-08-06 18:22:17 UTC (rev 26940)
+++ Zope3/trunk/src/zope/app/publisher/browser/tests/test_directoryresource.py 2004-08-06 18:55:23 UTC (rev 26941)
@@ -110,6 +110,8 @@
self.assert_(isinstance(removeAllProxies(template), PageTemplateResource))
file = resource['test.txt']
self.assert_(isinstance(removeAllProxies(file), FileResource))
+ file = resource['png']
+ self.assert_(isinstance(removeAllProxies(file), FileResource))
def test_suite():
return makeSuite(Test)
Copied: Zope3/trunk/src/zope/app/publisher/browser/tests/testfiles/png (from rev 26940, Zope3/trunk/src/zope/app/publisher/browser/tests/testfiles/test.txt)
More information about the Zope3-Checkins
mailing list