[Zope3-checkins]
SVN: Zope3/branches/srichter-blow-services/src/zope/
- Fixed deprecation proxy to work correctly.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Sun Feb 13 11:04:04 EST 2005
Log message for revision 29134:
- Fixed deprecation proxy to work correctly.
- Added feature to temporarly turn off deprecation warnings.
- Made sure that Zope does not create any deprecation warnings during
startup.
Changed:
U Zope3/branches/srichter-blow-services/src/zope/app/authentication/authentication.py
U Zope3/branches/srichter-blow-services/src/zope/app/pluggableauth/configure.zcml
U Zope3/branches/srichter-blow-services/src/zope/app/pluggableauth/tests/test_pluggableauth.py
U Zope3/branches/srichter-blow-services/src/zope/app/site/metaconfigure.py
U Zope3/branches/srichter-blow-services/src/zope/app/site/service.py
U Zope3/branches/srichter-blow-services/src/zope/app/testing/setup.py
U Zope3/branches/srichter-blow-services/src/zope/app/utility/__init__.py
U Zope3/branches/srichter-blow-services/src/zope/app/zopeappgenerations/evolve1.py
U Zope3/branches/srichter-blow-services/src/zope/configuration/config.py
U Zope3/branches/srichter-blow-services/src/zope/deprecation/README.txt
U Zope3/branches/srichter-blow-services/src/zope/deprecation/__init__.py
U Zope3/branches/srichter-blow-services/src/zope/deprecation/deprecation.py
-=-
Modified: Zope3/branches/srichter-blow-services/src/zope/app/authentication/authentication.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/authentication/authentication.py 2005-02-13 11:36:27 UTC (rev 29133)
+++ Zope3/branches/srichter-blow-services/src/zope/app/authentication/authentication.py 2005-02-13 16:04:04 UTC (rev 29134)
@@ -15,7 +15,6 @@
$Id$
"""
-
from zope.event import notify
import zope.interface
import zope.schema
@@ -26,9 +25,9 @@
from zope.security.interfaces import IGroupAwarePrincipal, IGroup
from zope.app.security.interfaces import IAuthentication
from zope.app.security.interfaces import IAuthenticatedGroup, IEveryoneGroup
-from zope.app.utility.utility import queryNextUtility
+from zope.app.component import queryNextUtility
from zope.app.container.contained import Contained
-from zope.app.utility.interfaces import ILocalUtility
+from zope.app.component.interfaces import ILocalUtility
from zope.app.location.interfaces import ILocation
from zope.app.authentication.interfaces import IExtractionPlugin
Modified: Zope3/branches/srichter-blow-services/src/zope/app/pluggableauth/configure.zcml
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/pluggableauth/configure.zcml 2005-02-13 11:36:27 UTC (rev 29133)
+++ Zope3/branches/srichter-blow-services/src/zope/app/pluggableauth/configure.zcml 2005-02-13 16:04:04 UTC (rev 29134)
@@ -2,7 +2,7 @@
xmlns="http://namespaces.zope.org/zope"
xmlns:browser="http://namespaces.zope.org/browser">
- <localService class=".PluggableAuthentication">
+ <localUtility class=".PluggableAuthentication">
<factory
id="zope.app.services.PluggableAuthentication"
/>
@@ -24,7 +24,7 @@
permission="zope.ManageSite"
interface="zope.app.site.interfaces.ISimpleService"
/>
- </localService>
+ </localUtility>
<subscriber
for=".interfaces.IPluggableAuthentication
Modified: Zope3/branches/srichter-blow-services/src/zope/app/pluggableauth/tests/test_pluggableauth.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/pluggableauth/tests/test_pluggableauth.py 2005-02-13 11:36:27 UTC (rev 29133)
+++ Zope3/branches/srichter-blow-services/src/zope/app/pluggableauth/tests/test_pluggableauth.py 2005-02-13 16:04:04 UTC (rev 29134)
@@ -159,12 +159,13 @@
def test_suite():
- t1 = makeSuite(AuthUtilityTest)
- t2 = DocTestSuite('zope.app.pluggableauth',
- setUp=setUp, tearDown=tearDown)
- t3 = makeSuite(BTreePrincipalSourceTest)
- t4 = makeSuite(PrincipalAuthenticationViewTest)
- return TestSuite((t1, t2, t3, t4))
+ return TestSuite((
+ makeSuite(AuthUtilityTest),
+ DocTestSuite('zope.app.pluggableauth',
+ setUp=setUp, tearDown=tearDown),
+ makeSuite(BTreePrincipalSourceTest),
+ makeSuite(PrincipalAuthenticationViewTest)
+ ))
if __name__=='__main__':
Modified: Zope3/branches/srichter-blow-services/src/zope/app/site/metaconfigure.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/site/metaconfigure.py 2005-02-13 11:36:27 UTC (rev 29133)
+++ Zope3/branches/srichter-blow-services/src/zope/app/site/metaconfigure.py 2005-02-13 16:04:04 UTC (rev 29134)
@@ -16,13 +16,14 @@
$Id$
"""
__docformat__ = "reStructuredText"
-from zope.deprecation import deprecated
+import zope.deprecation
from zope.interface import classImplements
from zope.app.component.contentdirective import ContentDirective
-from interfaces import ISimpleService
+zope.deprecation.__show__.off()
+from zope.app.site.interfaces import ISimpleService
+zope.deprecation.__show__.on()
-
class LocalServiceDirective(ContentDirective):
def __init__(self, _context, class_):
@@ -30,6 +31,7 @@
classImplements(class_, ISimpleService)
super(LocalServiceDirective, self).__init__(_context, class_)
-deprecated('LocalServiceDirective',
- 'The concept of services has been removed. Use utilities instead. '
- 'The reference will be gone in X3.3.')
+zope.deprecation.deprecated(
+ 'LocalServiceDirective',
+ 'The concept of services has been removed. Use utilities instead. '
+ 'The reference will be gone in X3.3.')
Modified: Zope3/branches/srichter-blow-services/src/zope/app/site/service.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/site/service.py 2005-02-13 11:36:27 UTC (rev 29133)
+++ Zope3/branches/srichter-blow-services/src/zope/app/site/service.py 2005-02-13 16:04:04 UTC (rev 29134)
@@ -17,22 +17,26 @@
"""
__docformat__ = "reStructuredText"
import zope.interface
-from zope.deprecation import deprecated
+import zope.deprecation
from zope.app.component.site import LocalSiteManager, UtilityRegistration
from zope.app.component.interfaces.registration import \
IRegisterableContainerContaining as IRegisterableContainerContainer
+zope.deprecation.__show__.off()
from interfaces import IServiceRegistration
+zope.deprecation.__show__.on()
-deprecated(('SiteManager', 'UtilityRegistration'),
- 'This class has been moved to zope.app.component.site. '
- 'The reference will be gone in X3.3.')
+zope.deprecation.deprecated(
+ ('SiteManager', 'UtilityRegistration'),
+ 'This class has been moved to zope.app.component.site. '
+ 'The reference will be gone in X3.3.')
-deprecated('IRegisterableContainerContainer',
- 'This interface has been moved to zope.app.component.interfaces '
- 'and been renamed to IRegisterableContainerContaining. '
- 'The reference will be gone in X3.3.')
+zope.deprecation.deprecated(
+ 'IRegisterableContainerContainer',
+ 'This interface has been moved to zope.app.component.interfaces '
+ 'and been renamed to IRegisterableContainerContaining. '
+ 'The reference will be gone in X3.3.')
ServiceManager = LocalSiteManager
SiteManager = LocalSiteManager
@@ -40,6 +44,7 @@
class ServiceRegistration(UtilityRegistration):
zope.interface.implements(IServiceRegistration)
-deprecated(('ServiceManager', 'ServiceRegistration'),
- 'The concept of services has been removed. Use utilities instead. '
- 'The reference will be gone in X3.3.')
+zope.deprecation.deprecated(
+ ('ServiceManager', 'ServiceRegistration'),
+ 'The concept of services has been removed. Use utilities instead. '
+ 'The reference will be gone in X3.3.')
Modified: Zope3/branches/srichter-blow-services/src/zope/app/testing/setup.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/testing/setup.py 2005-02-13 11:36:27 UTC (rev 29133)
+++ Zope3/branches/srichter-blow-services/src/zope/app/testing/setup.py 2005-02-13 16:04:04 UTC (rev 29134)
@@ -25,8 +25,13 @@
#############################################################################
# BBB: Goes away in 3.3
+import zope.deprecation
+
+zope.deprecation.__show__.off()
from zope.component.bbb.service import IService
from zope.app.site.interfaces import ISimpleService
+zope.deprecation.__show__.on()
+
from zope.app.component.site import UtilityRegistration
def addService(servicemanager, name, service, suffix=''):
Modified: Zope3/branches/srichter-blow-services/src/zope/app/utility/__init__.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/utility/__init__.py 2005-02-13 11:36:27 UTC (rev 29133)
+++ Zope3/branches/srichter-blow-services/src/zope/app/utility/__init__.py 2005-02-13 16:04:04 UTC (rev 29134)
@@ -13,6 +13,10 @@
$Id: __init__.py 25177 2004-06-02 13:17:31Z jim $
"""
+import zope.deprecation
+zope.deprecation.__show__.off()
from utility import LocalUtilityService
+zope.deprecation.__show__.on()
+
from zope.app.component.site import UtilityRegistration
Modified: Zope3/branches/srichter-blow-services/src/zope/app/zopeappgenerations/evolve1.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/app/zopeappgenerations/evolve1.py 2005-02-13 11:36:27 UTC (rev 29133)
+++ Zope3/branches/srichter-blow-services/src/zope/app/zopeappgenerations/evolve1.py 2005-02-13 16:04:04 UTC (rev 29134)
@@ -16,7 +16,7 @@
$Id$
"""
__docformat__ = "reStructuredText"
-from zope.component.bbb.service import IService
+import zope.deprecation
from zope.app import zapi
from zope.app.component.interfaces.registration import IRegistrationManager
@@ -27,9 +27,14 @@
from zope.app.principalannotation.interfaces import IPrincipalAnnotationUtility
from zope.app.component.interfaces.registration import ActiveStatus
from zope.app.component.interfaces.registration import InactiveStatus
+from zope.app.zopeappgenerations import getRootFolder
+
+# Imports that are only available via backward-compatibility
+zope.deprecation.__show__.off()
+from zope.component.bbb.service import IService
from zope.app.site.interfaces import ISite, IServiceRegistration
from zope.app.utility import UtilityRegistration
-from zope.app.zopeappgenerations import getRootFolder
+zope.deprecation.__show__.on()
from zope.app.generations.utility import findObjectsProviding
Modified: Zope3/branches/srichter-blow-services/src/zope/configuration/config.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/configuration/config.py 2005-02-13 11:36:27 UTC (rev 29133)
+++ Zope3/branches/srichter-blow-services/src/zope/configuration/config.py 2005-02-13 16:04:04 UTC (rev 29134)
@@ -25,6 +25,7 @@
import zope.schema
from keyword import iskeyword
+import zope.deprecation
from zope.configuration.exceptions import ConfigurationError
from zope.configuration.interfaces import IConfigurationContext
from zope.configuration.interfaces import IGroupingContext
@@ -188,8 +189,10 @@
try:
+ zope.deprecation.__show__.off()
return getattr(mod, oname)
except AttributeError:
+ zope.deprecation.__show__.on()
# No such name, maybe it's a module that we still need to import
try:
return __import__(mname+'.'+oname, *_import_chickens)
@@ -212,6 +215,8 @@
raise ConfigurationError("Module %s has no global %s"
% (mname, oname))
+ else:
+ zope.deprecation.__show__.on()
def path(self, filename):
"""
Modified: Zope3/branches/srichter-blow-services/src/zope/deprecation/README.txt
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/deprecation/README.txt 2005-02-13 11:36:27 UTC (rev 29133)
+++ Zope3/branches/srichter-blow-services/src/zope/deprecation/README.txt 2005-02-13 16:04:04 UTC (rev 29134)
@@ -87,3 +87,75 @@
3
>>> my.splat()
4
+
+
+Temporarily Turning Off Deprecation Warnings
+--------------------------------------------
+
+In some cases it is desireable to turn off the deprecation warnings for a
+short time. To support such a feature, the `zope.deprecation` package provides
+an attribute called `__show__`. One can ask for its status by calling it:
+
+ >>> from zope.deprecation import __show__
+ >>> __show__()
+ True
+
+ >>> class Foo(object):
+ ... bar = property(lambda self: 1)
+ ... bar = deprecation.deprecated(bar, 'bar is no more.')
+ ... blah = property(lambda self: 1)
+ ... blah = deprecation.deprecated(blah, 'blah is no more.')
+ >>> foo = Foo()
+
+ >>> foo.bar
+ <string>:1: DeprecationWarning: bar is no more.
+ 1
+
+You can turn off the depraction warnings using
+
+ >>> __show__.off()
+ >>> __show__()
+ False
+
+ >>> foo.blah
+ 1
+
+Now, you can also nest several turn-offs, so that calling `off()` multiple
+times is meaningful:
+
+ >>> __show__.stack
+ [False]
+
+ >>> __show__.off()
+ >>> __show__.stack
+ [False, False]
+
+ >>> __show__.on()
+ >>> __show__.stack
+ [False]
+ >>> __show__()
+ False
+
+ >>> __show__.on()
+ >>> __show__.stack
+ []
+ >>> __show__()
+ True
+
+You can also reset `__show__` to `True`:
+
+ >>> __show__.off()
+ >>> __show__.off()
+ >>> __show__()
+ False
+
+ >>> __show__.reset()
+ >>> __show__()
+ True
+
+Finally, you cannot call `on()` without having called `off()` before:
+
+ >>> __show__.on()
+ Traceback (most recent call last):
+ ...
+ IndexError: pop from empty list
\ No newline at end of file
Modified: Zope3/branches/srichter-blow-services/src/zope/deprecation/__init__.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/deprecation/__init__.py 2005-02-13 11:36:27 UTC (rev 29133)
+++ Zope3/branches/srichter-blow-services/src/zope/deprecation/__init__.py 2005-02-13 16:04:04 UTC (rev 29134)
@@ -1,3 +1,27 @@
-# Make a Python package
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Deprecation Package
-from zope.deprecation.deprecation import deprecated
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+from zope.deprecation.deprecation import deprecated, ShowSwitch
+
+# This attribute can be used to temporarly deactivate deprecation warnings, so
+# that backward-compatibility code can import other backward-compatiblity
+# components without arnings being produced.
+
+__show__ = ShowSwitch()
+
Modified: Zope3/branches/srichter-blow-services/src/zope/deprecation/deprecation.py
===================================================================
--- Zope3/branches/srichter-blow-services/src/zope/deprecation/deprecation.py 2005-02-13 11:36:27 UTC (rev 29133)
+++ Zope3/branches/srichter-blow-services/src/zope/deprecation/deprecation.py 2005-02-13 16:04:04 UTC (rev 29134)
@@ -24,8 +24,34 @@
import warnings
import zope.proxy
+import zope.deprecation
+
+class ShowSwitch(object):
+ """Simple stack-based switch."""
+
+ def __init__(self):
+ self.stack = []
+
+ def on(self):
+ self.stack.pop()
+
+ def off(self):
+ self.stack.append(False)
+
+ def reset(self):
+ self.stack = []
+
+ def __call__(self):
+ return self.stack == []
+
+ def __repr__(self):
+ return '<ShowSwitch %s>' %(self() and 'on' or 'off')
+
+
class DeprecationProxy(zope.proxy.ProxyBase):
+ __slots__ = ('_deprecated',)
+
def __init__(self, module):
super(DeprecationProxy, self).__init__(module)
self._deprecated = {}
@@ -39,7 +65,8 @@
def __getattribute__(self, name):
if name != '_deprecated' and name in self._deprecated:
- warnings.warn(self._deprecated[name], DeprecationWarning, 2)
+ if zope.deprecation.__show__():
+ warnings.warn(self._deprecated[name], DeprecationWarning, 2)
return super(DeprecationProxy, self).__getattribute__(name)
@@ -51,25 +78,29 @@
self.prop = prop
def __get__(self, inst, klass):
- warnings.warn(self.message, DeprecationWarning, 2)
+ if zope.deprecation.__show__():
+ warnings.warn(self.message, DeprecationWarning, 2)
return self.prop.__get__(inst, klass)
class DeprecatedGetSetProperty(DeprecatedGetProperty):
def __set__(self, inst, prop):
- warnings.warn(self.message, DeprecationWarning, 2)
+ if zope.deprecation.__show__():
+ warnings.warn(self.message, DeprecationWarning, 2)
self.prop.__set__(inst, prop)
class DeprecatedGetSetDeleteProperty(DeprecatedGetSetProperty):
def __delete__(self, inst):
- warnings.warn(self.message, DeprecationWarning, 2)
+ if zope.deprecation.__show__():
+ warnings.warn(self.message, DeprecationWarning, 2)
self.prop.__delete__(inst)
def DeprecatedMethod(method, message):
def deprecated_method(self, *args, **kw):
- warnings.warn(message, DeprecationWarning, 2)
+ if zope.deprecation.__show__():
+ warnings.warn(message, DeprecationWarning, 2)
return method(self, *args, **kw)
return deprecated_method
More information about the Zope3-Checkins
mailing list