[Zope3-checkins] SVN: Zope3/branches/zipimport-support/src/zope/app/publisher/browser/ demonstrate a view and template loaded directly from a ZIP archive,

Fred L. Drake, Jr. fdrake at gmail.com
Thu Nov 10 17:02:45 EST 2005


Log message for revision 40039:
  demonstrate a view and template loaded directly from a ZIP archive,
  and make it actually work
  

Changed:
  A   Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/test_zipped.py
  A   Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zippedview.zcml
  A   Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zippedview.zip
  A   Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zipsource/
  A   Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zipsource/sampleview/
  A   Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zipsource/sampleview/__init__.py
  A   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/myview.pt
  A   Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/zipped.txt
  U   Zope3/branches/zipimport-support/src/zope/app/publisher/browser/viewmeta.py

-=-
Added: Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/test_zipped.py
===================================================================
--- Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/test_zipped.py	2005-11-10 21:12:17 UTC (rev 40038)
+++ Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/test_zipped.py	2005-11-10 22:02:45 UTC (rev 40039)
@@ -0,0 +1,51 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Test harness for loading pages from packages contained in ZIP archives.
+
+"""
+__docformat__ = "reStructuredText"
+
+import os
+import sys
+
+from zope.app.testing import functional
+
+
+#### test setup ####
+
+class Layer(functional.ZCMLLayer):
+
+    # This layer still can't be completely torn down due to the base
+    # class, but tries to avoid doing more damage than it has to.
+
+    def setUp(self):
+        self.__sys_path = sys.path[:]
+        here = os.path.dirname(__file__)
+        zipfile = os.path.join(here, "testfiles", "zippedview.zip")
+        sys.path.append(zipfile)
+        functional.ZCMLLayer.setUp(self)
+
+    def tearDown(self):
+        sys.path[:] = self.__sys_path
+        functional.ZCMLLayer.tearDown(self)
+
+
+ZippedViewLayer = Layer(
+    os.path.join(os.path.dirname(__file__), "testfiles/zippedview.zcml"),
+    __name__, "ZippedViewLayer")
+
+def test_suite():
+    suite = functional.FunctionalDocFileSuite("zipped.txt")
+    suite.layer = ZippedViewLayer
+    return suite


Property changes on: Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/test_zipped.py
___________________________________________________________________
Name: svn:mime-type
   + text/x-python
Name: svn:eol-style
   + native

Added: Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zippedview.zcml
===================================================================
--- Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zippedview.zcml	2005-11-10 21:12:17 UTC (rev 40038)
+++ Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zippedview.zcml	2005-11-10 22:02:45 UTC (rev 40039)
@@ -0,0 +1,22 @@
+<configure
+    xmlns="http://namespaces.zope.org/zope"
+    package="zope.app.publisher.browser.tests"
+    >
+
+  <!-- This is a functional testing layer that adds the `sampleview`
+       package from a ZIP file to test that browser view defined by
+       products in zipped packages (such as eggs).
+       -->
+
+  <include package="zope.app"/>
+  <include package="sampleview"/>
+
+  <unauthenticatedPrincipal
+      id="zope.anybody"
+      title="Unauthenticated User" />
+
+  <securityPolicy
+      component="zope.security.simplepolicies.PermissiveSecurityPolicy"
+      />
+
+</configure>


Property changes on: Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zippedview.zcml
___________________________________________________________________
Name: svn:mime-type
   + text/xml
Name: svn:eol-style
   + native

Added: Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zippedview.zip
===================================================================
(Binary files differ)


Property changes on: Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zippedview.zip
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Added: Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zipsource/sampleview/__init__.py
===================================================================
--- Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zipsource/sampleview/__init__.py	2005-11-10 21:12:17 UTC (rev 40038)
+++ Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zipsource/sampleview/__init__.py	2005-11-10 22:02:45 UTC (rev 40039)
@@ -0,0 +1,24 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Sample view code.
+
+This is used to test views extracted from ZIP files.
+
+"""
+
+
+class MyView(object):
+
+    def sometext(self):
+        return u"(This is some text.)"


