[Checkins] SVN: z3c.extfile/trunk/src/z3c/extfile/ added IResult
adapter
Bernd Dorn
bernd.dorn at fhv.at
Wed Sep 13 09:41:30 EDT 2006
Log message for revision 70150:
added IResult adapter
Changed:
A z3c.extfile/trunk/src/z3c/extfile/adapter.py
A z3c.extfile/trunk/src/z3c/extfile/adapter.txt
U z3c.extfile/trunk/src/z3c/extfile/configure.zcml
U z3c.extfile/trunk/src/z3c/extfile/tests.py
-=-
Added: z3c.extfile/trunk/src/z3c/extfile/adapter.py
===================================================================
--- z3c.extfile/trunk/src/z3c/extfile/adapter.py 2006-09-13 13:03:50 UTC (rev 70149)
+++ z3c.extfile/trunk/src/z3c/extfile/adapter.py 2006-09-13 13:41:29 UTC (rev 70150)
@@ -0,0 +1,24 @@
+from zope import component
+from zope import interface
+from zope.publisher.interfaces.http import IHTTPRequest
+from zope.publisher.http import IResult
+import interfaces
+from zope.security.proxy import removeSecurityProxy
+from zope.app.wsgi.fileresult import FallbackWrapper
+from zope.publisher.http import DirectResult
+
+ at component.adapter(interfaces.IReadFile, IHTTPRequest)
+ at interface.implementer(IResult)
+def ReadFileResult(f, request):
+ f = removeSecurityProxy(f)
+ headers = ()
+ if request.response.getHeader('content-length') is None:
+ size=len(f)
+ headers += (('Content-Length', str(size)), )
+
+ wrapper = request.environment.get('wsgi.file_wrapper')
+ if wrapper is not None:
+ f = wrapper(f)
+ else:
+ f = FallbackWrapper(f)
+ return DirectResult(f, headers)
Property changes on: z3c.extfile/trunk/src/z3c/extfile/adapter.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Added: z3c.extfile/trunk/src/z3c/extfile/adapter.txt
===================================================================
--- z3c.extfile/trunk/src/z3c/extfile/adapter.txt 2006-09-13 13:03:50 UTC (rev 70149)
+++ z3c.extfile/trunk/src/z3c/extfile/adapter.txt 2006-09-13 13:41:29 UTC (rev 70150)
@@ -0,0 +1,17 @@
+=================
+ IResult adapter
+=================
+
+The IResult adapter is used by the publisher to get the right wrapper
+around objects.
+
+ >>> from z3c.extfile import adapter
+ >>> from zope.publisher.browser import TestRequest
+ >>> from z3c.extfile.hashdir import ReadFile
+ >>> rf = ReadFile(adapter.__file__)
+ >>> request = TestRequest()
+ >>> result = adapter.ReadFileResult(rf, request)
+ >>> result
+ <zope.publisher.http.DirectResult object at ...>
+
+
Property changes on: z3c.extfile/trunk/src/z3c/extfile/adapter.txt
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: z3c.extfile/trunk/src/z3c/extfile/configure.zcml
===================================================================
--- z3c.extfile/trunk/src/z3c/extfile/configure.zcml 2006-09-13 13:03:50 UTC (rev 70149)
+++ z3c.extfile/trunk/src/z3c/extfile/configure.zcml 2006-09-13 13:41:29 UTC (rev 70150)
@@ -3,10 +3,11 @@
i18n_domain='zope'
>
+ <adapter factory=".adapter.ReadFileResult" />
+
<class class=".hashdir.ReadFile">
<allow interface=".interfaces.IReadFile"/>
</class>
-
<class class=".hashdir.HashDir">
@@ -29,7 +30,6 @@
for="zope.app.appsetup.IDatabaseOpenedEvent"
handler=".utility.bootStrapSubscriber"
/>
-
<include package=".browser"/>
</configure>
\ No newline at end of file
Modified: z3c.extfile/trunk/src/z3c/extfile/tests.py
===================================================================
--- z3c.extfile/trunk/src/z3c/extfile/tests.py 2006-09-13 13:03:50 UTC (rev 70149)
+++ z3c.extfile/trunk/src/z3c/extfile/tests.py 2006-09-13 13:41:29 UTC (rev 70150)
@@ -14,6 +14,9 @@
DocFileSuite('property.txt',
optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
),
+ DocFileSuite('adapter.txt',
+ optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
+ ),
DocFileSuite('browser/widget.txt',
optionflags=doctest.NORMALIZE_WHITESPACE|doctest.ELLIPSIS,
),
More information about the Checkins
mailing list