[Zope3-checkins]
SVN: Zope3/branches/zipimport-support/src/zope/app/publisher/
make file resources available from ZIP archives
Fred L. Drake, Jr.
fdrake at gmail.com
Fri Nov 11 15:06:12 EST 2005
Log message for revision 40052:
make file resources available from ZIP archives
Changed:
U Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zippedview.zip
U Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zipsource/sampleview/configure.zcml
A Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zipsource/sampleview/mytext.txt
U Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/zipped.txt
U Zope3/branches/zipimport-support/src/zope/app/publisher/fileresource.py
-=-
Modified: Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zippedview.zip
===================================================================
(Binary files differ)
Modified: Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zipsource/sampleview/configure.zcml
===================================================================
--- Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zipsource/sampleview/configure.zcml 2005-11-11 20:00:54 UTC (rev 40051)
+++ Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zipsource/sampleview/configure.zcml 2005-11-11 20:06:12 UTC (rev 40052)
@@ -12,4 +12,9 @@
class=".MyView"
/>
+ <browser:resource
+ name="sometext.txt"
+ file="mytext.txt"
+ />
+
</configure>
Added: Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zipsource/sampleview/mytext.txt
===================================================================
--- Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zipsource/sampleview/mytext.txt 2005-11-11 20:00:54 UTC (rev 40051)
+++ Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zipsource/sampleview/mytext.txt 2005-11-11 20:06:12 UTC (rev 40052)
@@ -0,0 +1 @@
+This is a simple text file provided as a resource.
Property changes on: Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zipsource/sampleview/mytext.txt
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:eol-style
+ native
Modified: Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/zipped.txt
===================================================================
--- Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/zipped.txt 2005-11-11 20:00:54 UTC (rev 40051)
+++ Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/zipped.txt 2005-11-11 20:06:12 UTC (rev 40052)
@@ -23,3 +23,12 @@
This is the text provided by the view class in in the `sampleview`
package's __init__.py, wrapped in the <div> element from the myview.pt
template also contained in that package.
+
+We can also provide file resources from ZIP archives::
+
+ >>> print http("""
+ ... GET /@@/sometext.txt HTTP/1.1
+ ... """)
+ HTTP/1.1 200 ...
+ This is a simple text file provided as a resource.
+ <BLANKLINE>
Modified: Zope3/branches/zipimport-support/src/zope/app/publisher/fileresource.py
===================================================================
--- Zope3/branches/zipimport-support/src/zope/app/publisher/fileresource.py 2005-11-11 20:00:54 UTC (rev 40051)
+++ Zope3/branches/zipimport-support/src/zope/app/publisher/fileresource.py 2005-11-11 20:06:12 UTC (rev 40052)
@@ -16,25 +16,25 @@
$Id$
"""
import os
-import posixpath
from time import time
+from zope import filereference
from zope.app.content_types import guess_content_type
from zope.app.datetimeutils import rfc1123_date
class File(object):
-
+
def __init__(self, path, name):
self.path = path
- f = open(path, 'rb')
+ f = filereference.open(path, 'rb')
data = f.read()
f.close()
self.content_type, enc = guess_content_type(path, data)
self.__name__ = name
- self.lmt = float(os.path.getmtime(path)) or time()
+ self.lmt = float(filereference.getmtime(path)) or time()
self.lmh = rfc1123_date(self.lmt)
More information about the Zope3-Checkins
mailing list