[Zope-Checkins]
SVN: Products.Five/branches/regebro-traversal_refactor/
Removed some no longer used code.
Lennart Regebro
regebro at gmail.com
Thu Apr 27 11:07:45 EDT 2006
Log message for revision 67647:
Removed some no longer used code.
Deprecated the no longer needed BrowserDefault adapter.
Changed:
U Products.Five/branches/regebro-traversal_refactor/browser/tests/defaultview.zcml
U Products.Five/branches/regebro-traversal_refactor/browser/tests/test_defaultview.py
U Products.Five/branches/regebro-traversal_refactor/browser/tests/test_recurse.py
U Products.Five/branches/regebro-traversal_refactor/configure.zcml
U Products.Five/branches/regebro-traversal_refactor/fiveconfigure.py
U Products.Five/branches/regebro-traversal_refactor/tests/test_viewable.py
U Products.Five/branches/regebro-traversal_refactor/tests/viewable.txt
U Products.Five/branches/regebro-traversal_refactor/viewable.py
-=-
Modified: Products.Five/branches/regebro-traversal_refactor/browser/tests/defaultview.zcml
===================================================================
--- Products.Five/branches/regebro-traversal_refactor/browser/tests/defaultview.zcml 2006-04-27 14:08:06 UTC (rev 67646)
+++ Products.Five/branches/regebro-traversal_refactor/browser/tests/defaultview.zcml 2006-04-27 15:07:44 UTC (rev 67647)
@@ -2,9 +2,6 @@
xmlns:browser="http://namespaces.zope.org/browser"
xmlns:five="http://namespaces.zope.org/five">
- <five:defaultViewable
- class="Products.Five.tests.testing.simplecontent.SimpleContent" />
-
<browser:page
for="Products.Five.tests.testing.simplecontent.ISimpleContent"
name="eagledefaultview.txt"
Modified: Products.Five/branches/regebro-traversal_refactor/browser/tests/test_defaultview.py
===================================================================
--- Products.Five/branches/regebro-traversal_refactor/browser/tests/test_defaultview.py 2006-04-27 14:08:06 UTC (rev 67646)
+++ Products.Five/branches/regebro-traversal_refactor/browser/tests/test_defaultview.py 2006-04-27 15:07:44 UTC (rev 67647)
@@ -46,7 +46,18 @@
>>> uf = self.folder.acl_users
>>> uf._doAddUser('manager', 'r00t', ['Manager'], [])
- Test that index.html is still the default view:
+ BBB This is a test of backwards comaptibility with Five 1.3/Zope2.9.
+ The deprecated directive five:defaultViewable would before make
+ index.html the default view. Test that this is still the case.
+ five:defaultViewable goes away in Zope 2.12, and this test goes then too:
+ >>> import zope.deprecation
+ >>> zope.deprecation.__show__.off()
+ >>> zcml.load_string('''
+ ... <configure xmlns:five="http://namespaces.zope.org/five">
+ ... <five:defaultViewable
+ ... class="Products.Five.tests.testing.simplecontent.SimpleContent" />
+ ... </configure>''')
+ >>> zope.deprecation.__show__.on()
>>> print http(r'''
... GET /test_folder_1_/testoid HTTP/1.1
... Authorization: Basic manager:r00t
Modified: Products.Five/branches/regebro-traversal_refactor/browser/tests/test_recurse.py
===================================================================
--- Products.Five/branches/regebro-traversal_refactor/browser/tests/test_recurse.py 2006-04-27 14:08:06 UTC (rev 67646)
+++ Products.Five/branches/regebro-traversal_refactor/browser/tests/test_recurse.py 2006-04-27 15:07:44 UTC (rev 67647)
@@ -42,12 +42,8 @@
... return 'foo'
...
- Now we make the class default viewable and register a default view
- name for it:
+ Now we register a default view name for the class:
- >>> from Products.Five.fiveconfigure import classDefaultViewable
- >>> #classDefaultViewable(Recurse)
-
>>> from zope.component import provideAdapter
>>> from zope.publisher.interfaces.browser import IBrowserRequest
>>> from zope.component.interfaces import IDefaultViewName
Modified: Products.Five/branches/regebro-traversal_refactor/configure.zcml
===================================================================
--- Products.Five/branches/regebro-traversal_refactor/configure.zcml 2006-04-27 14:08:06 UTC (rev 67646)
+++ Products.Five/branches/regebro-traversal_refactor/configure.zcml 2006-04-27 15:07:44 UTC (rev 67647)
@@ -29,12 +29,6 @@
provides="zope.app.traversing.interfaces.ITraverser"
/>
- <adapter
- for="*"
- factory=".viewable.BrowserDefault"
- provides=".interfaces.IBrowserDefault"
- />
-
<!-- this is really lying, but it's to please checkContainer -->
<five:implements class="OFS.ObjectManager.ObjectManager"
interface="zope.app.container.interfaces.IContainer" />
Modified: Products.Five/branches/regebro-traversal_refactor/fiveconfigure.py
===================================================================
--- Products.Five/branches/regebro-traversal_refactor/fiveconfigure.py 2006-04-27 14:08:06 UTC (rev 67646)
+++ Products.Five/branches/regebro-traversal_refactor/fiveconfigure.py 2006-04-27 15:07:44 UTC (rev 67647)
@@ -26,6 +26,7 @@
import App.config
import Products
+import zope.deprecation
from zope.interface import classImplements, classImplementsOnly, implementedBy
from zope.interface.interface import InterfaceClass
from zope.configuration import xmlconfig
@@ -37,10 +38,11 @@
from zope.app.component.metaconfigure import adapter
from zope.app.security.interfaces import IPermission
-from Products.Five.viewable import Viewable
+#from Products.Five.viewable import Viewable
from Products.Five.traversable import Traversable
from Products.Five.bridge import fromZ2Interface
from Products.Five.browser.metaconfigure import page
+from Products.Five.interfaces import IBrowserDefault
debug_mode = App.config.getConfiguration().debug_mode
LOG = logging.getLogger('Five')
@@ -146,57 +148,17 @@
callable = classTraversable,
args = (class_,)
)
-
-_defaultviewable_monkies = []
-def classDefaultViewable(class_):
- # XXX deprecated, can be removed
- # If a class already has this attribute, it means it is either a
- # subclass of DefaultViewable or was already processed with this
- # directive; in either case, do nothing... except in the case were
- # the class overrides the attribute instead of getting it from
- # a base class. In this case, we suppose that the class probably
- # didn't bother with the base classes attribute anyway.
- if hasattr(class_, '__five_viewable__'):
- if (hasattr(class_, '__browser_default__') and
- isFiveMethod(class_.__browser_default__)):
- return
-
- if hasattr(class_, '__browser_default__'):
- # if there's an existing __browser_default__ hook already, use that
- # as the fallback
- if not isFiveMethod(class_.__browser_default__):
- setattr(class_, '__fallback_default__', class_.__browser_default__)
- if not hasattr(class_, '__fallback_default__'):
- setattr(class_, '__fallback_default__',
- Viewable.__fallback_default__.im_func)
-
- setattr(class_, '__browser_default__',
- Viewable.__browser_default__.im_func)
- setattr(class_, '__five_viewable__', True)
- # remember class for clean up
- _defaultviewable_monkies.append(class_)
-
-from zope.component import getSiteManager, provideAdapter
-from zope.interface import providedBy
-from zope.publisher.interfaces.browser import IBrowserRequest
-from zope.component.interfaces import IDefaultViewName
-from interfaces import IBrowserDefault
-
+
def defaultViewable(_context, class_):
- warnings.warn("The five:defaultViewable statement is no longer needed " \
- "and will be removed in Zope 2.12. \n If you rely on it " \
- "to make 'index.html' the default view, replace it with " \
- "<browser:defaultView name='index.html' />",
+ if zope.deprecation.__show__():
+ warnings.warn("The five:defaultViewable statement is no longer " \
+ "needed and will be removed in Zope 2.12. \n If you rely " \
+ "on it to make 'index.html' the default view, replace it " \
+ "with <browser:defaultView name='index.html' />",
DeprecationWarning, 2)
implements(_context, class_, (IBrowserDefault,))
- return
- # XXX old code
- #_context.action(
- #discriminator = None,
- #callable = classDefaultViewable,
- #args = (class_,)
- #)
+
def createZope2Bridge(zope2, package, name):
# Map a Zope 2 interface into a Zope3 interface, seated within 'package'
# as 'name'.
@@ -302,11 +264,11 @@
killMonkey(class_, '__bobo_traverse__', '__fallback_traverse__',
'__five_traversable__')
-def undefaultViewable(class_):
- """Restore class's initial state with respect to being default
- viewable."""
- killMonkey(class_, '__browser_default__', '__fallback_default__',
- '__five_viewable__')
+#def undefaultViewable(class_):
+ #"""Restore class's initial state with respect to being default
+ #viewable."""
+ #killMonkey(class_, '__browser_default__', '__fallback_default__',
+ #'__five_viewable__')
def unregisterClass(class_):
delattr(class_, 'meta_type')
@@ -321,10 +283,10 @@
untraversable(class_)
_traversable_monkies = []
- global _defaultviewable_monkies
- for class_ in _defaultviewable_monkies:
- undefaultViewable(class_)
- _defaultviewable_monkies = []
+ #global _defaultviewable_monkies
+ #for class_ in _defaultviewable_monkies:
+ #undefaultViewable(class_)
+ #_defaultviewable_monkies = []
global _register_monkies
for class_ in _register_monkies:
Modified: Products.Five/branches/regebro-traversal_refactor/tests/test_viewable.py
===================================================================
--- Products.Five/branches/regebro-traversal_refactor/tests/test_viewable.py 2006-04-27 14:08:06 UTC (rev 67646)
+++ Products.Five/branches/regebro-traversal_refactor/tests/test_viewable.py 2006-04-27 15:07:44 UTC (rev 67647)
@@ -40,6 +40,11 @@
and default view names for everything and IFoo objects in particular:
+ >>> from zope.app.component.metaconfigure import adapter
+ >>> from Products.Five.viewable import BrowserDefault
+ >>> from Products.Five.interfaces import IBrowserDefault
+ >>> from zope.interface import Interface
+ >>> provideAdapter(BrowserDefault, (Interface,), IBrowserDefault)
>>> provideAdapter(u'index.html', (None, IBrowserRequest), IDefaultViewName)
>>> provideAdapter(u'foo.html', (IFoo, IBrowserRequest), IDefaultViewName)
Modified: Products.Five/branches/regebro-traversal_refactor/tests/viewable.txt
===================================================================
--- Products.Five/branches/regebro-traversal_refactor/tests/viewable.txt 2006-04-27 14:08:06 UTC (rev 67646)
+++ Products.Five/branches/regebro-traversal_refactor/tests/viewable.txt 2006-04-27 15:07:44 UTC (rev 67647)
@@ -66,8 +66,8 @@
Now make the class default viewable:
- >>> from Products.Five.fiveconfigure import classDefaultViewable
- >>> from OFS.Folder import Folder
+ >>> #from Products.Five.fiveconfigure import classDefaultViewable
+ >>> #from OFS.Folder import Folder
>>> #classDefaultViewable(Folder)
And try it again:
Modified: Products.Five/branches/regebro-traversal_refactor/viewable.py
===================================================================
--- Products.Five/branches/regebro-traversal_refactor/viewable.py 2006-04-27 14:08:06 UTC (rev 67646)
+++ Products.Five/branches/regebro-traversal_refactor/viewable.py 2006-04-27 15:07:44 UTC (rev 67647)
@@ -27,81 +27,19 @@
_marker = object
-class Viewable:
- """A mixin to make an object viewable.
- """
- __five_viewable__ = True
+import warnings
+import zope.deprecation
- def __fallback_default__(self, request):
- """Try to dispatch to existing index_html or __call__"""
- if getattr(self, 'index_html', None):
- return self, ('index_html',)
- if getattr(self, 'fallback_call__', None):
- return self, ('fallback_call__',)
- # XXX Should never get this far. But if it does?
-
- # def fallback_call__(self, *args, **kw):
- # """By default, return self"""
- # return self
-
- # we have a default view, tell zpublisher to go there
- def __browser_default__(self, request):
- obj = self
- path = None
- if request['REQUEST_METHOD'] not in ('GET', 'POST'):
- return obj, [request['REQUEST_METHOD']]
- try:
- obj, path = IBrowserDefault(self).defaultView(request)
- except ComponentLookupError:
- pass
- if path:
- if len(path) == 1 and path[0] == '__call__':
- return obj, ('fallback_call__',)
- return obj, path
- return self.__fallback_default__(request)
- __browser_default__.__five_method__ = True
-
- # this is technically not needed because ZPublisher finds our
- # attribute through __browser_default__; but we also want to be
- # able to call pages from python modules, PythonScripts or ZPT
- # def __call__(self, *args, **kw):
- # """ """
- # request = kw.get('REQUEST')
- # if not IBrowserRequest.providedBy(request):
- # request = getattr(self, 'REQUEST', None)
- # if not IBrowserRequest.providedBy(request):
- # request = FakeRequest()
- # obj, path = self.__browser_default__(request)
- # if path and not simpleRecursion():
- # meth = obj.unrestrictedTraverse(path)
- # if meth is not None:
- # return meth(*args, **kw)
- # return self.fallback_call__(*args, **kw)
- # __call__.__five_method__ = True
-
-# def simpleRecursion():
-# # This tests for simple recursion, which can easily happen
-# # in CMF, like the following:
-# # - Object has a method named 'view'
-# # - 'view' method calls '__call__'
-# # - five:viewable overrides call to use '__browser_default__'
-# # to find a default view and call it
-# # - defaultView is set to 'view'
-# # Bang. Infinite recursion.
-# stack = inspect.stack()
-# try:
-# if len(stack) < 4:
-# return False
-# if stack[2][1:4] == stack[4][1:4]:
-# return True
-# finally:
-# del stack
-# return False
-
class BrowserDefault(object):
implements(IBrowserDefault)
def __init__(self, context):
+ if zope.deprecation.__show__():
+ warnings.warn("The BrowserDefault class is no longer needed and " \
+ "will be removed in Zope 2.12. \n If you rely on " \
+ "it to get the default view, replace the call with " \
+ "zope.app.publisher.browser.queryDefaultViewName",
+ DeprecationWarning, 2)
self.context = context
def defaultView(self, request):
More information about the Zope-Checkins
mailing list