Author: bree
Date: Thu Mar  9 18:35:41 2006
New Revision: 2561

Modified:
   azax/branches/snowsprint/__init__.py
   azax/branches/snowsprint/azaxview.py
Log:
Handle unicode in azax response

Modified: azax/branches/snowsprint/__init__.py
==============================================================================
--- azax/branches/snowsprint/__init__.py        (original)
+++ azax/branches/snowsprint/__init__.py        Thu Mar  9 18:35:41 2006
@@ -3,3 +3,4 @@
 mimetypes.types_map['.kkt'] = 'text/xml' 
 
 from azaxview import AzaxBaseView
+from unicode_quirks import force_unicode

Modified: azax/branches/snowsprint/azaxview.py
==============================================================================
--- azax/branches/snowsprint/azaxview.py        (original)
+++ azax/branches/snowsprint/azaxview.py        Thu Mar  9 18:35:41 2006
@@ -23,6 +23,7 @@
 from zope.interface import implements
 from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
 from Products.Five import BrowserView
+from unicode_quirks import force_unicode
 
 import htmlentitydefs
 import re
@@ -47,10 +48,11 @@
     from BeautifulSoup import BeautifulStoneSoup
     
     def __init__(self, value):
+        value = force_unicode(value)
         self.soup = self.BeautifulStoneSoup(value)
 
     def __call__(self):
-        return str(self.soup)
+        return unicode(self.soup)
         
 class HtmlParser(object):
     '''Custom HTML parser
@@ -61,12 +63,13 @@
     from BeautifulSoup import BeautifulSoup
     
     def __init__(self, value):
+        value = force_unicode(value)
         self.soup = self.BeautifulSoup(value)
         for tag in self.soup.fetch(recursive=False):
             tag['xmlns'] = "http://www.w3.org/1999/xhtml";
 
     def __call__(self):
-        return str(self.soup)
+        return unicode(self.soup)
         
 # --
 # Marshal objects
@@ -79,7 +82,8 @@
     
     def __init__(self, name, content=''):
         self.name = name
-        self.content = content
+        # Content must be str with ascii encoding, or unicode!
+        self.content = force_unicode(content)
 
     def getName(self):
         return self.name
@@ -155,7 +159,7 @@
     """
     
     # XML output gets rendered via a page template
-    _render = ViewPageTemplateFile('browser/kukitresponse.pt', 
content_type='text/xml')
+    _render = ViewPageTemplateFile('browser/kukitresponse.pt', 
content_type='text/xml;charset=utf-8')
 
     # replace named entities to fix a bug in IE
     def render(self):
@@ -167,7 +171,8 @@
             return "&#%i;" % value
 
         result = self._render()
-        return _entity_regexp.sub(entity_replacer, result)
+        result = _entity_regexp.sub(entity_replacer, result)
+        return result
 
     def __init__(self, context, request):
         BrowserView.__init__(self, context, request)
-- 
http://lists.nuxeo.com/mailman/listinfo/z3lab-checkins

Reply via email to