def __call__(self): mapply(self.update, (), self.request) if self.request.response.getStatus() in (302, 303): # A redirect was triggered somewhere in update(). Don't # continue rendering the template or doing anything else. return return self.render()
def testClass(self): values = {'a': 2, 'b': 3, 'c': 5} class c(object): a = 3 def __call__(self, b, c=4): return '%d%d%d' % (self.a, b, c) compute = __call__ cc = c() v = mapply(cc, (), values) self.failUnlessEqual(v, '335') del values['c'] v = mapply(cc.compute, (), values) self.failUnlessEqual(v, '334') class c2: """Must be a classic class.""" c2inst = c2() c2inst.__call__ = cc v = mapply(c2inst, (), values) self.failUnlessEqual(v, '334')
def __call__(self): mapply(self.update, (), self.request) agenda_recente = self.agenda_recente() if agenda_recente and not self.editable: return agenda_recente.restrictedTraverse('@@view')() else: return super(AgendaView, self).__call__()
def __call__(self): input = self.request.stdin.getvalue() if input: try: self.input = json.loads(input) except ValueError: self.response.setHeader('Content-Type', 'application/json') return json.dumps({'type': 'error', 'message': 'Invalid JSON input'}) mapply(self.update, (), self.request) if self.response.getStatus() in [302, 303]: return # Shortcircuit on redirect, no need to render self.response.setHeader('Content-Type', 'application/json') method = self.request.get('REQUEST_METHOD', 'GET').upper() renderer = getattr(self, 'do_%s' % method, None) if renderer is None: log.info('Invalid HTTP method %s attempted for %s', method, '/'.join(self.context.getPhysicalPath())) self.response.setStatus(405) response = {'type': 'error', 'message': 'HTTP method not allowed'} else: response = mapply(renderer, (), self.request) return json.dumps(response)
def testClass(self): values = {"a": 2, "b": 3, "c": 5} class c(object): a = 3 def __call__(self, b, c=4): return "%d%d%d" % (self.a, b, c) compute = __call__ cc = c() v = mapply(cc, (), values) self.failUnlessEqual(v, "335") del values["c"] v = mapply(cc.compute, (), values) self.failUnlessEqual(v, "334") class c2: """Must be a classic class.""" c2inst = c2() c2inst.__call__ = cc v = mapply(c2inst, (), values) self.failUnlessEqual(v, "334")
def __call__(self): input = self.request.stdin.getvalue() if input: try: self.input = json.loads(input) except ValueError: self.response.setHeader('Content-Type', 'application/json') return json.dumps({ 'type': 'error', 'message': 'Invalid JSON input' }) mapply(self.update, (), self.request) if self.response.getStatus() in [302, 303]: return # Shortcircuit on redirect, no need to render self.response.setHeader('Content-Type', 'application/json') method = self.request.get('REQUEST_METHOD', 'GET').upper() renderer = getattr(self, 'do_%s' % method, None) if renderer is None: log.info('Invalid HTTP method %s attempted for %s', method, '/'.join(self.context.getPhysicalPath())) self.response.setStatus(405) response = {'type': 'error', 'message': 'HTTP method not allowed'} else: response = mapply(renderer, (), self.request) return json.dumps(response)
def __call__(self): self.layout = self._get_layout() mapply(self.update, (), self.request) if self.request.response.getStatus() in (302, 303): # A redirect was triggered somewhere in update(). Don't # continue rendering the template or doing anything else. return return self.layout(self)
def testMethod(self): def compute(a,b,c=4): return '%d%d%d' % (a, b, c) values = {'a':2, 'b':3, 'c':5} v = mapply(compute, (), values) self.failUnlessEqual(v, '235') v = mapply(compute, (7,), values) self.failUnlessEqual(v, '735')
def testMethod(self): def compute(a,b,c=4): return '%d%d%d' % (a, b, c) values = {'a':2, 'b':3, 'c':5} v = mapply(compute, (), values) self.assertEqual(v, '235') v = mapply(compute, (7,), values) self.assertEqual(v, '735')
def __call__(self): mapply(self.update, (), self.request) if self.request.response.getStatus() in (302, 303): # A redirect was triggered somewhere in update(). Don't # continue rendering the template or doing anything else. return self.layout = zope.component.getMultiAdapter( (self.request, self.context), ILayout) return self.layout(self)
def testMethod(self): def compute(a, b, c=4): return "%d%d%d" % (a, b, c) values = {"a": 2, "b": 3, "c": 5} v = mapply(compute, (), values) self.assertEqual(v, "235") v = mapply(compute, (7,), values) self.assertEqual(v, "735")
def __call__(self): mapply(self.update, (), self.request) if self.request.response.getStatus() in (302, 303): # A redirect was triggered somewhere in update(). Don't # continue rendering the template or doing anything else. return if self.layout is None: layout = component.getMultiAdapter( (self.context, self.request), megrok.layout.ILayout) return layout(self) return self.layout()
def __call__(self): mapply(self.update, (), self.request) if self.request.response.getStatus() in (302, 303): # A redirect was triggered somewhere in update(). Don't # continue rendering the template or doing anything else. return template = getattr(self, 'template', None) if template is not None: return self._render_template() return mapply(self.render, (), self.request)
def __call__(self): mapply(self.update, (), self.request) if self.response.getStatus() in (302, 303): # A redirect was triggered somewhere in update(). Don't # continue processing the form return self.updateForm() if self.response.getStatus() in (302, 303): return return self.render()
def testAncientMethod(self): # Before Python 2.6, methods did not have __func__ and __code__. # They had im_func and func_code instead. # This may still be the case for RestrictedPython scripts. # Pretend a method that accepts one argument and one keyword argument. # The default value for the keyword argument is given as a tuple. method = AncientMethod('7 * %d + %d', (0,)) values = {} v = mapply(method, (6,), values) self.assertEqual(v, 42) v = mapply(method, (5, 4), values) self.assertEqual(v, 39)
def testAncientMethod(self): # Before Python 2.6, methods did not have __func__ and __code__. # They had im_func and func_code instead. # This may still be the case for RestrictedPython scripts. # Pretend a method that accepts one argument and one keyword argument. # The default value for the keyword argument is given as a tuple. method = AncientMethod('7 * %d + %d', (0, )) values = {} v = mapply(method, (6, ), values) self.assertEqual(v, 42) v = mapply(method, (5, 4), values) self.assertEqual(v, 39)
def __call__(self): mapply(self.update, (), self.request) if self.request.response.getStatus() in (302, 303): # A redirect was triggered somewhere in update(). Don't # continue processing the form return self.updateForm() if self.request.response.getStatus() in (302, 303): return self.layout = getMultiAdapter( (self.request, self.context), ILayout) return self.layout(self)
def testClass(self): values = {'a':2, 'b':3, 'c':5} class c(object): a = 3 def __call__(self, b, c=4): return '%d%d%d' % (self.a, b, c) compute = __call__ cc = c() v = mapply(cc, (), values) self.assertEqual(v, '335') del values['c'] v = mapply(cc.compute, (), values) self.assertEqual(v, '334')
def __call__(self): __traceback_supplement__ = (ErrorSupplement, self) layout_factory = component.getMultiAdapter( (self.request, self.context,), ILayoutFactory) self.layout = layout_factory(self) mapply(self.update, (), self.request) if self.request.response.getStatus() in (302, 303): # A redirect was triggered somewhere in update(). Don't # continue rendering the template or doing anything else. return return self.layout(self)
def __call__(self): """Calls update and returns the layout template which calls render. """ self.layout = self._get_layout() mapply(self.update, (), self.request) if self.request.response.getStatus() in (302, 303): # A redirect was triggered somewhere in update(). Don't # continue rendering the template or doing anything else. return # update_form() is what make a layout-aware form different from # 'regular" layout-aware component. self.update_form() if self.request.response.getStatus() in (302, 303): return return self.layout(self)
def callObject(self, request, ob): method = request['command'] view = zapi.queryMultiAdapter((ob, request), name=method, default=self) if view is self: raise NotFound(ob, method, request) return mapply(getattr(view, method), (), request)
def __call__(self): convert_request_form_to_unicode(self.request.form) self.layout = component.getMultiAdapter( (self.request, self.context), ILayout) mapply(self.update, (), self.request) if self.request.response.getStatus() in (302, 303): # A redirect was triggered somewhere in update(). Don't # continue processing the form return self.updateForm() if self.request.response.getStatus() in (302, 303): return return self.layout(self)
def callObject(self, request, ob): # Exception handling, dont try to call request.method orig = ob #if not IHTTPException.providedBy(ob): # ob = getattr(ob, request.method, None) # if ob is None: # raise MethodNotAllowed(orig, request) return mapply(ob, request.getPositionalArguments(), request)
def callObject(self, request, ob): endpoint = IEndpoint(ob, None) if endpoint is not None: method = getattr(endpoint, request.method, None) # do the security check here return mapply(method, request.getPositionalArguments(), request) else: # what do we do ? pass
def callObject(self, request, ob): """Call the object, returning the result. For GET/POST this means calling it, but for other methods (including those of WebDAV and FTP) this might mean invoking a method of an adapter. """ from zope.publisher.publish import mapply return mapply(ob, request.getPositionalArguments(), request)
def callObject(self, request, ob): method = request['command'] view = zope.component.queryMultiAdapter((ob, request), name=method, default=self) if view is self: raise NotFound(ob, method, request) return mapply(getattr(view, method), (), request)
def __call__(self): """Calls update and returns the layout template which calls render. """ mapply(self.update, (), self.request) if self.request.response.getStatus() in (302, 303): return self.update_form() if self.layout is None: layout = queryMultiAdapter((self.context, self.request), ILayoutTemplate) if layout is None: raise NotImplementedError( """Impossible to find a suitable layout for %r. This is an unimplemented siutation. Please, provide a useable layout or check your components.""" % self) return layout(self) return self.layout()
def callObject(self, request, ob): # Exception handling, dont try to call request.method orig = ob if not IHTTPException.providedBy(ob): ob = zapi.queryMultiAdapter((ob, request), name=request.method) ob = getattr(ob, request.method, None) if ob is None: raise MethodNotAllowed(orig, request) return mapply(ob, request.getPositionalArguments(), request)
def testClass(self): values = {"a": 2, "b": 3, "c": 5} class c(object): a = 3 def __call__(self, b, c=4): return "%d%d%d" % (self.a, b, c) compute = __call__ cc = c() v = mapply(cc, (), values) self.assertEqual(v, "335") del values["c"] v = mapply(cc.compute, (), values) self.assertEqual(v, "334")
def callObject(self, request, ob): # Exception handling, dont try to call request.method orig = ob if not IHTTPException.providedBy(ob): ob = zope.component.queryMultiAdapter((ob, request), name=request.method) ob = getattr(ob, request.method, None) if ob is None: raise MethodNotAllowed(orig, request) return mapply(ob, request.getPositionalArguments(), request)
def callObject(self, request, ob): if request.method == 'GET': orig = removeAllProxies(ob) if type(orig) is MethodType: strategy = ICacheStrategy(orig.im_self, None) else: strategy = ICacheStrategy(orig, None) if strategy is not None: strategy = strategy.__bind__(request) if not strategy.isModified(): request.response.setStatus(304) strategy.setNotModifiedHeaders() return '' result = mapply(ob, request.getPositionalArguments(), request) strategy.setCacheHeaders() return result return mapply(ob, request.getPositionalArguments(), request)
def callObject(self, request, ob): """See `zope.publisher.interfaces.IPublication`. Our implementation make sure that no result is returned on redirect. It also sets the launchpad.userid and launchpad.pageid WSGI environment variables. """ request._publicationticks_start = tickcount.tickcount() if request.response.getStatus() in [301, 302, 303, 307]: return '' request.setInWSGIEnvironment( 'launchpad.userid', request.principal.id) # The view may be security proxied view = removeSecurityProxy(ob) # It's possible that the view is a bound method. view = getattr(view, 'im_self', view) context = removeSecurityProxy(getattr(view, 'context', None)) pageid = self.constructPageID(view, context) request.setInWSGIEnvironment('launchpad.pageid', pageid) # And spit the pageid out to our tracelog. tracelog(request, 'p', pageid) # For status URLs, where we really don't want to have any DB access # at all, ensure that all flag lookups will stop early. if pageid in ( 'RootObject:OpStats', 'RootObject:+opstats', 'RootObject:+haproxy'): request.features = NullFeatureController() features.install_feature_controller(request.features) # Calculate the hard timeout: needed because featureflags can be used # to control the hard timeout, and they trigger DB access, but our # DB tracers are not safe for reentrant use, so we must do this # outside of the SQL stack. We must also do it after traversal so that # the view is known and can be used in scope resolution. As we # actually stash the pageid after afterTraversal, we need to do this # even later. da.set_permit_timeout_from_features(True) da._get_request_timeout() if isinstance(removeSecurityProxy(ob), METHOD_WRAPPER_TYPE): # this is a direct call on a C-defined method such as __repr__ or # dict.__setitem__. Apparently publishing this is possible and # acceptable, at least in the case of # lp.services.webapp.servers.PrivateXMLRPCPublication. # mapply cannot handle these methods because it cannot introspect # them. We'll just call them directly. return ob(*request.getPositionalArguments()) return mapply(ob, request.getPositionalArguments(), request)
def callObject(self, request, ob): orig = ob if not IHTTPException.providedBy(ob): ob = component.queryMultiAdapter((ob, request), name=request.method) checker = selectChecker(ob) if checker is not None: checker.check(ob, '__call__') ob = getattr(ob, request.method, None) if ob is None: raise GrokMethodNotAllowed(orig, request) return mapply(ob, request.getPositionalArguments(), request)
def callObject(self, request, ob): """See `zope.publisher.interfaces.IPublication`. Our implementation make sure that no result is returned on redirect. It also sets the launchpad.userid and launchpad.pageid WSGI environment variables. """ request._publicationticks_start = tickcount.tickcount() if request.response.getStatus() in [301, 302, 303, 307]: return '' request.setInWSGIEnvironment('launchpad.userid', request.principal.id) # The view may be security proxied view = removeSecurityProxy(ob) # It's possible that the view is a bound method. view = getattr(view, 'im_self', view) context = removeSecurityProxy(getattr(view, 'context', None)) pageid = self.constructPageID(view, context) request.setInWSGIEnvironment('launchpad.pageid', pageid) # And spit the pageid out to our tracelog. tracelog(request, 'p', pageid) # For status URLs, where we really don't want to have any DB access # at all, ensure that all flag lookups will stop early. if pageid in ('RootObject:OpStats', 'RootObject:+opstats', 'RootObject:+haproxy'): request.features = NullFeatureController() features.install_feature_controller(request.features) # Calculate the hard timeout: needed because featureflags can be used # to control the hard timeout, and they trigger DB access, but our # DB tracers are not safe for reentrant use, so we must do this # outside of the SQL stack. We must also do it after traversal so that # the view is known and can be used in scope resolution. As we # actually stash the pageid after afterTraversal, we need to do this # even later. da.set_permit_timeout_from_features(True) da._get_request_timeout() if isinstance(removeSecurityProxy(ob), METHOD_WRAPPER_TYPE): # this is a direct call on a C-defined method such as __repr__ or # dict.__setitem__. Apparently publishing this is possible and # acceptable, at least in the case of # lp.services.webapp.servers.PrivateXMLRPCPublication. # mapply cannot handle these methods because it cannot introspect # them. We'll just call them directly. return ob(*request.getPositionalArguments()) return mapply(ob, request.getPositionalArguments(), request)
def testClass(self): values = {'a':2, 'b':3, 'c':5} class c(object): a = 3 def __call__(self, b, c=4): return '%d%d%d' % (self.a, b, c) compute = __call__ cc = c() v = mapply(cc, (), values) self.failUnlessEqual(v, '335') del values['c'] v = mapply(cc.compute, (), values) self.failUnlessEqual(v, '334') class c2: """Must be a classic class.""" c2inst = c2() c2inst.__call__ = cc v = mapply(c2inst, (), values) self.failUnlessEqual(v, '334')
def testClassicClass(self): if not PYTHON2: # Classic classes are only available in py3 return values = {'a':2, 'b':3} class c(object): a = 3 def __call__(self, b, c=4): return '%d%d%d' % (self.a, b, c) compute = __call__ cc = c() class c2: """Must be a classic class.""" c2inst = c2() c2inst.__call__ = cc v = mapply(c2inst, (), values) self.assertEqual(v, '334')
def callObject(self, request, ob): command = getattr(ob, request.env['command']) if 'name' in request.env: request.env['path'] += "/" + request.env['name'] return mapply(command, request=request.env)
def __call__(self): view_name = self.__view_name__ method = getattr(self, view_name) method_result = mapply(method, (), self.request) return simplejson.dumps(method_result)
def handleException(self, object, request, exc_info, retry_allowed=True): # This transaction had an exception that reached the publisher. # It must definitely be aborted. transaction.abort() # Reraise Retry exceptions for the publisher to deal with. if retry_allowed and isinstance(exc_info[1], Retry): raise # Convert ConflictErrors to Retry exceptions. if retry_allowed and isinstance(exc_info[1], ConflictError): tryToLogWarning( 'ZopePublication', 'Competing writes/reads at %s: %s' % ( request.get('PATH_INFO', '???'), exc_info[1], ), ) raise Retry(exc_info) # Are there any reasons why we'd want to let application-level error # handling determine whether a retry is allowed or not? # Assume not for now. # Record the error with the ErrorReportingUtility self._logErrorWithErrorReportingUtility(object, request, exc_info) response = request.response response.reset() exception = None legacy_exception = not isinstance(exc_info[1], Exception) if legacy_exception: response.handleException(exc_info) if isinstance(exc_info[1], str): tryToLogWarning( 'Publisher received a legacy string exception: %s.' ' This will be handled by the request.' % exc_info[1]) else: tryToLogWarning( 'Publisher received a legacy classic class exception: %s.' ' This will be handled by the request.' % exc_info[1].__class__) else: # We definitely have an Exception # Set the request body, and abort the current transaction. self.beginErrorHandlingTransaction(request, object, 'application error-handling') view = None try: # We need to get a location, because some template content of # the exception view might require one. # # The object might not have a parent, because it might be a # method. If we don't have a `__parent__` attribute but have # an im_self or a __self__, use it. loc = object if not hasattr(object, '__parent__'): loc = removeSecurityProxy(object) # Try to get an object, since we apparently have a method # Note: We are guaranteed that an object has a location, # so just getting the instance the method belongs to is # sufficient. loc = getattr(loc, 'im_self', loc) loc = getattr(loc, '__self__', loc) # Protect the location with a security proxy loc = ProxyFactory(loc) # Give the exception instance its location and look up the # view. exception = LocationProxy(exc_info[1], loc, '') name = queryDefaultViewName(exception, request) if name is not None: view = zope.component.queryMultiAdapter( (exception, request), name=name) except: # Problem getting a view for this exception. Log an error. tryToLogException('Exception while getting view on exception') if view is not None: try: # We use mapply instead of self.callObject here # because we don't want to pass positional # arguments. The positional arguments were meant # for the published object, not an exception view. body = mapply(view, (), request) response.setResult(body) transaction.commit() if (ISystemErrorView.providedBy(view) and view.isSystemError()): # Got a system error, want to log the error # Lame hack to get around logging missfeature # that is fixed in Python 2.4 try: raise exc_info[0], exc_info[1], exc_info[2] except: logging.getLogger('SiteError').exception( str(request.URL), ) except: # Problem rendering the view for this exception. # Log an error. tryToLogException( 'Exception while rendering view on exception') # Record the error with the ErrorReportingUtility self._logErrorWithErrorReportingUtility( object, request, sys.exc_info()) view = None if view is None: # Either the view was not found, or view was set to None # because the view couldn't be rendered. In either case, # we let the request handle it. response.handleException(exc_info) transaction.abort() # See if there's an IExceptionSideEffects adapter for the # exception try: adapter = IExceptionSideEffects(exception, None) except: tryToLogException( 'Exception while getting IExceptionSideEffects adapter') adapter = None if adapter is not None: self.beginErrorHandlingTransaction( request, object, 'application error-handling side-effect') try: # Although request is passed in here, it should be # considered read-only. adapter(object, request, exc_info) transaction.commit() except: tryToLogException('Exception while calling' ' IExceptionSideEffects adapter') transaction.abort()
def content(self): template = getattr(self, 'template', None) if template is not None: return self._render_template() return mapply(self.render, (), self.request)
def callObject(self, request, ob): return mapply(ob, request.getPositionalArguments(), request)
def render(self): return mapply(self.view, self.request.getPositionalArguments(), self.request)
def __call__(self): return mapply(self.notify, (), self.request)
def handleException(self, object, request, exc_info, retry_allowed=True): #orig = removeAllProxies(object) transaction.abort() if retry_allowed and isinstance(exc_info[1], Retry): raise if retry_allowed and isinstance(exc_info[1], ConflictError): tryToLogWarning( 'ZopePublication', 'Competing writes/reads at %s: %s' % (request.get('PATH_INFO', '???'), exc_info[1], ), ) raise Retry(exc_info) self._logErrorWithErrorReportingUtility(object, request, exc_info) response = request.response response.reset() exception = None legacy_exception = not isinstance(exc_info[1], Exception) if legacy_exception: response.handleException(exc_info) if isinstance(exc_info[1], str): tryToLogWarning( 'Publisher received a legacy string exception: %s.' ' This will be handled by the request.' % exc_info[1]) else: tryToLogWarning( 'Publisher received a legacy classic class exception: %s.' ' This will be handled by the request.' % exc_info[1].__class__) else: self.beginErrorHandlingTransaction( request, object, 'application error-handling') view = None try: loc = object if not hasattr(object, '__parent__'): loc = removeSecurityProxy(object) loc = getattr(loc, 'im_self', loc) loc = getattr(loc, '__self__', loc) loc = ProxyFactory(loc) exception = LocationProxy(exc_info[1], loc, '') name = queryDefaultViewName(exception, request) if name is not None: view = queryMultiAdapter( (exception, request), name=name) except: tryToLogException('Exception while getting view on exception') if view is not None: try: body = mapply(view, (), request) response.setResult(body) transaction.commit() if (ISystemErrorView.providedBy(view) and view.isSystemError()): try: raise exc_info[0], exc_info[1], exc_info[2] except: logging.getLogger('SiteError').exception( str(request.URL), ) except ReadOnlyError: transaction.abort() except: tryToLogException('Exception while rendering view on exception') self._logErrorWithErrorReportingUtility( object, request, sys.exc_info()) view = None if view is None: response.handleException(exc_info) transaction.abort() try: adapter = IExceptionSideEffects(exception, None) except: tryToLogException( 'Exception while getting IExceptionSideEffects adapter') adapter = None if adapter is not None: self.beginErrorHandlingTransaction( request, object, 'application error-handling side-effect') try: adapter(object, request, exc_info) transaction.commit() except ReadOnlyError: transaction.abort() except: tryToLogException('Exception while calling' ' IExceptionSideEffects adapter') transaction.abort()
def handleException(self, object, request, exc_info, retry_allowed=True): # This transaction had an exception that reached the publisher. # It must definitely be aborted. try: transaction.abort() except: # Hm, a catastrophe. We might want to know what preceded it. self._logErrorWithErrorReportingUtility(object, request, exc_info) raise # Reraise Retry exceptions for the publisher to deal with. if retry_allowed and isinstance(exc_info[1], Retry): raise # Convert ConflictErrors to Retry exceptions. if retry_allowed and isinstance(exc_info[1], ConflictError): tryToLogWarning( 'ZopePublication', 'Competing writes/reads at %s: %s' % (request.get('PATH_INFO', '???'), exc_info[1], ), ) raise Retry(exc_info) # Are there any reasons why we'd want to let application-level error # handling determine whether a retry is allowed or not? # Assume not for now. # Record the error with the ErrorReportingUtility. self._logErrorWithErrorReportingUtility(object, request, exc_info) response = request.response response.reset() exception = None legacy_exception = not isinstance(exc_info[1], Exception) if legacy_exception: response.handleException(exc_info) if isinstance(exc_info[1], str): tryToLogWarning( 'Publisher received a legacy string exception: %s.' ' This will be handled by the request.' % exc_info[1]) else: tryToLogWarning( 'Publisher received a legacy classic class exception: %s.' ' This will be handled by the request.' % exc_info[1].__class__) else: # We definitely have an Exception # Set the request body, and abort the current transaction. self.beginErrorHandlingTransaction( request, object, 'application error-handling') view = None try: # We need to get a location, because some template content of # the exception view might require one. # # The object might not have a parent, because it might be a # method. If we don't have a `__parent__` attribute but have # an im_self or a __self__, use it. loc = object if not hasattr(object, '__parent__'): loc = removeSecurityProxy(object) # Try to get an object, since we apparently have a method # Note: We are guaranteed that an object has a location, # so just getting the instance the method belongs to is # sufficient. loc = getattr(loc, 'im_self', loc) loc = getattr(loc, '__self__', loc) # Protect the location with a security proxy loc = self.proxy(loc) # Give the exception instance its location and look up the # view. exception = LocationProxy(exc_info[1], loc, '') name = queryDefaultViewName(exception, request) if name is not None: view = zope.component.queryMultiAdapter( (exception, request), name=name) except: # Problem getting a view for this exception. Log an error. tryToLogException( 'Exception while getting view on exception') if view is not None: try: # We use mapply instead of self.callObject here # because we don't want to pass positional # arguments. The positional arguments were meant # for the published object, not an exception view. body = mapply(view, (), request) response.setResult(body) transaction.commit() if (ISystemErrorView.providedBy(view) and view.isSystemError()): # Got a system error, want to log the error # Lame hack to get around logging missfeature # that is fixed in Python 2.4 try: raise exc_info[0], exc_info[1], exc_info[2] except: logging.getLogger('SiteError').exception( str(request.URL), ) except: # Problem rendering the view for this exception. # Log an error. tryToLogException( 'Exception while rendering view on exception') # Record the error with the ErrorReportingUtility self._logErrorWithErrorReportingUtility( object, request, sys.exc_info()) view = None if view is None: # Either the view was not found, or view was set to None # because the view couldn't be rendered. In either case, # we let the request handle it. response.handleException(exc_info) transaction.abort() # See if there's an IExceptionSideEffects adapter for the # exception try: adapter = IExceptionSideEffects(exception, None) except: tryToLogException( 'Exception while getting IExceptionSideEffects adapter') adapter = None if adapter is not None: self.beginErrorHandlingTransaction( request, object, 'application error-handling side-effect') try: # Although request is passed in here, it should be # considered read-only. adapter(object, request, exc_info) transaction.commit() except: tryToLogException( 'Exception while calling' ' IExceptionSideEffects adapter') transaction.abort()
def callErrorView(self, request, view): # We don't want to pass positional arguments. The positional # arguments were meant for the published object, not an exception # view. return mapply(view, (), request)