Commit 9a25bc04 authored by Arnaud Fontaine's avatar Arnaud Fontaine Committed by Jérome Perrin

zope4: ZServer removal: Remove Publisher monkey patches.

parent e6ad58fb
......@@ -94,9 +94,6 @@ from Products.ERP5Type.patches import OFSFile
from Products.ERP5Type.patches import ZSQLMethod
from Products.ERP5Type.patches import MimetypesRegistry
from Products.ERP5Type.patches import users
if six.PY2:
# No ZServer
from Products.ERP5Type.patches import Publish
from Products.ERP5Type.patches import WSGITask
if six.PY2:
# XXX-zope4py3: urllib2 removed (see future/backports/urllib/request.py)
......
This diff is collapsed.
......@@ -25,7 +25,7 @@ from DocumentTemplate.DT_String import String
# Import from Localizer
import six
if six.PY2:
from .patches import get_request
from . import patches as _
from . import Localizer, MessageCatalog
from .LocalFiles import LocalDTMLFile
......
......@@ -18,70 +18,15 @@
This is a hotfix, it dynamically applies several patches to Zope.
"""
# Import from the Standard Library
import logging
import os
import six
# Import from itools
from .itools.i18n import AcceptLanguageType
# Import from Zope
from ZPublisher.HTTPRequest import HTTPRequest
from zope.globalrequest import clearRequest, setRequest
from zope.globalrequest import getRequest as get_request
# Flag
patch = False
Z_DEBUG_MODE = os.environ.get('Z_DEBUG_MODE') == '1'
logger = logging.getLogger('Localizer')
# PATCH 1: Global Request
#
# The original purpose was to get the request object from places where the
# acquisition was disabled (within the __of__ method for example). It was
# inspired by the Tim McLaughlin's GlobalGetRequest proposal, see
# http://dev.zope.org/Wikis/DevSite/Proposals/GlobalGetRequest
#
# Currently it keeps a Context instance, which wraps the request object,
# but also other things, like the user's session, as it is required by
# the ikaaro CMS.
#
# The request objects are stored in a dictionary in the Publish module,
# whose keys are the thread id.
#
# Also, we keep the get_request method in the Globals module for backwards
# compatibility (with TranslationService for example).
def get_new_publish(zope_publish):
def publish(request, *args, **kwargs):
try:
setRequest(request)
return zope_publish(request, *args, **kwargs)
finally:
clearRequest()
return publish
if patch is False:
patch = True
if six.PY2: # ZServer-specific patch
logger.info('Install "Globals.get_request".')
# Apply the patch
from ZPublisher import Publish
Publish.publish = get_new_publish(Publish.publish)
# Add to Globals for backwards compatibility
import Globals
Globals.get_request = get_request
# PATCH 2: Accept
# Accept
#
# Adds the variable AcceptLanguage to the REQUEST. It provides a higher
# level interface than HTTP_ACCEPT_LANGUAGE.
......@@ -110,7 +55,7 @@ def new_processInputs(self):
self.other['AcceptLanguage'] = accept_language
if patch:
if not patch:
HTTPRequest.old_processInputs = HTTPRequest.processInputs
HTTPRequest.processInputs = new_processInputs
patch = True
......@@ -22,10 +22,6 @@ from .itools.i18n import AcceptLanguageType, init_language_selector
# Import from Zope
from App.Common import package_home
# Import from Localizer
from .patches import get_request
# Package home
ph = package_home(globals())
......@@ -42,7 +38,8 @@ def lang_negotiator(available_languages):
the list of available languages. Returns the first user pref. language
that is available, if none is available returns None.
"""
request = get_request()
from zope.globalrequest import getRequest
request = getRequest()
if request is None:
return None
......
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