summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShane Hathaway <shane@hathawaymix.org>2009-12-27 06:55:16 +0000
committerShane Hathaway <shane@hathawaymix.org>2009-12-27 06:55:16 +0000
commit8bad391c468c1a43b081c01ac790be55b9ee11d7 (patch)
tree55895bff8255d272c167da9e01d9646dfbda6549 /src
parent57dec85a2eb2968497da6a600dd93c9619c9f915 (diff)
downloadzope-traversing-8bad391c468c1a43b081c01ac790be55b9ee11d7.tar.gz
Removed testing dependency on zope.app.publication.
Diffstat (limited to 'src')
-rw-r--r--src/zope/traversing/publicationtraverse.py13
-rw-r--r--src/zope/traversing/tests/ftesting.zcml3
-rw-r--r--src/zope/traversing/tests/test_vhosting.py100
3 files changed, 96 insertions, 20 deletions
diff --git a/src/zope/traversing/publicationtraverse.py b/src/zope/traversing/publicationtraverse.py
index 4fc90d1..b1e7c75 100644
--- a/src/zope/traversing/publicationtraverse.py
+++ b/src/zope/traversing/publicationtraverse.py
@@ -43,6 +43,8 @@ class PublicationTraverser(object):
- This version has a method, traverseRelativeURL(), that
supports "browserDefault" traversal.
"""
+ def proxy(self, ob):
+ return ProxyFactory(ob)
def traverseName(self, request, ob, name):
nm = name # the name to look up the object with
@@ -56,7 +58,7 @@ class PublicationTraverser(object):
except TraversalError:
raise NotFound(ob, name)
- return ProxyFactory(ob2)
+ return self.proxy(ob2)
if nm == '.':
return ob
@@ -72,7 +74,7 @@ class PublicationTraverser(object):
else:
raise NotFound(ob, name, request)
- return ProxyFactory(ob2)
+ return self.proxy(ob2)
def traversePath(self, request, ob, path):
@@ -113,7 +115,7 @@ class PublicationTraverser(object):
if adapter is None:
return ob
ob, path = adapter.browserDefault(request)
- ob = ProxyFactory(ob)
+ ob = self.proxy(ob)
if not path:
return ob
@@ -121,3 +123,8 @@ class PublicationTraverser(object):
# alternate spelling
PublicationTraverse = PublicationTraverser
+
+class PublicationTraverserWithoutProxy(PublicationTraverse):
+
+ def proxy(self, ob):
+ return ob
diff --git a/src/zope/traversing/tests/ftesting.zcml b/src/zope/traversing/tests/ftesting.zcml
index 3f4fe1b..752e60d 100644
--- a/src/zope/traversing/tests/ftesting.zcml
+++ b/src/zope/traversing/tests/ftesting.zcml
@@ -10,7 +10,6 @@
<include package="zope.publisher" file="meta.zcml" />
<include package="zope.security" file="meta.zcml" />
<include package="zope.securitypolicy" file="meta.zcml" />
- <include package="zope.app.publication" file="meta.zcml" />
<include package="zope.browserresource" />
<include package="zope.container" />
@@ -21,8 +20,6 @@
<include package="zope.site" />
<include package="zope.traversing" />
- <include package="zope.app.publication" />
-
<browser:defaultView name="index.html" />
<include package="zope.traversing.browser" />
diff --git a/src/zope/traversing/tests/test_vhosting.py b/src/zope/traversing/tests/test_vhosting.py
index bf4c2c6..ed4e6ae 100644
--- a/src/zope/traversing/tests/test_vhosting.py
+++ b/src/zope/traversing/tests/test_vhosting.py
@@ -20,11 +20,6 @@ import unittest
from StringIO import StringIO
import transaction
-from persistent import Persistent
-from ZODB.DB import DB
-from ZODB.DemoStorage import DemoStorage
-
-from zope.app.publication.browser import BrowserPublication
from zope.browserresource.resource import Resource
from zope.configuration import xmlconfig
@@ -48,7 +43,7 @@ class MyObj(Contained):
return traverse(self, '/foo/bar/' + key)
-class MyPageTemplate(AppPT, PageTemplate, Persistent):
+class MyPageTemplate(AppPT, PageTemplate):
def pt_getContext(self, instance, request, **_kw):
# instance is a View component
@@ -84,16 +79,11 @@ class TestVirtualHosting(unittest.TestCase):
def setUp(self):
f = os.path.join(os.path.split(__file__)[0], 'ftesting.zcml')
xmlconfig.file(f)
- self.db = DB(DemoStorage("Memory storage unnamed"))
- self.connection = self.db.open()
- root = self.connection.root()
- root_folder = rootFolder()
- root['Application'] = root_folder
+ self.app = rootFolder()
defineChecker(MyObj, NoProxy)
def tearDown(self):
undefineChecker(MyObj)
- self.connection.close()
cleanUp()
def makeRequest(self, path=''):
@@ -104,7 +94,7 @@ class TestVirtualHosting(unittest.TestCase):
env['PATH_INFO'] = p[0]
request = BrowserRequest(StringIO(''), env)
- request.setPublication(BrowserPublication(self.db))
+ request.setPublication(DummyPublication(self.app))
setDefaultSkin(request)
return request
@@ -181,7 +171,7 @@ class TestVirtualHosting(unittest.TestCase):
"""addFolders('/a/b/c/d') would traverse and/or create three nested
folders (a, b, c) and return a tuple (c, 'd') where c is a Folder
instance at /a/b/c."""
- folder = self.connection.root()['Application']
+ folder = self.app #self.connection.root()['Application']
if path[0] == '/':
path = path[1:]
path = path.split('/')
@@ -214,6 +204,88 @@ class TestVirtualHosting(unittest.TestCase):
self.assertEquals(result.getHeader('Location'), location)
+class DummyPublication:
+
+ def __init__(self, app):
+ self.app = app
+
+ def beforeTraversal(self, request):
+ """Pre-traversal hook.
+
+ This is called *once* before any traversal has been done.
+ """
+
+ def getApplication(self, request):
+ """Returns the object where traversal should commence.
+ """
+ return self.app
+
+ def callTraversalHooks(self, request, ob):
+ """Invokes any traversal hooks associated with the object.
+
+ This is called before traversing each object. The ob argument
+ is the object that is about to be traversed.
+ """
+
+ def traverseName(self, request, ob, name):
+ """Traverses to the next object.
+
+ Name must be an ASCII string or Unicode object."""
+ if name == 'index.html':
+ from zope.component import queryMultiAdapter
+ view = queryMultiAdapter((ob, request), name=name)
+ if view is None:
+ from zope.publisher.interfaces import NotFound
+ raise NotFound(ob, name)
+ return view
+ else:
+ from zope.traversing.publicationtraverse \
+ import PublicationTraverserWithoutProxy
+ t = PublicationTraverserWithoutProxy()
+ return t.traverseName(request, ob, name)
+
+ def afterTraversal(self, request, ob):
+ """Post-traversal hook.
+
+ This is called after all traversal.
+ """
+
+ 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 afterCall(self, request, ob):
+ """Post-callObject hook (if it was successful).
+ """
+
+ def handleException(self, ob, request, exc_info, retry_allowed=1):
+ """Handle an exception
+
+ Either:
+ - sets the body of the response, request.response, or
+ - raises a Retry exception, or
+ - throws another exception, which is a Bad Thing.
+ """
+ import traceback
+ traceback.print_exception(*exc_info)
+
+ def endRequest(self, request, ob):
+ """Do any end-of-request cleanup
+ """
+
+ def getDefaultTraversal(self, request, ob):
+ if hasattr(ob, 'index'):
+ return ob, ()
+ else:
+ return ob, ('index.html',)
+
+
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestVirtualHosting))