Commit c3653237 authored by 's avatar

- replaced getattr by aq_get

- whitespace cleanup
parent 1f35ed1d
...@@ -35,6 +35,9 @@ Restructuring ...@@ -35,6 +35,9 @@ Restructuring
Bugs Fixed 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. - Object managers should evaluate to True in a boolean test.
2.12.0a1 (2009-02-26) 2.12.0a1 (2009-02-26)
......
...@@ -10,16 +10,21 @@ ...@@ -10,16 +10,21 @@
# FOR A PARTICULAR PURPOSE # FOR A PARTICULAR PURPOSE
# #
############################################################################## ##############################################################################
"""Unicode conflict resolution.
$Id$
"""
import sys import sys
from Acquisition import aq_get
from Products.PageTemplates.interfaces import IUnicodeEncodingConflictResolver
from zope.interface import implements from zope.interface import implements
from zope.i18n.interfaces import IUserPreferredCharsets from zope.i18n.interfaces import IUserPreferredCharsets
from Products.PageTemplates.interfaces import IUnicodeEncodingConflictResolver
default_encoding = sys.getdefaultencoding() default_encoding = sys.getdefaultencoding()
class DefaultUnicodeEncodingConflictResolver: class DefaultUnicodeEncodingConflictResolver:
""" This resolver implements the old-style behavior and will """ This resolver implements the old-style behavior and will
raise an exception in case of the string 'text' can't be converted raise an exception in case of the string 'text' can't be converted
...@@ -53,6 +58,7 @@ class Z2UnicodeEncodingConflictResolver: ...@@ -53,6 +58,7 @@ class Z2UnicodeEncodingConflictResolver:
encoding = getattr(context, 'management_page_charset', default_encoding) encoding = getattr(context, 'management_page_charset', default_encoding)
return unicode(text, encoding, self.mode) return unicode(text, encoding, self.mode)
class PreferredCharsetResolver: class PreferredCharsetResolver:
""" A resolver that tries use the encoding information """ A resolver that tries use the encoding information
from the HTTP_ACCEPT_CHARSET header. from the HTTP_ACCEPT_CHARSET header.
...@@ -62,7 +68,7 @@ class PreferredCharsetResolver: ...@@ -62,7 +68,7 @@ class PreferredCharsetResolver:
def resolve(self, context, text, expression): 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. # Deal with the fact that a REQUEST is not always available.
# In this case fall back to the encoding of the ZMI and the # In this case fall back to the encoding of the ZMI and the
...@@ -74,7 +80,7 @@ class PreferredCharsetResolver: ...@@ -74,7 +80,7 @@ class PreferredCharsetResolver:
if management_charset: if management_charset:
charsets.insert(0, management_charset) charsets.insert(0, management_charset)
else: else:
# charsets might by cached within the request # charsets might by cached within the request
charsets = getattr(request, '__zpt_available_charsets', None) charsets = getattr(request, '__zpt_available_charsets', None)
# No uncached charsets found: investigate the HTTP_ACCEPT_CHARSET # No uncached charsets found: investigate the HTTP_ACCEPT_CHARSET
...@@ -86,12 +92,12 @@ class PreferredCharsetResolver: ...@@ -86,12 +92,12 @@ class PreferredCharsetResolver:
charsets = list() charsets = list()
# add Python's default encoding as last fallback # 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 # include the charsets based on the HTTP_ACCEPT_CHARSET
# header # header
charsets = IUserPreferredCharsets(request).getPreferredCharsets() +\ charsets = IUserPreferredCharsets(request).getPreferredCharsets() +\
charsets charsets
# cache list of charsets # cache list of charsets
request.__zpt_available_charsets = charsets request.__zpt_available_charsets = charsets
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment