[Checkins] SVN: zope3org/trunk/src/zorg/ Fixed an encoding warning

Uwe Oestermeier uwe_oestermeier at iwm-kmrc.de
Tue Mar 28 11:33:07 EST 2006


Log message for revision 66243:
  Fixed an encoding warning

Changed:
  U   zope3org/trunk/src/zorg/restsupport/tests.py
  U   zope3org/trunk/src/zorg/tinymcesupport/tiny_mce/tiny_mce_src.js
  U   zope3org/trunk/src/zorg/wikification/browser/wikilink.py
  U   zope3org/trunk/src/zorg/wikification/browser/wikipage.py

-=-
Modified: zope3org/trunk/src/zorg/restsupport/tests.py
===================================================================
--- zope3org/trunk/src/zorg/restsupport/tests.py	2006-03-28 16:29:33 UTC (rev 66242)
+++ zope3org/trunk/src/zorg/restsupport/tests.py	2006-03-28 16:33:06 UTC (rev 66243)
@@ -50,7 +50,7 @@
 <html><body><p><i>Test</i> paragraph</p> 
     <ul>
     <li>1. Text</li>
-    <li>2. Text&nbsp;</li>
+    <li>2. Text</li>
     </ul>
 </body></html>"""
 
@@ -88,10 +88,9 @@
     <BLANKLINE>
     * 1. Text
     <BLANKLINE>
-    * 2. TextÊ
+    * 2. Text
     <BLANKLINE>
 
-
     """
     
 

Modified: zope3org/trunk/src/zorg/tinymcesupport/tiny_mce/tiny_mce_src.js
===================================================================
--- zope3org/trunk/src/zorg/tinymcesupport/tiny_mce/tiny_mce_src.js	2006-03-28 16:29:33 UTC (rev 66242)
+++ zope3org/trunk/src/zorg/tinymcesupport/tiny_mce/tiny_mce_src.js	2006-03-28 16:33:06 UTC (rev 66243)
@@ -505,7 +505,7 @@
 
 	triggerSave : function(skip_cleanup, skip_callback) {
 		var inst, n;
-
+        
 		// Default to false
 		if (typeof(skip_cleanup) == "undefined")
 			skip_cleanup = false;

Modified: zope3org/trunk/src/zorg/wikification/browser/wikilink.py
===================================================================
--- zope3org/trunk/src/zorg/wikification/browser/wikilink.py	2006-03-28 16:29:33 UTC (rev 66242)
+++ zope3org/trunk/src/zorg/wikification/browser/wikilink.py	2006-03-28 16:33:06 UTC (rev 66243)
@@ -117,6 +117,40 @@
         
     command = None
     
+    _url = r'''(?=[a-zA-Z0-9./#])    # Must start correctly
+                  ((?:              # Match the leading part
+                      (?:ftp|https?|telnet|nntp) #     protocol
+                      ://                        #     ://
+                      (?:                       # Optional 'username:password@'
+                          \w+                   #         username
+                          (?::\w+)?             #         optional :password
+                          @                     #         @
+                      )?                        # 
+                      [-\w]+(?:\.\w[-\w]*)+     #  hostname (sub.example.com)
+                  )                             #
+                  (?::\d+)?                     # Optional port number
+                  (?:                           # Rest of the URL, optional
+                      /?                                # Start with '/'
+                      [^.!,?;:"'<>()\[\]{}\s\x7F-\xFF]* # Can't start with these
+                      (?:                               #
+                          [.!,?;:]+                     #  One or more of these
+                          [^.!,?;:"'<>()\[\]{}\s\x7F-\xFF]+  # Can't finish
+                          #'"                           #  # or ' or "
+                      )*                                #
+                  )?)                                   #
+               '''
+
+    _email = r'''(?:mailto:)?            # Optional mailto:
+                    ([-\+\w]+               # username
+                    \@                      # at
+                    [-\w]+(?:\.\w[-\w]*)+)  # hostname
+                 '''
+    
+    url_link = re.compile(_url, re.VERBOSE)
+    email_link = re.compile(_email, re.VERBOSE)
+    text_link = re.compile('\[.*?\]', re.VERBOSE)
+
+
     def __init__(self, page) :
         BaseHTMLProcessor.__init__(self)
         self.page = page
@@ -306,19 +340,32 @@
         >>> link_processor.pieces
         ['A <a ...>[link]</a> and <a ...>[another one]</a>']
         
+        This method also converts urls and email addresses into clickable links:
         
+        >>> link_processor = BaseLinkProcessor(page)
+        >>> link_processor.handle_data('Test mailto:jim at zope.org')
+        >>> link_processor.pieces
+        ['Test <a href="mailto:jim at zope.org">jim at zope.org</a>']
+        
+        >>> link_processor = BaseLinkProcessor(page)
+        >>> link_processor.handle_data('Test http://www.iwm-kmrc.de')
+        >>> link_processor.pieces
+        ['Test <a href="http://www.iwm-kmrc.de">http://www.iwm-kmrc.de</a>']
+        
         """
                  
         if self.placeholder is not None :
             self.placeholder.label += text
             self.pieces.append(text)
             return
-
-        text_link = re.compile('\[.*?\]', re.VERBOSE)
+            
         
+        text = re.sub(self.url_link, r'''<a href="\1">\1</a>''', text)
+        text = re.sub(self.email_link, r'''<a href="mailto:\1">\1</a>''', text)
+        
         result = ""
         end = 0
-        for m in text_link.finditer(text):
+        for m in self.text_link.finditer(text):
             
             start = m.start()
             result += text[end:start]

Modified: zope3org/trunk/src/zorg/wikification/browser/wikipage.py
===================================================================
--- zope3org/trunk/src/zorg/wikification/browser/wikipage.py	2006-03-28 16:29:33 UTC (rev 66242)
+++ zope3org/trunk/src/zorg/wikification/browser/wikipage.py	2006-03-28 16:33:06 UTC (rev 66243)
@@ -106,7 +106,19 @@
     def getContainer(self) :
         """ Returns the base container. Should be overwritten. """
         return None
-                           
+        
+    def getAbstract(self) :
+        """ Returns the abstract resp. description. """
+        file = self.getFile()
+        if file is not None :
+            return IZopeDublinCore(file).description or u""
+        return u""
+
+    def renderAbstract(self) :
+        """ Render the abstract as ReST. """
+        desc = self.getAbstract()
+        return rest2html(desc)
+        
     def wikify(self, body) :
         """ 
             Renders HTML with dead relative links as 'wikified' HTML,
@@ -186,8 +198,7 @@
         if file :
             page = WikiFilePage(file, self.request, self.getContainer())
             return page.getBody()
-            
-            
+      
     def renderBody(self, debug=False) :
         """ Delegates the rendering to the WikiFilePage of the 
             index.html doocument.
@@ -251,21 +262,42 @@
     asType = "text/plain"
     
     title = description = None
+    
+    def asHTML(self, data) :
+        if self.isType == "text/plain" :
+            return rest2html(data)
+        elif self.isType == "text/html" :
+            return data
+        return _("unknown format: cannot convert content. """)
 
     def toHTML(self) :
