[Zope-Checkins] SVN: Zope/trunk/lib/python/OFS/ Collector #533: ZMI Find now searches in text Files.

Stefan H. Holek stefan at epy.co.at
Thu Jan 27 13:48:58 EST 2005


Log message for revision 28966:
  Collector #533: ZMI Find now searches in text Files.
  

Changed:
  U   Zope/trunk/lib/python/OFS/Image.py
  U   Zope/trunk/lib/python/OFS/tests/testFileAndImage.py

-=-
Modified: Zope/trunk/lib/python/OFS/Image.py
===================================================================
--- Zope/trunk/lib/python/OFS/Image.py	2005-01-27 16:32:39 UTC (rev 28965)
+++ Zope/trunk/lib/python/OFS/Image.py	2005-01-27 18:48:53 UTC (rev 28966)
@@ -105,7 +105,7 @@
          ('manage_edit','manage_upload','PUT')),
         ('View',
          ('index_html', 'view_image_or_file', 'get_size',
-          'getContentType', '')),
+          'getContentType', 'PrincipiaSearchSource', '')),
         ('FTP access',
          ('manage_FTPstat','manage_FTPget','manage_FTPlist')),
         ('Delete objects',
@@ -413,6 +413,13 @@
         """
         raise Redirect, URL1
 
+    def PrincipiaSearchSource(self):
+        """ Allow file objects to be searched.
+        """
+        if self.content_type.startswith('text/'):
+            return str(self.data)
+        return ''
+
     # private
     update_data__roles__=()
     def update_data(self, data, content_type=None, size=None):

Modified: Zope/trunk/lib/python/OFS/tests/testFileAndImage.py
===================================================================
--- Zope/trunk/lib/python/OFS/tests/testFileAndImage.py	2005-01-27 16:32:39 UTC (rev 28965)
+++ Zope/trunk/lib/python/OFS/tests/testFileAndImage.py	2005-01-27 18:48:53 UTC (rev 28966)
@@ -1,3 +1,7 @@
+import Testing
+import Zope
+Zope.startup()
+
 import os, sys
 import unittest
 import time
@@ -219,6 +223,25 @@
     def testStr(self):
         self.assertEqual(str(self.file), self.data)
 
+    def testFindSupport_not_text(self):
+        self.file.manage_edit('foobar', 'application/octet-stream',
+                              filedata=''.join([chr(x) for x in range(256)]))
+        self.assertEqual(self.file.PrincipiaSearchSource(), '')
+
+    def testFindSupport_text(self):
+        self.file.manage_edit('foobar', 'text/plain',
+                              filedata='Now is the time for all good men to '
+                                       'come to the aid of the Party.')
+        self.failUnless('Party' in self.file.PrincipiaSearchSource())
+
+    def testFindFile(self):
+        self.file.manage_edit('foobar', 'text/plain',
+                              filedata='Now is the time for all good men to '
+                                       'come to the aid of the Party.')
+        results = self.app.ZopeFind(self.app, obj_searchterm='Party')
+        self.assertEqual(len(results), 1)
+        self.assertEqual(results[0][1], self.file)
+
 class ImageTests(FileTests):
     data = open(filedata, 'rb').read()
     content_type = 'image/gif'



More information about the Zope-Checkins mailing list