[Zope3-checkins] SVN: Zope3/trunk/ Set UTF-8 as default encoding for OnlineHelp sources

Dmitry Vasiliev dima at hlabs.spb.ru
Sun Nov 6 07:33:05 EST 2005


Log message for revision 39944:
  Set UTF-8 as default encoding for OnlineHelp sources
  

Changed:
  U   Zope3/trunk/doc/CHANGES.txt
  U   Zope3/trunk/src/zope/app/onlinehelp/onlinehelptopic.py
  U   Zope3/trunk/src/zope/app/onlinehelp/tests/help.html
  U   Zope3/trunk/src/zope/app/onlinehelp/tests/help.pt
  U   Zope3/trunk/src/zope/app/onlinehelp/tests/help.rst
  U   Zope3/trunk/src/zope/app/onlinehelp/tests/help.stx
  U   Zope3/trunk/src/zope/app/onlinehelp/tests/help2.txt

-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt	2005-11-06 10:29:33 UTC (rev 39943)
+++ Zope3/trunk/doc/CHANGES.txt	2005-11-06 12:33:04 UTC (rev 39944)
@@ -149,6 +149,9 @@
 
     Bug Fixes
 
+      - Fix: OnlineHelp source files and textual resources now
+        use UTF-8 as default encoding.
+
       - Fixed issue #455: tal:content="" does not get translated
         by i18n:translate=""
 

Modified: Zope3/trunk/src/zope/app/onlinehelp/onlinehelptopic.py
===================================================================
--- Zope3/trunk/src/zope/app/onlinehelp/onlinehelptopic.py	2005-11-06 10:29:33 UTC (rev 39943)
+++ Zope3/trunk/src/zope/app/onlinehelp/onlinehelptopic.py	2005-11-06 12:33:04 UTC (rev 39944)
@@ -36,8 +36,10 @@
 from zope.app.onlinehelp.interfaces import IOnlineHelpResource
 
 
+DEFAULT_ENCODING = "utf-8"
+
 class OnlineHelpResource(Persistent):
-    """
+    r"""
     Represents a resource that is used inside
     the rendered Help Topic - for example a screenshot.
 
@@ -57,14 +59,19 @@
     'text/plain'
     >>> resource._fileMode
     'r'
+    >>> resource.data.splitlines()[0]
+    u'This is another help!'
+    >>> u'\u0444\u0430\u0439\u043b' in resource.data
+    True
     """
     implements(IOnlineHelpResource)
 
     def __init__(self, path='', contentType=''):
         self.path = path
         _data = open(os.path.normpath(self.path), 'rb').read()
-        self._size=len(path)
+        self._size = len(_data)
         self._fileMode = 'rb'
+        self._encoding = DEFAULT_ENCODING
 
         if contentType=='':
             content_type, encoding = guess_content_type(self.path, _data, '')
@@ -75,9 +82,14 @@
 
         if self.contentType.startswith('text/'):
             self._fileMode = 'r'
+            if encoding:
+                self._encoding = encoding
 
     def _getData(self):
-        return open(os.path.normpath(self.path), self._fileMode).read()
+        data = open(os.path.normpath(self.path), self._fileMode).read()
+        if self.contentType.startswith('text/'):
+            data = unicode(data, self._encoding)
+        return data
 
     data = property(_getData)
 
@@ -171,7 +183,8 @@
     type = None
 
     def _getSource(self):
-        return open(os.path.normpath(self.path)).read()
+        source = open(os.path.normpath(self.path)).read()
+        return unicode(source, DEFAULT_ENCODING)
 
     source = property(_getSource)
 
@@ -213,7 +226,7 @@
     Test the help content.
 
       >>> topic.source
-      'This is a help!'
+      u'This is a help!'
 
       >>> path = os.path.join(testdir(), 'help.stx')
       >>> topic = OnlineHelpTopic('help','Help',path,'')
@@ -271,7 +284,7 @@
 
 
 class RESTOnlineHelpTopic(SourceTextOnlineHelpTopic):
-    """
+    r"""
     Represents a restructed text based Help Topic which has other
     filename extension then '.rst' or 'rest'.
 
@@ -302,8 +315,10 @@
 
     Test the help content.
 
-      >>> topic.source
-      'This is a ReST help!'
+      >>> topic.source.splitlines()[0]
+      u'This is a ReST help!'
+      >>> u'\u0444\u0430\u0439\u043b' in topic.source
+      True
 
     Resources can be added to an online help topic.
 
@@ -318,14 +333,9 @@
 
     type = 'zope.source.rest'
 
-    def __init__(self, id, title, path, parentPath, interface=None, view=None):
-        """Initialize object."""
-        super(RESTOnlineHelpTopic, self).__init__(id, title, path, parentPath,
-              interface, view)
 
-
 class STXOnlineHelpTopic(SourceTextOnlineHelpTopic):
-    """
+    r"""
     Represents a restructed text based Help Topic which has other
     filename extension then '.stx'.
 
@@ -356,8 +366,10 @@
 
     Test the help content.
 
-      >>> topic.source
-      'This is a STX help!'
+      >>> topic.source.splitlines()[0]
+      u'This is a STX help!'
+      >>> u'\u0444\u0430\u0439\u043b' in topic.source
+      True
 
     Resources can be added to an online help topic.
 
@@ -372,12 +384,7 @@
 
     type = 'zope.source.stx'
 
-    def __init__(self, id, title, path, parentPath, interface=None, view=None):
-        """Initialize object."""
-        super(STXOnlineHelpTopic, self).__init__(id, title, path, parentPath,
-              interface, view)
 
-
 class ZPTOnlineHelpTopic(BaseOnlineHelpTopic):
     r"""Represents a page template based Help Topic which has other
     filename extension then `.pt`.