+        return self.asHTML(self.data)
+
+    def asRest(self, data, fragment=False) :
         if self.isType == "text/plain" :
-            return rest2html(self.data)
+            return data
         elif self.isType == "text/html" :
-            return self.data
-        return _("unknown format: cannot convert file content. """)
+            return html2rest(data, fragment) 
+        return _("unknown format: cannot convert content. """)
         
     def toRest(self) :
-        if self.isType == "text/plain" :
-            return self.data
-        elif self.isType == "text/html" :
-            return html2rest(self.data) 
-        return _("unknown format: cannot convert file content. """)
+        return self.asRest(self.data)
         
+    def asContentType(self, data) :
+        """ Return data as selected content type. """
+        if self.asType == "text/html" :
+            return self.asHTML(data)
+        elif self.asType == "text/plain" :
+            return self.asRest(data)
+        return None
+        
+    def asDisplayType(self, ascii) :
+        if self.isType == "text/html" :
+            return rest2html(ascii)
+        elif self.isType == "text/plain" :
+            return ascii
+        return None
+        
     def saveTo(self, file) :
         """ 
         Save method that stores the main content and sets
@@ -394,8 +426,8 @@
     def render(self) :
         """ Presents the rest editor to the user. """
         return self._rest()    
+        
 
-
 class TinyMCEEditor(Editor) :
     """ Main page element that shows a TineMCE editor. """
     
@@ -531,6 +563,12 @@
         file = self.getFile()
         dc = IZopeDublinCore(file, None)
         return (dc and dc.title) or u"Untitled"
+        
+    def editableAbstract(self) :
+        """ Returns the abstract that should be edited. """
+        file = self.getFile()
+        dc = IZopeDublinCore(file, None)
+        return (dc and self.main.asDisplayType(dc.description)) or u""
                 
     def display(self) :
         """ Returns the data that should be edited. """
@@ -572,7 +610,15 @@
         if self.isAddView() or self.getFile() is None :
             return u"Untitled"
         return IZopeDublinCore(self.getFile()).title
+
+    def editableAbstract(self) :
+        """ Returns the abstract that should be edited. """
+        if self.isAddView() or self.getFile() is None :
+            return u""
+        dc = IZopeDublinCore(self.getFile())
+        return self.main.asDisplayType(dc.description)
         
+
     def display(self) :
         """ Returns the data that should be edited. """
         if self.isAddView() or self.getFile() is None :



More information about the Checkins mailing list