Property changes on: Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zipsource/sampleview/__init__.py
___________________________________________________________________
Name: svn:mime-type
   + text/x-python
Name: svn:eol-style
   + native

Added: 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-10 21:12:17 UTC (rev 40038)
+++ Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zipsource/sampleview/configure.zcml	2005-11-10 22:02:45 UTC (rev 40039)
@@ -0,0 +1,15 @@
+<?xml version="1.0" encoding="utf-8"?>
+<configure
+    xmlns="http://namespaces.zope.org/zope"
+    xmlns:browser="http://namespaces.zope.org/browser"
+    >
+
+  <browser:page
+      name="sometext.html"
+      permission="zope.Public"
+      for="zope.interface.Interface"
+      template="myview.pt"
+      class=".MyView"
+      />
+
+</configure>


Property changes on: Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zipsource/sampleview/configure.zcml
___________________________________________________________________
Name: svn:mime-type
   + text/xml
Name: svn:eol-style
   + native

Added: Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zipsource/sampleview/myview.pt
===================================================================
--- Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zipsource/sampleview/myview.pt	2005-11-10 21:12:17 UTC (rev 40038)
+++ Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zipsource/sampleview/myview.pt	2005-11-10 22:02:45 UTC (rev 40039)
@@ -0,0 +1 @@
+<div tal:content="view/sometext"/>


Property changes on: Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/testfiles/zipsource/sampleview/myview.pt
___________________________________________________________________
Name: svn:mime-type
   + text/xml
Name: svn:eol-style
   + native

Added: 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-10 21:12:17 UTC (rev 40038)
+++ Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/zipped.txt	2005-11-10 22:02:45 UTC (rev 40039)
@@ -0,0 +1,25 @@
+==================================
+Publishing views from ZIP archives
+==================================
+
+Python packages can be imported from ZIP files.  Zope supports using
+such packages as extension providers: ZCML can be loaded from them and
+they can provide views based on templates or other data contained
+inside the archive.
+
+This document demonstrates this facility.  The Python harness for this
+test (test_zipped.py) has added a ZIP file containing a sample package
+to sys.path, and loaded ZCML that loads a view from that package.
+
+Since the ZCML has already been loaded, we can check that our view is
+available::
+
+  >>> print http("""
+  ... GET /@@sometext.html HTTP/1.1
+  ... """)
+  HTTP/1.1 200 ...
+  <div>(This is some text.)</div>
+
+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.


Property changes on: Zope3/branches/zipimport-support/src/zope/app/publisher/browser/tests/zipped.txt
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native

Modified: Zope3/branches/zipimport-support/src/zope/app/publisher/browser/viewmeta.py
===================================================================
--- Zope3/branches/zipimport-support/src/zope/app/publisher/browser/viewmeta.py	2005-11-10 21:12:17 UTC (rev 40038)
+++ Zope3/branches/zipimport-support/src/zope/app/publisher/browser/viewmeta.py	2005-11-10 22:02:45 UTC (rev 40039)
@@ -17,6 +17,7 @@
 """
 import os
 
+from zope import filereference
 from zope.component.exceptions import ComponentLookupError
 from zope.component.interfaces import IDefaultViewName
 from zope.interface import implements, classImplements, Interface
@@ -124,8 +125,7 @@
                 "A class must be provided if attribute is used")
 
     if template:
-        template = os.path.abspath(str(_context.path(template)))
-        if not os.path.isfile(template):
+        if not filereference.isfile(template):
             raise ConfigurationError("No such file", template)
         required['__getitem__'] = permission
 
@@ -236,8 +236,7 @@
 
     def page(self, _context, name, attribute=None, template=None):
         if template:
-            template = os.path.abspath(_context.path(template))
-            if not os.path.isfile(template):
+            if not filereference.isfile(template):
                 raise ConfigurationError("No such file", template)
         else:
             if not attribute:



More information about the Zope3-Checkins mailing list