[Checkins] SVN: z3c.soap/trunk/z3c/soap/ Adapted monkey patches to Zope 2.13.19
Gauthier Bastien
cvs-admin at zope.org
Tue Jan 29 16:23:33 UTC 2013
Log message for revision 129114:
Adapted monkey patches to Zope 2.13.19
Changed:
U z3c.soap/trunk/z3c/soap/HTTPRequest.py
U z3c.soap/trunk/z3c/soap/patch.py
-=-
Modified: z3c.soap/trunk/z3c/soap/HTTPRequest.py
===================================================================
--- z3c.soap/trunk/z3c/soap/HTTPRequest.py 2013-01-29 11:44:07 UTC (rev 129113)
+++ z3c.soap/trunk/z3c/soap/HTTPRequest.py 2013-01-29 16:23:32 UTC (rev 129114)
@@ -1,18 +1,17 @@
##############################################################################
#
-# Copyright (c) 2001 Zope Foundation and Contributors.
+# Copyright (c) 2002-2009 Zope Foundation and Contributors.
+# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
-# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
-# FOR A PARTICULAR PURPOSE
+# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-__version__='$Revision: 1.90.2.6 $'[11:-2]
-
import re
from cgi import FieldStorage, escape
from ZPublisher.Converters import get_converter
@@ -30,7 +29,7 @@
DEFAULT=2,
RECORD=4,
RECORDS=8,
- REC=12, # RECORD|RECORDS
+ REC=12, # RECORD | RECORDS
EMPTY=16,
CONVERTED=32,
hasattr=hasattr,
@@ -43,21 +42,30 @@
We need to delay input parsing so that it is done under
publisher control for error handling purposes.
"""
- response=self.response
- environ=self.environ
- method=environ.get('REQUEST_METHOD','GET')
+ response = self.response
+ environ = self.environ
+ method = environ.get('REQUEST_METHOD','GET')
- if method != 'GET': fp=self.stdin
- else: fp=None
+ if method != 'GET':
+ fp = self.stdin
+ else:
+ fp = None
- form=self.form
- other=self.other
- taintedform=self.taintedform
+ form = self.form
+ other = self.other
+ taintedform = self.taintedform
+ # If 'QUERY_STRING' is not present in environ
+ # FieldStorage will try to get it from sys.argv[1]
+ # which is not what we need.
+ if 'QUERY_STRING' not in environ:
+ environ['QUERY_STRING'] = ''
- meth=None
- fs=FieldStorage(fp=fp,environ=environ,keep_blank_values=1)
+ meth = None
+ fs = ZopeFieldStorage(fp=fp,environ=environ,keep_blank_values=1)
if not hasattr(fs,'list') or fs.list is None:
+
+ # XXX begin monkeypatch
contentType = None
if fs.headers.has_key('content-type'):
contentType = fs.headers['content-type']
@@ -93,33 +101,37 @@
other['RESPONSE'] = self.response = response
other['REQUEST_METHOD'] = method
self.maybe_webdav_client = 0
+ # XXX end monkeypatch
+ # Stash XML request for interpretation by a SOAP-aware view
+ other['SOAPXML'] = fs.value
# Hm, maybe it's an XML-RPC
- # check for a real XML-RPC methodCall !
- # This allows to post normal text/xml files to Zope !
- elif (contentType == 'text/xml' and method == 'POST' and fs.value.find('<methodCall>') > 0):
+ elif ('content-type' in fs.headers and
+ 'text/xml' in fs.headers['content-type'] and
+ method == 'POST'):
# Ye haaa, XML-RPC!
global xmlrpc
- if xmlrpc is None: from ZPublisher import xmlrpc
+ if xmlrpc is None:
+ from ZPublisher import xmlrpc
meth, self.args = xmlrpc.parse_input(fs.value)
- response=xmlrpc.response(response)
- other['RESPONSE']=self.response=response
+ response = xmlrpc.response(response)
+ other['RESPONSE'] = self.response = response
self.maybe_webdav_client = 0
else:
- self._file=fs.file
+ self._file = fs.file
else:
- fslist=fs.list
- tuple_items={}
- lt=type([])
- CGI_name=isCGI_NAME
- defaults={}
- tainteddefaults={}
- converter=None
+ fslist = fs.list
+ tuple_items = {}
+ lt = type([])
+ CGI_name = isCGI_NAMEs
+ defaults = {}
+ tainteddefaults = {}
+ converter = None
for item in fslist:
isFileUpload = 0
- key=item.name
+ key = item.name
if (hasattr(item,'file') and hasattr(item,'filename')
and hasattr(item,'headers')):
if (item.file and
@@ -127,12 +139,12 @@
# RFC 1867 says that all fields get a content-type.
# or 'content-type' in map(lower, item.headers.keys())
)):
- item=FileUpload(item)
+ item = FileUpload(item)
isFileUpload = 1
else:
- item=item.value
+ item = item.value
- flags=0
+ flags = 0
character_encoding = ''
# Variables for potentially unsafe values.
tainted = None
@@ -147,55 +159,64 @@
# a re search.
- l=key.rfind(':')
+ l = key.rfind(':')
if l >= 0:
mo = search_type(key,l)
- if mo: l=mo.start(0)
- else: l=-1
+ if mo:
+ l = mo.start(0)
+ else:
+ l = -1
while l >= 0:
- type_name=key[l+1:]
- key=key[:l]
- c=get_converter(type_name, None)
+ type_name = key[l+1:]
+ key = key[:l]
+ c = get_converter(type_name, None)
if c is not None:
- converter=c
+ converter = c
converter_type = type_name
- flags=flags|CONVERTED
+ flags = flags | CONVERTED
elif type_name == 'list':
- flags=flags|SEQUENCE
+ flags = flags | SEQUENCE
elif type_name == 'tuple':
- tuple_items[key]=1
- flags=flags|SEQUENCE
+ tuple_items[key] = 1
+ flags = flags | SEQUENCE
elif (type_name == 'method' or type_name == 'action'):
- if l: meth=key
- else: meth=item
+ if l:
+ meth = key
+ else:
+ meth = item
elif (type_name == 'default_method' or type_name == \
'default_action'):
if not meth:
- if l: meth=key
- else: meth=item
+ if l:
+ meth = key
+ else:
+ meth = item
elif type_name == 'default':
- flags=flags|DEFAULT
+ flags = flags | DEFAULT
elif type_name == 'record':
- flags=flags|RECORD
+ flags = flags | RECORD
elif type_name == 'records':
- flags=flags|RECORDS
+ flags = flags | RECORDS
elif type_name == 'ignore_empty':
- if not item: flags=flags|EMPTY
+ if not item:
+ flags = flags | EMPTY
elif has_codec(type_name):
character_encoding = type_name
- l=key.rfind(':')
- if l < 0: break
- mo=search_type(key,l)
- if mo: l = mo.start(0)
- else: l = -1
+ l = key.rfind(':')
+ if l < 0:
+ break
+ mo = search_type(key,l)
+ if mo:
+ l = mo.start(0)
+ else:
+ l = -1
-
-
# Filter out special names from form:
- if CGI_name(key) or key[:5]=='HTTP_': continue
+ if key in CGI_name or key[:5] == 'HTTP_':
+ continue
# If the key is tainted, mark it so as well.
tainted_key = key
@@ -205,12 +226,13 @@
if flags:
# skip over empty fields
- if flags&EMPTY: continue
+ if flags & EMPTY:
+ continue
#Split the key and its attribute
- if flags&REC:
- key=key.split(".")
- key, attr=".".join(key[:-1]), key[-1]
+ if flags & REC:
+ key = key.split(".")
+ key, attr = ".".join(key[:-1]), key[-1]
# Update the tainted_key if necessary
tainted_key = key
@@ -224,19 +246,21 @@
escape(attr))
# defer conversion
- if flags&CONVERTED:
+ if flags & CONVERTED:
try:
if character_encoding:
- # We have a string with a specified character encoding.
- # This gets passed to the converter either as unicode, if it can
- # handle it, or crunched back down to latin-1 if it can not.
+ # We have a string with a specified character
+ # encoding. This gets passed to the converter
+ # either as unicode, if it can handle it, or
+ # crunched back down to latin-1 if it can not.
item = unicode(item,character_encoding)
if hasattr(converter,'convert_unicode'):
item = converter.convert_unicode(item)
else:
- item = converter(item.encode('iso-8859-15'))
+ item = converter(
+ item.encode(default_encoding))
else:
- item=converter(item)
+ item = converter(item)
# Flag potentially unsafe values
if converter_type in ('string', 'required', 'text',
@@ -255,18 +279,18 @@
tainted = None
except:
- if (not item and not (flags&DEFAULT) and
- defaults.has_key(key)):
+ if (not item and not (flags & DEFAULT) and
+ key in defaults):
item = defaults[key]
- if flags&RECORD:
- item=getattr(item,attr)
- if flags&RECORDS:
+ if flags & RECORD:
+ item = getattr(item,attr)
+ if flags & RECORDS:
item = getattr(item[-1], attr)
- if tainteddefaults.has_key(tainted_key):
+ if tainted_key in tainteddefaults:
tainted = tainteddefaults[tainted_key]
- if flags&RECORD:
+ if flags & RECORD:
tainted = getattr(tainted, attr)
- if flags&RECORDS:
+ if flags & RECORDS:
tainted = getattr(tainted[-1], attr)
else:
raise
@@ -281,7 +305,7 @@
tainted = item
#Determine which dictionary to use
- if flags&DEFAULT:
+ if flags & DEFAULT:
mapping_object = defaults
tainted_mapping = tainteddefaults
else:
@@ -289,8 +313,8 @@
tainted_mapping = taintedform
#Insert in dictionary
- if mapping_object.has_key(key):
- if flags&RECORDS:
+ if key in mapping_object:
+ if flags & RECORDS:
#Get the list and the last record
#in the list. reclist is mutable.
reclist = mapping_object[key]
@@ -298,17 +322,18 @@
if tainted:
# Store a tainted copy as well
- if not tainted_mapping.has_key(tainted_key):
+ if tainted_key not in tainted_mapping:
tainted_mapping[tainted_key] = deepcopy(
reclist)
treclist = tainted_mapping[tainted_key]
lastrecord = treclist[-1]
if not hasattr(lastrecord, attr):
- if flags&SEQUENCE: tainted = [tainted]
+ if flags & SEQUENCE:
+ tainted = [tainted]
setattr(lastrecord, attr, tainted)
else:
- if flags&SEQUENCE:
+ if flags & SEQUENCE:
getattr(lastrecord,
attr).append(tainted)
else:
@@ -316,7 +341,7 @@
setattr(newrec, attr, tainted)
treclist.append(newrec)
- elif tainted_mapping.has_key(tainted_key):
+ elif tainted_key in tainted_mapping:
# If we already put a tainted value into this
# recordset, we need to make sure the whole
# recordset is built.
@@ -325,10 +350,11 @@
copyitem = item
if not hasattr(lastrecord, attr):
- if flags&SEQUENCE: copyitem = [copyitem]
+ if flags & SEQUENCE:
+ copyitem = [copyitem]
setattr(lastrecord, attr, copyitem)
else:
- if flags&SEQUENCE:
+ if flags & SEQUENCE:
getattr(lastrecord,
attr).append(copyitem)
else:
@@ -339,10 +365,11 @@
if not hasattr(x,attr):
#If the attribute does not
#exist, setit
- if flags&SEQUENCE: item=[item]
+ if flags & SEQUENCE:
+ item = [item]
setattr(x,attr,item)
else:
- if flags&SEQUENCE:
+ if flags & SEQUENCE:
# If the attribute is a
# sequence, append the item
# to the existing attribute
@@ -352,45 +379,45 @@
else:
# Create a new record and add
# it to the list
- n=record()
+ n = record()
setattr(n,attr,item)
mapping_object[key].append(n)
- elif flags&RECORD:
- b=mapping_object[key]
- if flags&SEQUENCE:
- item=[item]
- if not hasattr(b,attr):
+ elif flags & RECORD:
+ b = mapping_object[key]
+ if flags & SEQUENCE:
+ item = [item]
+ if not hasattr(b, attr):
# if it does not have the
# attribute, set it
- setattr(b,attr,item)
+ setattr(b, attr, item)
else:
# it has the attribute so
# append the item to it
- setattr(b,attr,getattr(b,attr)+item)
+ setattr(b, attr, getattr(b, attr) + item)
else:
# it is not a sequence so
# set the attribute
- setattr(b,attr,item)
+ setattr(b, attr, item)
# Store a tainted copy as well if necessary
if tainted:
- if not tainted_mapping.has_key(tainted_key):
+ if tainted_key not in tainted_mapping:
tainted_mapping[tainted_key] = deepcopy(
mapping_object[key])
b = tainted_mapping[tainted_key]
- if flags&SEQUENCE:
+ if flags & SEQUENCE:
seq = getattr(b, attr, [])
seq.append(tainted)
setattr(b, attr, seq)
else:
setattr(b, attr, tainted)
- elif tainted_mapping.has_key(tainted_key):
+ elif tainted_key in tainted_mapping:
# If we already put a tainted value into this
# record, we need to make sure the whole record
# is built.
b = tainted_mapping[tainted_key]
- if flags&SEQUENCE:
+ if flags & SEQUENCE:
seq = getattr(b, attr, [])
seq.append(item)
setattr(b, attr, seq)
@@ -399,11 +426,11 @@
else:
# it is not a record or list of records
- found=mapping_object[key]
+ found = mapping_object[key]
if tainted:
# Store a tainted version if necessary
- if not tainted_mapping.has_key(tainted_key):
+ if tainted_key not in tainted_mapping:
copied = deepcopy(found)
if isinstance(copied, lt):
tainted_mapping[tainted_key] = copied
@@ -411,7 +438,7 @@
tainted_mapping[tainted_key] = [copied]
tainted_mapping[tainted_key].append(tainted)
- elif tainted_mapping.has_key(tainted_key):
+ elif tainted_key in tainted_mapping:
# We may already have encountered a tainted
# value for this key, and the tainted_mapping
# needs to hold all the values.
@@ -425,45 +452,51 @@
if type(found) is lt:
found.append(item)
else:
- found=[found,item]
- mapping_object[key]=found
+ found = [found,item]
+ mapping_object[key] = found
else:
# The dictionary does not have the key
- if flags&RECORDS:
+ if flags & RECORDS:
# Create a new record, set its attribute
# and put it in the dictionary as a list
a = record()
- if flags&SEQUENCE: item=[item]
+ if flags & SEQUENCE:
+ item = [item]
setattr(a,attr,item)
- mapping_object[key]=[a]
+ mapping_object[key] = [a]
if tainted:
# Store a tainted copy if necessary
a = record()
- if flags&SEQUENCE: tainted = [tainted]
+ if flags & SEQUENCE:
+ tainted = [tainted]
setattr(a, attr, tainted)
tainted_mapping[tainted_key] = [a]
- elif flags&RECORD:
+ elif flags & RECORD:
# Create a new record, set its attribute
# and put it in the dictionary
- if flags&SEQUENCE: item=[item]
- r = mapping_object[key]=record()
+ if flags & SEQUENCE:
+ item = [item]
+ r = mapping_object[key] = record()
setattr(r,attr,item)
if tainted:
# Store a tainted copy if necessary
- if flags&SEQUENCE: tainted = [tainted]
+ if flags & SEQUENCE:
+ tainted = [tainted]
r = tainted_mapping[tainted_key] = record()
setattr(r, attr, tainted)
else:
# it is not a record or list of records
- if flags&SEQUENCE: item=[item]
- mapping_object[key]=item
+ if flags & SEQUENCE:
+ item = [item]
+ mapping_object[key] = item
if tainted:
# Store a tainted copy if necessary
- if flags&SEQUENCE: tainted = [tainted]
+ if flags & SEQUENCE:
+ tainted = [tainted]
tainted_mapping[tainted_key] = tainted
else:
@@ -476,13 +509,13 @@
tainted = item
#Insert in dictionary
- if mapping_object.has_key(key):
+ if key in mapping_object:
# it is not a record or list of records
- found=mapping_object[key]
+ found = mapping_object[key]
if tainted:
# Store a tainted version if necessary
- if not taintedform.has_key(tainted_key):
+ if tainted_key not in taintedform:
copied = deepcopy(found)
if isinstance(copied, lt):
taintedform[tainted_key] = copied
@@ -493,7 +526,7 @@
taintedform[tainted_key]]
taintedform[tainted_key].append(tainted)
- elif taintedform.has_key(tainted_key):
+ elif tainted_key in taintedform:
# We may already have encountered a tainted value
# for this key, and the taintedform needs to hold
# all the values.
@@ -506,10 +539,10 @@
if type(found) is lt:
found.append(item)
else:
- found=[found,item]
- mapping_object[key]=found
+ found = [found,item]
+ mapping_object[key] = found
else:
- mapping_object[key]=item
+ mapping_object[key] = item
if tainted:
taintedform[tainted_key] = tainted
@@ -517,14 +550,15 @@
if defaults:
for key, value in defaults.items():
tainted_key = key
- if '<' in key: tainted_key = TaintedString(key)
+ if '<' in key:
+ tainted_key = TaintedString(key)
- if not form.has_key(key):
+ if key not in form:
# if the form does not have the key,
# set the default
- form[key]=value
+ form[key] = value
- if tainteddefaults.has_key(tainted_key):
+ if tainted_key in tainteddefaults:
taintedform[tainted_key] = \
tainteddefaults[tainted_key]
else:
@@ -536,13 +570,13 @@
r = form[key]
# First deal with tainted defaults.
- if taintedform.has_key(tainted_key):
+ if tainted_key in taintedform:
tainted = taintedform[tainted_key]
for k, v in tdefault.__dict__.items():
if not hasattr(tainted, k):
setattr(tainted, k, v)
- elif tainteddefaults.has_key(tainted_key):
+ elif tainted_key in tainteddefaults:
# Find out if any of the tainted default
# attributes needs to be copied over.
missesdefault = 0
@@ -573,7 +607,7 @@
l = [l]
# First deal with tainted copies
- if taintedform.has_key(tainted_key):
+ if tainted_key in taintedform:
tainted = taintedform[tainted_key]
if not isinstance(tainted, lt):
tainted = [tainted]
@@ -588,7 +622,7 @@
tainted.append(defitem)
taintedform[tainted_key] = tainted
- elif tainteddefaults.has_key(tainted_key):
+ elif tainted_key in tainteddefaults:
missesdefault = 0
for defitem in tdefault:
if isinstance(defitem, record):
@@ -596,7 +630,8 @@
for k, v in \
defitem.__dict__.items():
for origitem in l:
- if not hasattr(origitem, k):
+ if not hasattr(
+ origitem, k):
missesdefault = 1
raise NestedLoopExit
except NestedLoopExit:
@@ -609,9 +644,11 @@
tainted = deepcopy(l)
for defitem in tdefault:
if isinstance(defitem, record):
- for k, v in defitem.__dict__.items():
+ for k, v in (
+ defitem.__dict__.items()):
for origitem in tainted:
- if not hasattr(origitem, k):
+ if not hasattr(
+ origitem, k):
setattr(origitem, k, v)
else:
if not defitem in tainted:
@@ -653,26 +690,27 @@
if tuple_items:
for key in tuple_items.keys():
# Split the key and get the attr
- k=key.split( ".")
- k,attr='.'.join(k[:-1]), k[-1]
+ k = key.split( ".")
+ k,attr = '.'.join(k[:-1]), k[-1]
a = attr
new = ''
# remove any type_names in the attr
- while not a=='':
- a=a.split( ":")
- a,new=':'.join(a[:-1]), a[-1]
+ while not a =='':
+ a = a.split( ":")
+ a,new = ':'.join(a[:-1]), a[-1]
attr = new
- if form.has_key(k):
+ if k in form:
# If the form has the split key get its value
tainted_split_key = k
- if '<' in k: tainted_split_key = TaintedString(k)
+ if '<' in k:
+ tainted_split_key = TaintedString(k)
item =form[k]
if isinstance(item, record):
# if the value is mapped to a record, check if it
# has the attribute, if it has it, convert it to
# a tuple and set it
if hasattr(item,attr):
- value=tuple(getattr(item,attr))
+ value = tuple(getattr(item,attr))
setattr(item,attr,value)
else:
# It is mapped to a list of records
@@ -681,11 +719,11 @@
if hasattr(x, attr):
# If the record has the attribute
# convert it to a tuple and set it
- value=tuple(getattr(x,attr))
+ value = tuple(getattr(x,attr))
setattr(x,attr,value)
# Do the same for the tainted counterpart
- if taintedform.has_key(tainted_split_key):
+ if tainted_split_key in taintedform:
tainted = taintedform[tainted_split_key]
if isinstance(item, record):
seq = tuple(getattr(tainted, attr))
@@ -699,29 +737,33 @@
else:
# the form does not have the split key
tainted_key = key
- if '<' in key: tainted_key = TaintedString(key)
- if form.has_key(key):
+ if '<' in key:
+ tainted_key = TaintedString(key)
+ if key in form:
# if it has the original key, get the item
# convert it to a tuple
- item=form[key]
- item=tuple(form[key])
- form[key]=item
+ item = form[key]
+ item = tuple(form[key])
+ form[key] = item
- if taintedform.has_key(tainted_key):
+ if tainted_key in taintedform:
tainted = tuple(taintedform[tainted_key])
taintedform[tainted_key] = tainted
if meth:
- if environ.has_key('PATH_INFO'):
- path=environ['PATH_INFO']
- while path[-1:]=='/': path=path[:-1]
- else: path=''
- other['PATH_INFO']=path="%s/%s" % (path,meth)
- self._hacked_path=1
+ if 'PATH_INFO' in environ:
+ path = environ['PATH_INFO']
+ while path[-1:] == '/':
+ path = path[:-1]
+ else:
+ path = ''
+ other['PATH_INFO'] = path = "%s/%s" % (path,meth)
+ self._hacked_path = 1
+#XXX this monkey patch does not seems useful anymore???
HTTPRequest.processInputs = processInputs
import logging
logger = logging.getLogger('Zope')
-logger.info("z3c.soap: modified ZPublisher.HTTPRequest.processInputs")
+logger.info("z3c.soap: monkeypatched ZPublisher.HTTPRequest.processInputs")
# vi:ts=4
Modified: z3c.soap/trunk/z3c/soap/patch.py
===================================================================
--- z3c.soap/trunk/z3c/soap/patch.py 2013-01-29 11:44:07 UTC (rev 129113)
+++ z3c.soap/trunk/z3c/soap/patch.py 2013-01-29 16:23:32 UTC (rev 129114)
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
##############################################################################
#
-# Copyright (c) 2001 Zope Foundation and Contributors.
+# Copyright (c) 2002 Zope Foundation and Contributors.
#
# This software is subject to the provisions of the Zope Public License,
-# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
@@ -12,17 +12,22 @@
#
##############################################################################
import sys
-from zExceptions import Redirect
+from zExceptions import Redirect, Unauthorized
from ZPublisher.mapply import mapply
from ZPublisher.Publish import (call_object, missing_name, dont_publish_class,
get_module_info, Retry)
+from ZPublisher.pubevents import PubStart, PubSuccess, PubFailure, \
+ PubBeforeCommit, PubAfterTraversal, PubBeforeAbort
from zope.publisher.browser import setDefaultSkin
+from zope.publisher.interfaces import ISkinnable
from zope.security.management import newInteraction, endInteraction
+from zope.event import notify
from z3c.soap.interfaces import ISOAPRequest
from z3c.soap.soap import SOAPResponse
def publish(request, module_name, after_list, debug=0,
+ # Optimize:
call_object=call_object,
missing_name=missing_name,
dont_publish_class=dont_publish_class,
@@ -36,6 +41,7 @@
response=None
try:
+ notify(PubStart(request))
# TODO pass request here once BaseRequest implements IParticipation
newInteraction()
@@ -45,15 +51,15 @@
response=request.response
# First check for "cancel" redirect:
- if request_get('SUBMIT', '').strip().lower()=='cancel':
- cancel=request_get('CANCEL_ACTION', '')
+ if request_get('SUBMIT','').strip().lower()=='cancel':
+ cancel=request_get('CANCEL_ACTION','')
if cancel:
- raise Redirect(cancel)
+ raise Redirect, cancel
after_list[0]=bobo_after
if debug_mode:
response.debug_mode=debug_mode
- if realm and not request.get('REMOTE_USER', None):
+ if realm and not request.get('REMOTE_USER',None):
response.realm=realm
if bobo_before is not None:
@@ -70,11 +76,13 @@
object=request.traverse(path, validated_hook=validated_hook)
+ notify(PubAfterTraversal(request))
+
if transactions_manager:
transactions_manager.recordMetaData(object, request)
result=mapply(object, request.args, request,
- call_object, 1,
+ call_object,1,
missing_name,
dont_publish_class,
request, bind=1)
@@ -82,31 +90,46 @@
if result is not response:
response.setBody(result)
+ notify(PubBeforeCommit(request))
+
if transactions_manager:
transactions_manager.commit()
endInteraction()
+ notify(PubSuccess(request))
+
return response
except:
+ # save in order to give 'PubFailure' the original exception info
+ exc_info = sys.exc_info()
# DM: provide nicer error message for FTP
sm = None
if response is not None:
sm = getattr(response, "setMessage", None)
+
if sm is not None:
from asyncore import compact_traceback
- cl, val= sys.exc_info()[:2]
+ cl,val= sys.exc_info()[:2]
sm('%s: %s %s' % (
- getattr(cl, '__name__', cl), val,
+ getattr(cl,'__name__',cl), val,
debug_mode and compact_traceback()[-1] or ''))
+
+ # debug is just used by tests (has nothing to do with debug_mode!)
+ # XXX begin monkeypatch
if ISOAPRequest.providedBy(request):
if transactions_manager:
transactions_manager.abort()
endInteraction()
if response is None:
response = SOAPResponse(request.response)
- response.exception()
+ if isinstance(exc_info[1], Unauthorized):
+ response._unauthorized()
+ else:
+ response.exception()
return response
- if err_hook is not None:
+ # XXX end monkeypatch
+ if not debug and err_hook is not None:
+ retry = False
if parents:
parents=parents[0]
try:
@@ -123,29 +146,49 @@
sys.exc_info()[1],
sys.exc_info()[2],
)
+ retry = True
finally:
- if transactions_manager:
- transactions_manager.abort()
- endInteraction()
+ # Note: 'abort's can fail. Nevertheless, we want end request handling
+ try:
+ try:
+ notify(PubBeforeAbort(request, exc_info, retry))
+ finally:
+ if transactions_manager:
+ transactions_manager.abort()
+ finally:
+ endInteraction()
+ notify(PubFailure(request, exc_info, retry))
# Only reachable if Retry is raised and request supports retry.
newrequest=request.retry()
request.close() # Free resources held by the request.
+
# Set the default layer/skin on the newly generated request
- setDefaultSkin(newrequest)
+ if ISkinnable.providedBy(newrequest):
+ setDefaultSkin(newrequest)
try:
return publish(newrequest, module_name, after_list, debug)
finally:
newrequest.close()
else:
- if transactions_manager:
- transactions_manager.abort()
- endInteraction()
+ # Note: 'abort's can fail. Nevertheless, we want end request handling
+ try:
+ try:
+ notify(PubBeforeAbort(request, exc_info, False))
+ finally:
+ if transactions_manager:
+ transactions_manager.abort()
+ finally:
+ endInteraction()
+ notify(PubFailure(request, exc_info, False))
raise
import ZPublisher.Publish
ZPublisher.Publish.publish = publish
+import logging
+logger = logging.getLogger('Zope')
+logger.info("z3c.soap: monkeypatched ZPublisher.Publish.publish")
from Products.PluggableAuthService.plugins.CookieAuthHelper import CookieAuthHelper
from urllib import quote
@@ -156,20 +199,22 @@
resp = req['RESPONSE']
# If we set the auth cookie before, delete it now.
- if self.cookie_name in resp.cookies:
+ if resp.cookies.has_key(self.cookie_name):
del resp.cookies[self.cookie_name]
# Redirect if desired.
url = self.getLoginURL()
+ # XXX begin monkeypatch
if ISOAPRequest.providedBy(req):
#no need to redirect if it's a soap request
return 0
+ # XXX end monkeypatch
if url is not None:
came_from = req.get('came_from', None)
if came_from is None:
- came_from = req.get('URL', '')
+ came_from = req.get('ACTUAL_URL', '')
query = req.get('QUERY_STRING')
if query:
if not query.startswith('?'):
@@ -180,8 +225,8 @@
# must be coming through here a second time
# Reasons could be typos when providing credentials
# or a redirect loop (see below)
- req_url = req.get('URL', '')
-
+ req_url = req.get('ACTUAL_URL', '')
+
if req_url and req_url == url:
# Oops... The login_form cannot be reached by the user -
# it might be protected itself due to misconfiguration -
@@ -189,11 +234,18 @@
# in an endless redirect loop.
return 0
- url = url + '?came_from=%s' % quote(came_from)
+ if '?' in url:
+ sep = '&'
+ else:
+ sep = '?'
+ url = '%s%scame_from=%s' % (url, sep, quote(came_from))
resp.redirect(url, lock=1)
+ resp.setHeader('Expires', 'Sat, 01 Jan 2000 00:00:00 GMT')
+ resp.setHeader('Cache-Control', 'no-cache')
return 1
# Could not challenge.
return 0
CookieAuthHelper.unauthorized = unauthorized
+logger.info("z3c.soap: monkeypatched CookieAuthHelper.unauthorized")
More information about the checkins
mailing list