[Zope3-checkins] SVN: Zope3/trunk/ Factored text-indexing support
in zptpahe into a separately
Jim Fulton
jim at zope.com
Sun May 23 15:28:23 EDT 2004
Log message for revision 24912:
Factored text-indexing support in zptpahe into a separately
distributed subpackage.
-=-
Added: Zope3/trunk/package-includes/zope.app.zptpage.textindex-configure.zcml
===================================================================
--- Zope3/trunk/package-includes/zope.app.zptpage.textindex-configure.zcml 2004-05-23 19:24:49 UTC (rev 24911)
+++ Zope3/trunk/package-includes/zope.app.zptpage.textindex-configure.zcml 2004-05-23 19:28:22 UTC (rev 24912)
@@ -0,0 +1 @@
+<include package="zope.app.zptpage.textindex" />
Property changes on: Zope3/trunk/package-includes/zope.app.zptpage.textindex-configure.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: Zope3/trunk/src/zope/app/zptpage/DEPENDENCIES.cfg
===================================================================
--- Zope3/trunk/src/zope/app/zptpage/DEPENDENCIES.cfg 2004-05-23 19:24:49 UTC (rev 24911)
+++ Zope3/trunk/src/zope/app/zptpage/DEPENDENCIES.cfg 2004-05-23 19:28:22 UTC (rev 24912)
@@ -9,7 +9,4 @@
zope.schema
zope.security
zope.testing
-
-zope.app
-zope.app.index
zope.app.pagetemplate
Modified: Zope3/trunk/src/zope/app/zptpage/PACKAGE.cfg
===================================================================
--- Zope3/trunk/src/zope/app/zptpage/PACKAGE.cfg 2004-05-23 19:24:49 UTC (rev 24911)
+++ Zope3/trunk/src/zope/app/zptpage/PACKAGE.cfg 2004-05-23 19:28:22 UTC (rev 24912)
@@ -5,3 +5,7 @@
zptpage-configure.zcml svn://svn.zope.org/repos/main/Zope3/tags/*/package-includes/zptpage-configure.zcml
</load>
+
+<collection>
+textindex -
+</collection>
Modified: Zope3/trunk/src/zope/app/zptpage/configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/zptpage/configure.zcml 2004-05-23 19:24:49 UTC (rev 24911)
+++ Zope3/trunk/src/zope/app/zptpage/configure.zcml 2004-05-23 19:28:22 UTC (rev 24912)
@@ -57,12 +57,6 @@
<adapter
for=".interfaces.IZPTPage"
- provides="zope.app.index.interfaces.text.ISearchableText"
- factory=".zptpage.SearchableText"
- />
-
- <adapter
- for=".interfaces.IZPTPage"
provides="zope.app.size.interfaces.ISized"
factory=".zptpage.Sized"
/>
Modified: Zope3/trunk/src/zope/app/zptpage/tests/test_zptpage.py
===================================================================
--- Zope3/trunk/src/zope/app/zptpage/tests/test_zptpage.py 2004-05-23 19:24:49 UTC (rev 24911)
+++ Zope3/trunk/src/zope/app/zptpage/tests/test_zptpage.py 2004-05-23 19:28:22 UTC (rev 24912)
@@ -22,7 +22,6 @@
from zope.exceptions import Forbidden
from zope.app.tests import ztapi
-from zope.app.index.interfaces.text import ISearchableText
from zope.component import getView
from zope.publisher.browser import TestRequest
from zope.app.publisher.browser import BrowserView
@@ -38,7 +37,7 @@
from zope.app.zptpage.interfaces import IZPTPage
from zope.app.zptpage.zptpage import ZPTPage, ZPTSourceView,\
ZPTReadFile, ZPTWriteFile, ZPTFactory
-from zope.app.zptpage.zptpage import Sized, SearchableText
+from zope.app.zptpage.zptpage import Sized
class Data(object):
@@ -52,26 +51,9 @@
super(ZPTPageTests, self).setUp()
ztapi.provideAdapter(None, ITraverser, Traverser)
ztapi.provideAdapter(None, ITraversable, DefaultTraversable)
- ztapi.provideAdapter(IZPTPage, ISearchableText, SearchableText)
defineChecker(Data, NamesChecker(['URL', 'name']))
defineChecker(TestRequest, NamesChecker(['getPresentationSkin']))
- def testSearchableText(self):
- page = ZPTPage()
- searchableText = ISearchableText(page)
-
- utext = u'another test\n' # The source will grow a newline if ommited
- html = u"<html><body>%s</body></html>\n" % (utext, )
-
- page.setSource(utext)
- self.failUnlessEqual(searchableText.getSearchableText(), [utext])
-
- page.setSource(html, content_type='text/html')
- self.assertEqual(searchableText.getSearchableText(), [utext+'\n'])
-
- page.setSource(html, content_type='text/plain')
- self.assertEqual(searchableText.getSearchableText(), [html])
-
def testZPTRendering(self):
page = ZPTPage()
page.setSource(
Copied: Zope3/trunk/src/zope/app/zptpage/textindex/DEPENDENCIES.cfg (from rev 24906, Zope3/trunk/src/zope/app/zptpage/DEPENDENCIES.cfg)
===================================================================
--- Zope3/trunk/src/zope/app/zptpage/DEPENDENCIES.cfg 2004-05-23 16:21:33 UTC (rev 24906)
+++ Zope3/trunk/src/zope/app/zptpage/textindex/DEPENDENCIES.cfg 2004-05-23 19:28:22 UTC (rev 24912)
@@ -0,0 +1 @@
+zope.app.index
Copied: Zope3/trunk/src/zope/app/zptpage/textindex/SETUP.cfg (from rev 24906, Zope3/trunk/src/zope/app/zptpage/SETUP.cfg)
Added: Zope3/trunk/src/zope/app/zptpage/textindex/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/zptpage/textindex/__init__.py 2004-05-23 19:24:49 UTC (rev 24911)
+++ Zope3/trunk/src/zope/app/zptpage/textindex/__init__.py 2004-05-23 19:28:22 UTC (rev 24912)
@@ -0,0 +1 @@
+#
Property changes on: Zope3/trunk/src/zope/app/zptpage/textindex/__init__.py
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native
Copied: Zope3/trunk/src/zope/app/zptpage/textindex/configure.zcml (from rev 24906, Zope3/trunk/src/zope/app/zptpage/configure.zcml)
===================================================================
--- Zope3/trunk/src/zope/app/zptpage/configure.zcml 2004-05-23 16:21:33 UTC (rev 24906)
+++ Zope3/trunk/src/zope/app/zptpage/textindex/configure.zcml 2004-05-23 19:28:22 UTC (rev 24912)
@@ -0,0 +1,9 @@
+<configure xmlns='http://namespaces.zope.org/zope'>
+
+ <adapter
+ for="..interfaces.IZPTPage"
+ provides="zope.app.index.interfaces.text.ISearchableText"
+ factory=".zptpage.SearchableText"
+ />
+
+</configure>
Copied: Zope3/trunk/src/zope/app/zptpage/textindex/tests.py (from rev 24906, Zope3/trunk/src/zope/app/zptpage/tests/test_zptpage.py)
===================================================================
--- Zope3/trunk/src/zope/app/zptpage/tests/test_zptpage.py 2004-05-23 16:21:33 UTC (rev 24906)
+++ Zope3/trunk/src/zope/app/zptpage/textindex/tests.py 2004-05-23 19:28:22 UTC (rev 24912)
@@ -0,0 +1,55 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+#
+##############################################################################
+"""Basic tests for Page Templates used in content-space.
+
+$Id$
+"""
+
+from zope.app.index.interfaces.text import ISearchableText
+from zope.app.tests import ztapi
+from zope.app.tests.placelesssetup import PlacelessSetup
+from zope.app.zptpage.interfaces import IZPTPage
+from zope.app.zptpage.textindex.zptpage import SearchableText
+from zope.app.zptpage.zptpage import ZPTPage
+import unittest
+
+class ZPTPageTests(PlacelessSetup, unittest.TestCase):
+
+ def setUp(self):
+ super(ZPTPageTests, self).setUp()
+ ztapi.provideAdapter(IZPTPage, ISearchableText, SearchableText)
+
+ def testSearchableText(self):
+ page = ZPTPage()
+ searchableText = ISearchableText(page)
+
+ utext = u'another test\n' # The source will grow a newline if ommited
+ html = u"<html><body>%s</body></html>\n" % (utext, )
+
+ page.setSource(utext)
+ self.failUnlessEqual(searchableText.getSearchableText(), [utext])
+
+ page.setSource(html, content_type='text/html')
+ self.assertEqual(searchableText.getSearchableText(), [utext+'\n'])
+
+ page.setSource(html, content_type='text/plain')
+ self.assertEqual(searchableText.getSearchableText(), [html])
+
+def test_suite():
+ return unittest.TestSuite((
+ unittest.makeSuite(ZPTPageTests),
+ ))
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run(test_suite())
Added: Zope3/trunk/src/zope/app/zptpage/textindex/zpe.app.zptpage.textindex-configure.zcml
===================================================================
--- Zope3/trunk/src/zope/app/zptpage/textindex/zpe.app.zptpage.textindex-configure.zcml 2004-05-23 19:24:49 UTC (rev 24911)
+++ Zope3/trunk/src/zope/app/zptpage/textindex/zpe.app.zptpage.textindex-configure.zcml 2004-05-23 19:28:22 UTC (rev 24912)
@@ -0,0 +1 @@
+<include package="zope.app.zptpage.textindex" />
Property changes on: Zope3/trunk/src/zope/app/zptpage/textindex/zpe.app.zptpage.textindex-configure.zcml
___________________________________________________________________
Name: svn:eol-style
+ native
Copied: Zope3/trunk/src/zope/app/zptpage/textindex/zptpage.py (from rev 24906, Zope3/trunk/src/zope/app/zptpage/zptpage.py)
===================================================================
--- Zope3/trunk/src/zope/app/zptpage/zptpage.py 2004-05-23 16:21:33 UTC (rev 24906)
+++ Zope3/trunk/src/zope/app/zptpage/textindex/zptpage.py 2004-05-23 19:28:22 UTC (rev 24912)
@@ -0,0 +1,45 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (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.
+#
+##############################################################################
+"""
+$Id$
+"""
+
+from zope.interface import implements
+from zope.app.zptpage.interfaces import IZPTPage
+from zope.app.index.interfaces.text import ISearchableText
+import re
+
+tag = re.compile(r"<[^>]+>")
+
+class SearchableText:
+
+ __used_for__ = IZPTPage
+ implements(ISearchableText)
+
+ def __init__(self, page):
+ self.page = page
+
+ def getSearchableText(self):
+ text = self.page.getSource()
+ if isinstance(text, str):
+ text = unicode(self.page.source, 'utf-8')
+ # else:
+ # text was already Unicode, which happens, but unclear how it
+ # gets converted to Unicode since the ZPTPage stores UTF-8 as
+ # an 8-bit string.
+
+ if self.page.content_type.startswith('text/html'):
+ text = tag.sub('', text)
+
+ return [text]
Modified: Zope3/trunk/src/zope/app/zptpage/zptpage.py
===================================================================
--- Zope3/trunk/src/zope/app/zptpage/zptpage.py 2004-05-23 19:24:49 UTC (rev 24911)
+++ Zope3/trunk/src/zope/app/zptpage/zptpage.py 2004-05-23 19:28:22 UTC (rev 24912)
@@ -14,7 +14,6 @@
"""
$Id$
"""
-import re
from persistent import Persistent
@@ -25,7 +24,6 @@
from zope.app.pagetemplate.engine import AppPT
from zope.app.i18n import ZopeMessageIDFactory as _
-from zope.app.index.interfaces.text import ISearchableText
from zope.app.size.interfaces import ISized
from zope.app.filerepresentation.interfaces import IReadFile, IWriteFile
from zope.app.filerepresentation.interfaces import IFileFactory
@@ -90,29 +88,6 @@
"""Source of the Page Template.""")
-class SearchableText:
-
- __used_for__ = IZPTPage
- implements(ISearchableText)
-
- def __init__(self, page):
- self.page = page
-
- def getSearchableText(self):
- text = self.page.getSource()
- if isinstance(text, str):
- text = unicode(self.page.source, 'utf-8')
- # else:
- # text was already Unicode, which happens, but unclear how it
- # gets converted to Unicode since the ZPTPage stores UTF-8 as
- # an 8-bit string.
-
- if self.page.content_type.startswith('text/html'):
- tag = re.compile(r"<[^>]+>")
- text = tag.sub('', text)
-
- return [text]
-
class Sized:
implements(ISized)
More information about the Zope3-Checkins
mailing list