[Zope-Checkins] SVN: Zope/trunk/ - replaced getattr by aq_get

Yvo Schubbe y.2009 at wcm-solutions.de
Sun Mar 8 10:09:12 EDT 2009


Log message for revision 97666:
  - replaced getattr by aq_get
  - whitespace cleanup

Changed:
  U   Zope/trunk/doc/CHANGES.rst
  U   Zope/trunk/src/Products/PageTemplates/unicodeconflictresolver.py

-=-
Modified: Zope/trunk/doc/CHANGES.rst
===================================================================
--- Zope/trunk/doc/CHANGES.rst	2009-03-08 13:30:52 UTC (rev 97665)
+++ Zope/trunk/doc/CHANGES.rst	2009-03-08 14:09:12 UTC (rev 97666)
@@ -35,6 +35,9 @@
 Bugs Fixed
 ++++++++++
 
+- PageTemplates: Made PreferredCharsetResolver work with new kinds of contexts
+  that are not acquisition wrapped.
+
 - Object managers should evaluate to True in a boolean test.
 
 2.12.0a1 (2009-02-26)

Modified: Zope/trunk/src/Products/PageTemplates/unicodeconflictresolver.py
===================================================================
--- Zope/trunk/src/Products/PageTemplates/unicodeconflictresolver.py	2009-03-08 13:30:52 UTC (rev 97665)
+++ Zope/trunk/src/Products/PageTemplates/unicodeconflictresolver.py	2009-03-08 14:09:12 UTC (rev 97666)
@@ -10,16 +10,21 @@
 # FOR A PARTICULAR PURPOSE
 #
 ##############################################################################
+"""Unicode conflict resolution.
 
+$Id$
+"""
+
 import sys
 
+from Acquisition import aq_get
+from Products.PageTemplates.interfaces import IUnicodeEncodingConflictResolver
 from zope.interface import implements
 from zope.i18n.interfaces import IUserPreferredCharsets
 
-from Products.PageTemplates.interfaces import IUnicodeEncodingConflictResolver
-
 default_encoding = sys.getdefaultencoding()
 
+
 class DefaultUnicodeEncodingConflictResolver:
     """ This resolver implements the old-style behavior and will 
         raise an exception in case of the string 'text' can't be converted
@@ -53,6 +58,7 @@
             encoding = getattr(context, 'management_page_charset', default_encoding)
             return unicode(text, encoding, self.mode)
 
+
 class PreferredCharsetResolver:
     """ A resolver that tries use the encoding information
         from the HTTP_ACCEPT_CHARSET header.
@@ -62,7 +68,7 @@
 
     def resolve(self, context, text, expression):
 
-        request = getattr(context, 'REQUEST', None)
+        request = aq_get(context, 'REQUEST', None)
 
         # Deal with the fact that a REQUEST is not always available.
         # In this case fall back to the encoding of the ZMI and the
@@ -74,7 +80,7 @@
             if management_charset:
                 charsets.insert(0, management_charset)
         else:
-            # charsets might by cached within the request            
+            # charsets might by cached within the request
             charsets = getattr(request, '__zpt_available_charsets', None)
 
         # No uncached charsets found: investigate the HTTP_ACCEPT_CHARSET
@@ -86,12 +92,12 @@
             charsets = list()
 
             # add Python's default encoding as last fallback
-            charsets.append(default_encoding)               
+            charsets.append(default_encoding)
 
             # include the charsets based on the HTTP_ACCEPT_CHARSET
             # header
             charsets = IUserPreferredCharsets(request).getPreferredCharsets() +\
-                       charsets                    
+                       charsets
 
             # cache list of charsets
             request.__zpt_available_charsets = charsets



More information about the Zope-Checkins mailing list