[Zope3-checkins] SVN: Zope3/branches/zipimport-support/src/zope/app/onlinehelp/ add support for online help from zipped packages

Fred L. Drake, Jr. fdrake at gmail.com
Fri Nov 11 17:29:34 EST 2005


Log message for revision 40054:
  add support for online help from zipped packages

Changed:
  U   Zope3/branches/zipimport-support/src/zope/app/onlinehelp/DEPENDENCIES.cfg
  U   Zope3/branches/zipimport-support/src/zope/app/onlinehelp/onlinehelp.py
  U   Zope3/branches/zipimport-support/src/zope/app/onlinehelp/onlinehelptopic.py
  A   Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/test_zipped.py
  A   Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/zippedtopic.txt
  A   Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/zippedtopic.zcml
  A   Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/zippedtopic.zip
  A   Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/zipsource/
  A   Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/zipsource/onlinehelp_test/
  A   Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/zipsource/onlinehelp_test/__init__.py
  A   Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/zipsource/onlinehelp_test/configure.zcml
  A   Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/zipsource/onlinehelp_test/docs.txt

-=-
Modified: Zope3/branches/zipimport-support/src/zope/app/onlinehelp/DEPENDENCIES.cfg
===================================================================
--- Zope3/branches/zipimport-support/src/zope/app/onlinehelp/DEPENDENCIES.cfg	2005-11-11 22:01:20 UTC (rev 40053)
+++ Zope3/branches/zipimport-support/src/zope/app/onlinehelp/DEPENDENCIES.cfg	2005-11-11 22:29:34 UTC (rev 40054)
@@ -4,6 +4,7 @@
 zope.app.renderer
 zope.app.i18n
 zope.configuration
+zope.filereference
 zope.interface
 zope.proxy
 zope.schema

Modified: Zope3/branches/zipimport-support/src/zope/app/onlinehelp/onlinehelp.py
===================================================================
--- Zope3/branches/zipimport-support/src/zope/app/onlinehelp/onlinehelp.py	2005-11-11 22:01:20 UTC (rev 40053)
+++ Zope3/branches/zipimport-support/src/zope/app/onlinehelp/onlinehelp.py	2005-11-11 22:29:34 UTC (rev 40054)
@@ -25,6 +25,7 @@
 from zope.interface import implements
 from zope.configuration.exceptions import ConfigurationError
 
+from zope import filereference
 from zope.app import zapi
 from zope.app.traversing.interfaces import IContainmentRoot
 from zope.app.onlinehelp.interfaces import IOnlineHelp, IOnlineHelpTopic
@@ -119,7 +120,7 @@
                           class_=None, resources=None):
         "See zope.app.onlineHelp.interfaces.IOnlineHelp"
 
-        if not os.path.exists(doc_path):
+        if not filereference.exists(doc_path):
             raise ConfigurationError(
                 "Help Topic definition %s does not exist" % doc_path
                 )

Modified: Zope3/branches/zipimport-support/src/zope/app/onlinehelp/onlinehelptopic.py
===================================================================
--- Zope3/branches/zipimport-support/src/zope/app/onlinehelp/onlinehelptopic.py	2005-11-11 22:01:20 UTC (rev 40053)
+++ Zope3/branches/zipimport-support/src/zope/app/onlinehelp/onlinehelptopic.py	2005-11-11 22:29:34 UTC (rev 40054)
@@ -23,6 +23,7 @@
 from persistent import Persistent
 from zope.interface import implements
 from zope.configuration.exceptions import ConfigurationError
+from zope import filereference
 
 from zope.app.container.sample import SampleContainer
 from zope.app.content_types import guess_content_type
@@ -68,12 +69,12 @@
 
     def __init__(self, path='', contentType=''):
         self.path = path
-        _data = open(os.path.normpath(self.path), 'rb').read()
+        _data = filereference.open(self.path, 'rb').read()
         self._size = len(_data)
         self._fileMode = 'rb'
         self._encoding = DEFAULT_ENCODING
 
-        if contentType=='':
+        if contentType == '':
             content_type, encoding = guess_content_type(self.path, _data, '')
         if content_type.startswith('image/'):
             self.contentType, width, height = getImageInfo(_data)
@@ -86,7 +87,7 @@
                 self._encoding = encoding
 
     def _getData(self):
-        data = open(os.path.normpath(self.path), self._fileMode).read()
+        data = filereference.open(self.path, self._fileMode).read()
         if self.contentType.startswith('text/'):
             data = unicode(data, self._encoding)
         return data
@@ -146,7 +147,7 @@
         self.interface = interface
         self.view = view
 
-        if not os.path.exists(self.path):
+        if not filereference.exists(self.path):
             raise ConfigurationError(
                 "Help Topic definition %s does not exist" % self.path
                 )
@@ -155,16 +156,17 @@
 
     def addResources(self, resources):
         """ see IOnlineHelpTopic """
+        # TODO: does not support ZIP archives yet
         dirname = os.path.dirname(self.path)
         for resource in resources:
-            resource_path=dirname+'/'+resource
-            if os.path.exists(resource_path):
+            resource_path = dirname + '/' + resource
+            if filereference.exists(resource_path):
                 self[resource] = OnlineHelpResource(resource_path)
 
     def getTopicPath(self):
         """See IOnlineHelpTopic"""
         if self.parentPath:
-            return self.parentPath+'/'+self.id
+            return self.parentPath + '/' + self.id
         else:
             return self.id
 
@@ -183,7 +185,7 @@
     type = None
 
     def _getSource(self):
-        source = open(os.path.normpath(self.path)).read()
+        source = filereference.open(self.path).read()
         return unicode(source, DEFAULT_ENCODING)
 
     source = property(_getSource)
