1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
|
# -*- coding: iso-8859-1 -*-
# Copyright (C) 2000-2002 Juan David Ibez Palomar <j-david@noos.fr>
# (this copyright notice is encoding in ISO-8859-1 (Latin1))
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# PATCH 1
#
# Makes REQUEST available from the Globals module.
#
# It's needed because context is not available in the __of__ method,
# so we can't get REQUEST with acquisition. And we need REQUEST for
# local properties (see LocalPropertyManager.pu).
#
# This patch is at the beginning to be sure code that requires it
# doesn't breaks.
#
# This pach is inspired in a similar patch by Tim McLaughlin, see
# "http://dev.zope.org/Wikis/DevSite/Proposals/GlobalGetRequest".
# Thanks Tim!!
#
from thread import get_ident
from traceback import format_stack
from ZPublisher import Publish, mapply
import Globals
from utils import log, INFO, BLATHER, PROBLEM
def get_request():
"""Get a request object"""
return Publish._requests.get(get_ident(), None)
def new_publish(request, module_name, after_list, debug=0):
Publish._requests[get_ident()] = request
x = Publish.old_publish(request, module_name, after_list, debug)
try:
del Publish._requests[get_ident()]
except KeyError:
# already deleted?
pass
return x
def applyRequestPatch():
if not hasattr(Publish, '_requests'):
log('Applying patch', severity=INFO,
detail='*** Patching ZPublisher.Publish with the get_request patch! ***')
# Apply patch
Publish._requests = {}
Publish.old_publish = Publish.publish
Publish.publish = new_publish
Globals.get_request = get_request
applyRequestPatch()
# PATCH 2
#
# Fix uses of StringIO with a Unicode-aware StringIO
#
from Products.PageTemplates.PageTemplate import PageTemplate
from TAL.TALInterpreter import TALInterpreter
from FasterStringIO import FasterStringIO
if hasattr(TALInterpreter, 'StringIO'):
# Simply patch the StringIO method of TALInterpreter and PageTemplate
# on a new Zope
def patchedStringIO(self):
return FasterStringIO()
TALInterpreter.StringIO = patchedStringIO
PageTemplate.StringIO = patchedStringIO
|