@@ -416,8 +423,10 @@
       >>> request = TestRequest()
       >>> view = TestView(topic, request)
       >>> res = view.index()
-      >>> str(res).find('<body>This is a ZPT help!</body>') > 0
+      >>> u'<span>This is a ZPT help!</span>' in res
       True
+      >>> u'\u0444\u0430\u0439\u043b' in res
+      True
 
     Resources can be added to an online help topic.
 
@@ -430,12 +439,7 @@
 
     implements(IZPTOnlineHelpTopic)
 
-    def __init__(self, id, title, path, parentPath, interface=None, view=None):
-        """Initialize object."""
-        super(ZPTOnlineHelpTopic, self).__init__(id, title, path, parentPath,
-              interface, view)
 
-
 def OnlineHelpTopicFactory(name, schema, label, permission, layer,
                     template, default_template, bases, for_, fields,
                     fulledit_path=None, fulledit_label=None, menu=u''):

Modified: Zope3/trunk/src/zope/app/onlinehelp/tests/help.html
===================================================================
--- Zope3/trunk/src/zope/app/onlinehelp/tests/help.html	2005-11-06 10:29:33 UTC (rev 39943)
+++ Zope3/trunk/src/zope/app/onlinehelp/tests/help.html	2005-11-06 12:33:04 UTC (rev 39944)
@@ -1 +1 @@
-This is a STX help!
\ No newline at end of file
+This is a STX help!

Modified: Zope3/trunk/src/zope/app/onlinehelp/tests/help.pt
===================================================================
--- Zope3/trunk/src/zope/app/onlinehelp/tests/help.pt	2005-11-06 10:29:33 UTC (rev 39943)
+++ Zope3/trunk/src/zope/app/onlinehelp/tests/help.pt	2005-11-06 12:33:04 UTC (rev 39944)
@@ -1 +1,9 @@
-<html><head><title tal:content="context/title">Title</title></head><body>This is a ZPT help!</body></html>
\ No newline at end of file
+<html>
+  <head>
+    <title tal:content="context/title">Title</title>
+  </head>
+  <body>
+    <span>This is a ZPT help!</span>
+    <span>Russian (UTF-8): ZPT файл помощи!</span>
+  </body>
+</html>

Modified: Zope3/trunk/src/zope/app/onlinehelp/tests/help.rst
===================================================================
--- Zope3/trunk/src/zope/app/onlinehelp/tests/help.rst	2005-11-06 10:29:33 UTC (rev 39943)
+++ Zope3/trunk/src/zope/app/onlinehelp/tests/help.rst	2005-11-06 12:33:04 UTC (rev 39944)
@@ -1 +1,2 @@
-This is a ReST help!
\ No newline at end of file
+This is a ReST help!
+Russian (UTF-8): ReST файл помощи!

Modified: Zope3/trunk/src/zope/app/onlinehelp/tests/help.stx
===================================================================
--- Zope3/trunk/src/zope/app/onlinehelp/tests/help.stx	2005-11-06 10:29:33 UTC (rev 39943)
+++ Zope3/trunk/src/zope/app/onlinehelp/tests/help.stx	2005-11-06 12:33:04 UTC (rev 39944)
@@ -1 +1,2 @@
-This is a STX help!
\ No newline at end of file
+This is a STX help!
+Russian (UTF-8): STX файл помощи!

Modified: Zope3/trunk/src/zope/app/onlinehelp/tests/help2.txt
===================================================================
--- Zope3/trunk/src/zope/app/onlinehelp/tests/help2.txt	2005-11-06 10:29:33 UTC (rev 39943)
+++ Zope3/trunk/src/zope/app/onlinehelp/tests/help2.txt	2005-11-06 12:33:04 UTC (rev 39944)
@@ -1 +1,2 @@
-This is another help!
\ No newline at end of file
+This is another help!
+Russian (UTF-8): Еще один файл помощи!



More information about the Zope3-Checkins mailing list