@@ -270,16 +272,13 @@
         super(OnlineHelpTopic, self).__init__(id, title, path, parentPath,
               interface, view)
 
-        filename = os.path.basename(path.lower())
-        file_ext = 'txt'
-        if len(filename.split('.'))>1:
-            file_ext = filename.split('.')[-1]
+        file_ext = os.path.splitext(path)[1].lower()
 
         self.type = 'zope.source.plaintext'
 
-        if file_ext in ('rst', 'rest') :
+        if file_ext in ('.rst', '.rest'):
             self.type = 'zope.source.rest'
-        elif file_ext in ('stx', 'html', 'htm'):
+        elif file_ext in ('.stx', '.html', '.htm'):
             self.type = 'zope.source.stx'
 
 

Added: Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/test_zipped.py
===================================================================
--- Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/test_zipped.py	2005-11-11 22:01:20 UTC (rev 40053)
+++ Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/test_zipped.py	2005-11-11 22:29:34 UTC (rev 40054)
@@ -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.
+#
+##############################################################################
+"""Harness for loading help topics 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, "zippedtopic.zip")
+        sys.path.append(zipfile)
+        functional.ZCMLLayer.setUp(self)
+
+    def tearDown(self):
+        sys.path[:] = self.__sys_path
+        functional.ZCMLLayer.tearDown(self)
+
+
+ZippedOnlineHelpTopicLayer = Layer(
+    os.path.join(os.path.dirname(__file__), "zippedtopic.zcml"),
+    __name__, "ZippedOnlineHelpTopicLayer")
+
+def test_suite():
+    suite = functional.FunctionalDocFileSuite("zippedtopic.txt")
+    suite.layer = ZippedOnlineHelpTopicLayer
+    return suite


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

Added: Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/zippedtopic.txt
===================================================================
--- Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/zippedtopic.txt	2005-11-11 22:01:20 UTC (rev 40053)
+++ Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/zippedtopic.txt	2005-11-11 22:29:34 UTC (rev 40054)
@@ -0,0 +1,24 @@
+=====================================
+Loading help topics from ZIP archives
+=====================================
+
+Help topics, like many types of resources, can be offered by packages
+imported from ZIP archives.  The harness for this test adds a ZIP file
+containing the "onlinehelp_test" package, which provides a single help
+topic.  We'll load the topic via the help system to demonstrate that
+this works::
+
+  >>> print http("""
+  ... GET /++help++/@@contexthelp.html HTTP/1.1
+  ... """, handle_errors=False)
+  HTTP/1.1 200 ...
+  ...<a href="/++help++/onlinehelp_test">Online Help Test Topic</a...
+
+We can now select our topic to see our sample help text::
+
+  >>> print http("""
+  ... GET /++help++/onlinehelp_test HTTP/1.1
+  ... """)
+  HTTP/1.1 200 ...
+  ...This is the test online help topic...
+  ...There isn't much text here...


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

Added: Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/zippedtopic.zcml
===================================================================
--- Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/zippedtopic.zcml	2005-11-11 22:01:20 UTC (rev 40053)
+++ Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/zippedtopic.zcml	2005-11-11 22:29:34 UTC (rev 40054)
@@ -0,0 +1,25 @@
+<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="zope.app.renderer"/>
+  <include package="zope.app.onlinehelp" file="meta.zcml"/>
+  <include package="zope.app.onlinehelp"/>
+  <include package="onlinehelp_test"/>
+
+  <unauthenticatedPrincipal
+      id="zope.anybody"
+      title="Unauthenticated User" />
+
+  <securityPolicy
+      component="zope.security.simplepolicies.PermissiveSecurityPolicy"
+      />
+
+</configure>


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

Added: Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/zippedtopic.zip
===================================================================
(Binary files differ)


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

Added: Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/zipsource/onlinehelp_test/__init__.py
===================================================================
--- Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/zipsource/onlinehelp_test/__init__.py	2005-11-11 22:01:20 UTC (rev 40053)
+++ Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/zipsource/onlinehelp_test/__init__.py	2005-11-11 22:29:34 UTC (rev 40054)
@@ -0,0 +1 @@
+# This directory is a Python package.


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

Added: Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/zipsource/onlinehelp_test/configure.zcml
===================================================================
--- Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/zipsource/onlinehelp_test/configure.zcml	2005-11-11 22:01:20 UTC (rev 40053)
+++ Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/zipsource/onlinehelp_test/configure.zcml	2005-11-11 22:29:34 UTC (rev 40054)
@@ -0,0 +1,14 @@
+<configure
+    xmlns="http://namespaces.zope.org/zope"
+    xmlns:help="http://namespaces.zope.org/help"
+    i18n_domain="zope"
+    >
+
+  <include package="zope.app"/>
+  <help:register
+      id="onlinehelp_test"
+      title="Online Help Test Topic"
+      doc_path="docs.txt"
+      />
+
+</configure>


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

Added: Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/zipsource/onlinehelp_test/docs.txt
===================================================================
--- Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/zipsource/onlinehelp_test/docs.txt	2005-11-11 22:01:20 UTC (rev 40053)
+++ Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/zipsource/onlinehelp_test/docs.txt	2005-11-11 22:29:34 UTC (rev 40054)
@@ -0,0 +1,3 @@
+This is the test online help topic.
+
+There isn't much text here.


Property changes on: Zope3/branches/zipimport-support/src/zope/app/onlinehelp/tests/zipsource/onlinehelp_test/docs.txt
___________________________________________________________________
Name: svn:mime-type
   + text/plain
Name: svn:eol-style
   + native



More information about the Zope3-Checkins mailing list