Back to index

plone3  3.1.7
unicodeFallbackPatch.py
Go to the documentation of this file.
00001 # The following hacks make sure that Unicode and utf-8 encoded strings can be
00002 # mixed in all page templates and tal snippets.
00003 
00004 # While the general direction is to require Unicode in all places, we need to
00005 # provide a gentle evolution path, as we cannot radically change this
00006 # requirement and end up with lots of broken code. Our strategy is to allow
00007 # only utf-8 encoded strings though in order to limit the performance impact
00008 # instead of supporting all encodings.
00009 
00010 # Therefor these patches will probably stay here for quite a while.
00011 
00012 # import hacks
00013 from unicodehacks import new__call__
00014 from unicodehacks import _nulljoin
00015 from unicodehacks import _unicode_replace
00016 from unicodehacks import FasterStringIO
00017 
00018 # import the poor victims of our monkey patches
00019 from zope.tal import talinterpreter
00020 from zope.tales import expressions
00021 from zope.pagetemplate import pagetemplate
00022 from Products.Five import i18n
00023 
00024 # Enable use of utf-8 text in tales inserts, until all code is changed to use
00025 # pure Unicode only. This will only work for sites with a portal encoding of
00026 # utf-8 but it will give us some time to change Archetypes and Plone
00027 talinterpreter.unicode = _unicode_replace
00028 
00029 # Patch Five's translation service to allow encoded strings as msgids
00030 i18n.unicode = _unicode_replace
00031 
00032 # Deal with the case where Unicode and encoded strings occur on the same tag.
00033 talinterpreter._nulljoin_old = talinterpreter._nulljoin
00034 talinterpreter._nulljoin = _nulljoin
00035 
00036 # Deal with the case of tal snippets encoded as utf-8 and those being Unicode.
00037 # These are joined using a the getValue method of a StringIO class.
00038 talinterpreter.TALInterpreter.StringIO = FasterStringIO
00039 pagetemplate.StringIO = FasterStringIO
00040 
00041 # Deal with the case of unicode tal expressions that have included parts
00042 # encoded in utf-8. For example u'string:Select $item_title_or_id' where
00043 # item_title_or_id is encoded in utf-8
00044 expressions.StringExpr._old_call = expressions.StringExpr.__call__
00045 expressions.StringExpr.__call__ = new__call__