[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/OFS/Content/File - File.py:1.9 configure.zcml:1.13

Guido van Rossum guido@python.org
Wed, 4 Dec 2002 15:49:39 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/OFS/Content/File
In directory cvs.zope.org:/tmp/cvs-serv1842

Modified Files:
	File.py configure.zcml 
Log Message:
Add an adapter from IReadFile to ISearchableText.
If the contentType is text/plain, return the data, as unicode.
For other content types, return None (meaning not to index it).

=== Zope3/lib/python/Zope/App/OFS/Content/File/File.py 1.8 => 1.9 ===
--- Zope3/lib/python/Zope/App/OFS/Content/File/File.py:1.8	Thu Jul 25 18:09:30 2002
+++ Zope3/lib/python/Zope/App/OFS/Content/File/File.py	Wed Dec  4 15:49:38 2002
@@ -21,11 +21,10 @@
 from Transaction import get_transaction
 
 from Zope.App.OFS.Content.File.FileChunk import FileChunk
-from Zope.App.OFS.Content.File.IFile import IFile
 from Zope.Publisher.Browser.BrowserRequest import FileUpload
 
 from Zope.App.OFS.Annotation.IAnnotatable import IAnnotatable
-from Zope.App.OFS.Content.File.IFile import IFile
+from Zope.App.OFS.Content.File.IFile import IFile, IReadFile
 
 # set the size of the chunks
 MAXCHUNKSIZE = 1 << 16
@@ -174,3 +173,22 @@
 
     size = property(getSize, None, None,
                     """Specifies the size of the file in bytes. Read only.""")
+
+
+# Adapter for ISearchableText
+
+from Zope.App.index.text.interfaces import ISearchableText
+
+class SearchableText:
+
+    __implements__ = ISearchableText
+    __used_for__ = IReadFile
+
+    def __init__(self, file):
+        self.file = file
+
+    def getSearchableText(self):
+        if self.file.contentType == "text/plain":
+            return [unicode(self.file.data)]
+        else:
+            return None


=== Zope3/lib/python/Zope/App/OFS/Content/File/configure.zcml 1.12 => 1.13 ===
--- Zope3/lib/python/Zope/App/OFS/Content/File/configure.zcml:1.12	Wed Nov 13 15:38:25 2002
+++ Zope3/lib/python/Zope/App/OFS/Content/File/configure.zcml	Wed Dec  4 15:49:38 2002
@@ -45,6 +45,10 @@
 
 </content>
 
+<adapter factory=".File.SearchableText"
+         provides="Zope.App.index.text.interfaces.ISearchableText"
+         for="Zope.App.OFS.Content.File.IFile.IReadFile" />
+
 <include package=".Views" />
 
 </zopeConfigure>