[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher - Publish.py:1.1.2.17.2.1
Jim Fulton
jim@zope.com
Fri, 26 Apr 2002 14:23:23 -0400
Update of /cvs-repository/Zope3/lib/python/Zope/Publisher
In directory cvs.zope.org:/tmp/cvs-serv26237/lib/python/Zope/Publisher
Modified Files:
Tag: SecurityProxy-branch
Publish.py
Log Message:
Changed security code to use security proxies and name-based
security. This has pretty far-reaching implications:
- You now protect names/operations, *not* values. This means it's as
easy yo protect data attributes that have simple values as it is to
protect methods.
- There is no longer a __permissions__ attribute. :)
- There is no longer a validate method in either security managers or
policies.
- No more need to have a special compiler for restricted code.
In exchange, lots of objects are proxies and code sometimes needs to
be prepared to remove proxies.
In addition:
- Basic objects (None, strings, numbers, etc.) are not wrapped in
context wrappers.
- There is a test that fails unless Python 2.3 is used.
=== Zope3/lib/python/Zope/Publisher/Publish.py 1.1.2.17 => 1.1.2.17.2.1 ===
from Exceptions import Retry
-
-def executeRequest(request):
- """Either sets the body of the response or raises:
- - Retry to try the request again
- - SystemExit to stop publishing (maybe?)
- - Some other exception if handleException() raised an exception.
- """
-
- publication = request.getPublication()
- response = request.getResponse()
-
- try:
- request.processInputs()
- publication.beforeTraversal(request)
-
- root_object = publication.getApplication(request)
- object = request.traverse(root_object)
- publication.afterTraversal(request, object)
-
- result = publication.callObject(request, object)
- if result is not response:
- response.setBody(result)
-
- publication.afterCall(request)
- except:
- publication.handleException(request, sys.exc_info(), 1)
-
-
-def publish(request):
- try:
+def publish(request, handle_errors=1):
+ try: # finally to clean up to_raise and close request
to_raise = None
while 1:
+ publication = request.getPublication()
try:
try:
- executeRequest(request)
- # Successful.
- break
+ try:
+ request.processInputs()
+ publication.beforeTraversal(request)
+
+ root_object = publication.getApplication(request)
+ object = request.traverse(root_object)
+ publication.afterTraversal(request, object)
+
+ result = publication.callObject(request, object)
+ response = request.getResponse()
+ if result is not response:
+ response.setBody(result)
+
+ publication.afterCall(request)
+
+ except:
+ publication.handleException(request, sys.exc_info(), 1)
+ if not handle_errors:
+ raise
+
+ break # Successful.
+
except Retry, retryException:
if request.supportsRetry():
# Create a copy of the request and use it.
newrequest = request.retry()
request.close()
request = newrequest
- else:
+ elif handle_errors:
# Output the original exception.
publication = request.getPublication()
publication.handleException(
request, retryException.getOriginalException(), 0)
break
+ else:
+ raise
+
except:
# Bad exception handler or retry method.
# Re-raise after outputting the response.
- request.getResponse().internalError()
- to_raise = sys.exc_info()
- break
+ if handle_errors:
+ request.getResponse().internalError()
+ to_raise = sys.exc_info()
+ break
+ else:
+ raise
response = request.getResponse()
response.outputBody()
@@ -85,4 +83,7 @@
finally:
to_raise = None # Avoid circ. ref.
request.close() # Close database connections, etc.
+
+
+