[Zope-Checkins]
SVN: Zope/branches/publication-refactor/lib/python/ZPublisher/
- Fixed a couple mistakes.
Sidnei da Silva
sidnei at enfoldsystems.com
Mon Dec 12 16:05:33 EST 2005
Log message for revision 40755:
- Fixed a couple mistakes.
- The ZPublisher tests now pass
Changed:
U Zope/branches/publication-refactor/lib/python/ZPublisher/BaseRequest.py
U Zope/branches/publication-refactor/lib/python/ZPublisher/HTTPRequest.py
U Zope/branches/publication-refactor/lib/python/ZPublisher/Publication.py
U Zope/branches/publication-refactor/lib/python/ZPublisher/Publish.py
U Zope/branches/publication-refactor/lib/python/ZPublisher/tests/testPublish.py
-=-
Modified: Zope/branches/publication-refactor/lib/python/ZPublisher/BaseRequest.py
===================================================================
--- Zope/branches/publication-refactor/lib/python/ZPublisher/BaseRequest.py 2005-12-12 20:55:46 UTC (rev 40754)
+++ Zope/branches/publication-refactor/lib/python/ZPublisher/BaseRequest.py 2005-12-12 21:05:33 UTC (rev 40755)
@@ -81,8 +81,13 @@
if other is None: other=kw
else: other.update(kw)
self.other = other
- # Publication will be set by ZPublisher.Publish, publish().
- self.publication = None
+ self.environ = {}
+ # Publication will be overriden by ZPublisher.Publish,
+ # publish(), we assume that by default it's the "Zope2"
+ # module. This is done so that tests using BaseRequest
+ # directly don't break.
+ from ZPublisher.Publication import get_publication
+ self.publication = get_publication(module_name="Zope2")
def setPublication(self, publication):
self.publication = publication
@@ -238,11 +243,15 @@
URL=request['URL']
parents = request['PARENTS']
+ object = parents[-1]
del parents[:]
if not path and not method:
return response.forbiddenError(self['URL'])
+ if self.publication.root is not object:
+ self.publication.root = object
+
object = self.publication.getApplication(self)
roles = getRoles(None, None, object, UNSPECIFIED_ROLES)
parents.append(object)
Modified: Zope/branches/publication-refactor/lib/python/ZPublisher/HTTPRequest.py
===================================================================
--- Zope/branches/publication-refactor/lib/python/ZPublisher/HTTPRequest.py 2005-12-12 20:55:46 UTC (rev 40754)
+++ Zope/branches/publication-refactor/lib/python/ZPublisher/HTTPRequest.py 2005-12-12 21:05:33 UTC (rev 40755)
@@ -239,6 +239,8 @@
return self._client_addr
def __init__(self, stdin, environ, response, clean=0):
+ # Call base class __init__.
+ BaseRequest.__init__(self, RESPONSE=response)
self._orig_env=environ
# Avoid the overhead of scrubbing the environment in the
# case of request cloning for traversal purposes. If the
@@ -256,7 +258,7 @@
have_env=environ.has_key
get_env=environ.get
self.response=response
- other=self.other={'RESPONSE': response}
+ other = self.other
self.form={}
self.taintedform={}
self.steps=[]
Modified: Zope/branches/publication-refactor/lib/python/ZPublisher/Publication.py
===================================================================
--- Zope/branches/publication-refactor/lib/python/ZPublisher/Publication.py 2005-12-12 20:55:46 UTC (rev 40754)
+++ Zope/branches/publication-refactor/lib/python/ZPublisher/Publication.py 2005-12-12 21:05:33 UTC (rev 40755)
@@ -12,6 +12,7 @@
##############################################################################
__version__='$Revision$'[11:-2]
+import sys
import transaction
from zope.event import notify
from zope.interface import implements
@@ -19,6 +20,8 @@
from zope.publisher.interfaces import NotFound, IPublicationRequest
from zope.app.publication.interfaces import EndRequestEvent
from zope.app.publication.interfaces import BeforeTraverseEvent
+from zope.app.publication.interfaces import IBeforeTraverseEvent
+from zope.app.testing import ztapi
from ZPublisher.Publish import Retry
from ZPublisher.Publish import get_module_info, call_object
@@ -42,7 +45,7 @@
# Fetch module info to be backwards compatible with 'bobo'
# and Zope 2.
(self.bobo_before, self.bobo_after,
- self.application, self.realm, self.debug_mode,
+ self.root, self.realm, self.debug_mode,
self.err_hook, self.validated_hook,
self.transactions_manager) = get_module_info(self.module_name)
@@ -72,7 +75,7 @@
def getApplication(self, request):
# Return the application object for the given module.
- ob = self.application
+ ob = self.root
# Now, some code from ZPublisher.BaseRequest:
# If the top object has a __bobo_traverse__ method, then use it
@@ -151,9 +154,9 @@
except Retry:
if not retry_allowed:
return self.err_hook(object, request,
- exc_info[0],
- exc_info[1],
- exc_info[2],
+ sys.exc_info()[0],
+ sys.exc_info()[1],
+ sys.exc_info()[2],
)
finally:
self._abort()
@@ -208,11 +211,22 @@
TypeError, AttributeError):
raise NotFound(ob, name)
-_publication = None
+_publications = {}
def get_publication(module_name=None):
- global _publication
if module_name is None:
module_name = "Zope2"
- if _publication is None:
- _publication = ZopePublication(db=None, module_name=module_name)
- return _publication
+ if not _publications.has_key(module_name):
+ _publications[module_name] = ZopePublication(db=None,
+ module_name=module_name)
+ return _publications[module_name]
+
+def bptSubscriber(event):
+ ob = event.object
+ request = event.request
+ bpth = getattr(ob, '__before_publishing_traverse__', None)
+ if bpth is not None:
+ bpth(ob, request)
+
+# XXX Move to zcml.
+ztapi.subscribe([IBeforeTraverseEvent], None, bptSubscriber)
+
Modified: Zope/branches/publication-refactor/lib/python/ZPublisher/Publish.py
===================================================================
--- Zope/branches/publication-refactor/lib/python/ZPublisher/Publish.py 2005-12-12 20:55:46 UTC (rev 40754)
+++ Zope/branches/publication-refactor/lib/python/ZPublisher/Publish.py 2005-12-12 21:05:33 UTC (rev 40755)
@@ -105,7 +105,7 @@
# Get a nice clean path list:
path = request_get('PATH_INFO').strip()
- request['PARENTS'] = parents = [publication.application]
+ request['PARENTS'] = parents = [publication.root]
# Traverse to the requested path.
object = request.traverse(path, validated_hook=validated_hook)
@@ -138,30 +138,25 @@
getattr(cl,'__name__',cl), val,
debug_mode and compact_traceback()[-1] or ''))
- if parents:
- parents = parents[0]
+ if parents:
+ parents = parents[0]
- err_handled = publication.handleException(
- parents, request, sys.exc_info(),
- retry_allowed=request.supports_retry())
+ err_handled = publication.handleException(
+ parents, request, sys.exc_info(),
+ retry_allowed=request.supports_retry())
- # XXX What if 'err_hook' returns None?
- if err_handled is not None:
- return err_handled
+ # XXX What if 'err_hook' returns None?
+ if err_handled is not None:
+ return err_handled
- # Only reachable if Retry is raised and request supports retry.
- newrequest = request.retry()
- request.close() # Free resources held by the request.
- try:
- return publish(newrequest, module_name, after_list, debug)
- finally:
- newrequest.close()
+ # Only reachable if Retry is raised and request supports retry.
+ newrequest = request.retry()
+ request.close() # Free resources held by the request.
+ try:
+ return publish(newrequest, module_name, after_list, debug)
+ finally:
+ newrequest.close()
- else:
- publication._abort()
- raise
-
-
def publish_module_standard(module_name,
stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr,
environ=os.environ, debug=0, request=None, response=None):
Modified: Zope/branches/publication-refactor/lib/python/ZPublisher/tests/testPublish.py
===================================================================
--- Zope/branches/publication-refactor/lib/python/ZPublisher/tests/testPublish.py 2005-12-12 20:55:46 UTC (rev 40754)
+++ Zope/branches/publication-refactor/lib/python/ZPublisher/tests/testPublish.py 2005-12-12 21:05:33 UTC (rev 40755)
@@ -91,6 +91,9 @@
def __init__(self):
self.response = Response()
+ def setPublication(self, publication):
+ self.publication = publication
+
def processInputs(self):
pass
More information about the Zope-Checkins
mailing list