[Erp5-report] r17342 - /erp5/trunk/products/TimerService/timerserver/TimerServer.py

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Nov 1 11:37:32 CET 2007


Author: jerome
Date: Thu Nov  1 11:37:31 2007
New Revision: 17342

URL: http://svn.erp5.org?rev=17342&view=rev
Log:
Make TimerResponse support _encode_unicode like HTTPResponse, this is required
to use page templates with unicode.

Modified:
    erp5/trunk/products/TimerService/timerserver/TimerServer.py

Modified: erp5/trunk/products/TimerService/timerserver/TimerServer.py
URL: http://svn.erp5.org/erp5/trunk/products/TimerService/timerserver/TimerServer.py?rev=17342&r1=17341&r2=17342&view=diff
==============================================================================
--- erp5/trunk/products/TimerService/timerserver/TimerServer.py (original)
+++ erp5/trunk/products/TimerService/timerserver/TimerServer.py Thu Nov  1 11:37:31 2007
@@ -6,6 +6,7 @@
 import traceback
 
 import thread
+import re
 import sys, os, errno, time, socket
 from StringIO import StringIO
 from zLOG import LOG, INFO
@@ -14,6 +15,7 @@
 from ZPublisher.BaseRequest import BaseRequest
 from ZPublisher.BaseResponse import BaseResponse
 from ZPublisher.HTTPRequest import HTTPRequest
+import ZPublisher.HTTPRequest
 
 class TimerServer:
     def __init__(self, module, interval=600):
@@ -98,6 +100,25 @@
     def unauthorized(self):
         pass
 
+    # This is taken from ZPublisher.HTTPResponse
+    # I don't think it's safe to make TimerResponse a subclass of HTTPResponse,
+    # so I inline here the method . This is required it you want unicode page
+    # templates to be usable by timer service.
+    # This is used by an iHotFix patch on PageTemplate.StringIO method
+    def _encode_unicode(self, body,
+                        charset_re=re.compile(r'(?:application|text)/[-+0-9a-z]+\s*;\s*' +
+                                              r'charset=([-_0-9a-z]+' +
+                                              r')(?:(?:\s*;)|\Z)',
+                                              re.IGNORECASE)):
+        # Encode the Unicode data as requested
+        if self.headers.has_key('content-type'):
+            match = charset_re.match(self.headers['content-type'])
+            if match:
+                encoding = match.group(1)
+                return body.encode(encoding)
+        # Use the default character encoding
+        return body.encode(ZPublisher.HTTPResponse.default_encoding,'replace')
+
 
 class TimerRequest(HTTPRequest):
 




More information about the Erp5-report mailing list