[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/onlinehelp/onlinehelptopic.py The file mode in _getData now depends on the content type:

Eckart Hertzler eckart at hertzler.de
Fri Jun 4 04:49:49 EDT 2004


Log message for revision 25247:

The file mode in _getData now depends on the content type:

By default it is : 'rb'
For content type text/* it is : 'r'




-=-
Modified: Zope3/trunk/src/zope/app/onlinehelp/onlinehelptopic.py
===================================================================
--- Zope3/trunk/src/zope/app/onlinehelp/onlinehelptopic.py	2004-06-04 00:49:24 UTC (rev 25246)
+++ Zope3/trunk/src/zope/app/onlinehelp/onlinehelptopic.py	2004-06-04 08:49:49 UTC (rev 25247)
@@ -29,7 +29,6 @@
 from zope.app.onlinehelp.interfaces import IOnlineHelpTopic, \
      IOnlineHelpResource
 
-
 class OnlineHelpResource(Persistent):
     """
     Represents a resource that is used inside
@@ -41,7 +40,18 @@
     >>> resource = OnlineHelpResource(path)
     >>> resource.contentType
     'image/png'
+    >>> resource._fileMode
+    'rb'
+
     
+    >>> path = os.path.join(testdir(), 'help2.txt')
+
+    >>> resource = OnlineHelpResource(path)
+    >>> resource.contentType
+    'text/plain'
+    >>> resource._fileMode
+    'r'
+    
     """
     implements(IOnlineHelpResource)
 
@@ -49,6 +59,7 @@
         self.path = path
         _data = open(os.path.normpath(self.path), 'rb').read()
         self._size=len(path)
+        self._fileMode = 'rb'
 
         if contentType=='':
             content_type, encoding = guess_content_type(self.path, _data, '')
@@ -57,8 +68,11 @@
         else:
             self.contentType = content_type
 
+        if self.contentType.startswith('text/'):
+            self._fileMode = 'r'
+
     def _getData(self):
-        return open(os.path.normpath(self.path)).read()
+        return open(os.path.normpath(self.path), self._fileMode).read()
 
     data = property(_getData)
 




More information about the Zope3-Checkins mailing list