[Zope3-checkins] SVN: Zope3/branches/jim-adapter/src/zope/app/
properly deprecate LayerField
Philipp von Weitershausen
philikon at philikon.de
Mon Apr 24 01:00:47 EDT 2006
Log message for revision 67559:
properly deprecate LayerField
Changed:
U Zope3/branches/jim-adapter/src/zope/app/component/back35.py
U Zope3/branches/jim-adapter/src/zope/app/component/fields.py
U Zope3/branches/jim-adapter/src/zope/app/component/metadirectives.py
U Zope3/branches/jim-adapter/src/zope/app/component/tests/test_fields.py
U Zope3/branches/jim-adapter/src/zope/app/container/browser/metaconfigure.py
U Zope3/branches/jim-adapter/src/zope/app/form/browser/metadirectives.py
U Zope3/branches/jim-adapter/src/zope/app/publisher/browser/metadirectives.py
-=-
Modified: Zope3/branches/jim-adapter/src/zope/app/component/back35.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/component/back35.py 2006-04-23 19:28:23 UTC (rev 67558)
+++ Zope3/branches/jim-adapter/src/zope/app/component/back35.py 2006-04-24 05:00:45 UTC (rev 67559)
@@ -18,6 +18,7 @@
from persistent import Persistent
import zope.event
+import zope.schema
import zope.interface.adapter
import zope.component.interfaces
import zope.deprecation
@@ -28,6 +29,10 @@
from zope.security.checker import InterfaceChecker, CheckerPublic
from zope.security.proxy import Proxy, removeSecurityProxy
from zope.lifecycleevent import ObjectCreatedEvent
+from zope.component.interfaces import ComponentLookupError
+from zope.configuration.fields import GlobalObject
+from zope.configuration.exceptions import ConfigurationError
+from zope.publisher.interfaces.back35 import ILayer
import zope.app.component.registration
import zope.app.component.interfaces.registration
@@ -805,3 +810,94 @@
def getRegistry(self):
return zapi.getSiteManager(self)
+
+
+class LayerField(GlobalObject):
+ r"""This field represents a layer.
+
+ Besides being able to look up the layer by importing it, we also try
+ to look up the name in the site manager.
+
+ >>> from zope.interface import directlyProvides
+ >>> from zope.interface.interface import InterfaceClass
+
+ >>> layer1 = InterfaceClass('layer1', (),
+ ... __doc__='Layer: layer1',
+ ... __module__='zope.app.layers')
+ >>> directlyProvides(layer1, ILayer)
+
+ >>> layers = None
+ >>> class Resolver(object):
+ ... def resolve(self, path):
+ ... if '..' in path:
+ ... raise ValueError('Empty module name')
+ ... if (path.startswith('zope.app.layers') and
+ ... hasattr(layers, 'layer1') or
+ ... path == 'zope.app.component.fields.layer1' or
+ ... path == '.fields.layer1'):
+ ... return layer1
+ ... raise ConfigurationError('layer1')
+
+ >>> field = LayerField()
+ >>> field = field.bind(Resolver())
+
+ Test 1: Import the layer
+ ------------------------
+
+ >>> field.fromUnicode('zope.app.component.fields.layer1') is layer1
+ True
+
+ Test 2: We have a shortcut name. Import the layer from `zope.app.layers`.
+ -------------------------------------------------------------------------
+
+ >>> from types import ModuleType as module
+ >>> import sys
+ >>> layers = module('layers')
+ >>> old = sys.modules.get('zope.app.layers', None)
+ >>> sys.modules['zope.app.layers'] = layers
+ >>> setattr(layers, 'layer1', layer1)
+
+ >>> field.fromUnicode('layer1') is layer1
+ True
+
+ >>> if old is not None:
+ ... sys.modules['zope.app.layers'] = old
+
+ Test 3: Get the layer from the site manager
+ -------------------------------------------
+
+ >>> from zope.app.testing import ztapi
+ >>> ztapi.provideUtility(ILayer, layer1, 'layer1')
+
+ >>> field.fromUnicode('layer1') is layer1
+ True
+
+ Test 4: Import the layer by using a short name
+ ----------------------------------------------
+
+ >>> field.fromUnicode('.fields.layer1') is layer1
+ True
+ """
+
+ def fromUnicode(self, u):
+ name = str(u.strip())
+
+ try:
+ value = zope.component.queryUtility(ILayer, name)
+ except ComponentLookupError:
+ # The component architecture is not up and running.
+ pass
+ else:
+ if value is not None:
+ return value
+
+ try:
+ value = self.context.resolve('zope.app.layers.'+name)
+ except (ConfigurationError, ValueError), v:
+ try:
+ value = self.context.resolve(name)
+ except ConfigurationError, v:
+ raise zope.schema.ValidationError(v)
+
+ self.validate(value)
+ return value
Modified: Zope3/branches/jim-adapter/src/zope/app/component/fields.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/component/fields.py 2006-04-23 19:28:23 UTC (rev 67558)
+++ Zope3/branches/jim-adapter/src/zope/app/component/fields.py 2006-04-24 05:00:45 UTC (rev 67559)
@@ -13,108 +13,16 @@
##############################################################################
"""Component-related fields
+This module will be gone in Zope 3.5.
+
$Id$
"""
__docformat__ = 'restructuredtext'
-import zope.schema
-from zope.component.interfaces import ComponentLookupError
-from zope.configuration.exceptions import ConfigurationError
-from zope.configuration.fields import GlobalObject
-
-from zope.app import zapi
-
# BBB 2006/02/18, to be removed after 12 months
-import zope.deprecation
-from zope.publisher.interfaces.back35 import ILayer
-
-# XXX why osn't LayerField deprecated?
-class LayerField(GlobalObject):
- r"""This field represents a layer.
-
- Besides being able to look up the layer by importing it, we also try
- to look up the name in the site manager.
-
- >>> from zope.interface import directlyProvides
- >>> from zope.interface.interface import InterfaceClass
-
- >>> layer1 = InterfaceClass('layer1', (),
- ... __doc__='Layer: layer1',
- ... __module__='zope.app.layers')
- >>> directlyProvides(layer1, ILayer)
-
- >>> layers = None
- >>> class Resolver(object):
- ... def resolve(self, path):
- ... if '..' in path:
- ... raise ValueError('Empty module name')
- ... if (path.startswith('zope.app.layers') and
- ... hasattr(layers, 'layer1') or
- ... path == 'zope.app.component.fields.layer1' or
- ... path == '.fields.layer1'):
- ... return layer1
- ... raise ConfigurationError('layer1')
-
- >>> field = LayerField()
- >>> field = field.bind(Resolver())
-
- Test 1: Import the layer
- ------------------------
-
- >>> field.fromUnicode('zope.app.component.fields.layer1') is layer1
- True
-
- Test 2: We have a shortcut name. Import the layer from `zope.app.layers`.
- -------------------------------------------------------------------------
-
- >>> from types import ModuleType as module
- >>> import sys
- >>> layers = module('layers')
- >>> old = sys.modules.get('zope.app.layers', None)
- >>> sys.modules['zope.app.layers'] = layers
- >>> setattr(layers, 'layer1', layer1)
-
- >>> field.fromUnicode('layer1') is layer1
- True
-
- >>> if old is not None:
- ... sys.modules['zope.app.layers'] = old
-
- Test 3: Get the layer from the site manager
- -------------------------------------------
-
- >>> from zope.app.testing import ztapi
- >>> ztapi.provideUtility(ILayer, layer1, 'layer1')
-
- >>> field.fromUnicode('layer1') is layer1
- True
-
- Test 4: Import the layer by using a short name
- ----------------------------------------------
-
- >>> field.fromUnicode('.fields.layer1') is layer1
- True
- """
-
- def fromUnicode(self, u):
- name = str(u.strip())
-
- try:
- value = zapi.queryUtility(ILayer, name)
- except ComponentLookupError:
- # The component architecture is not up and running.
- pass
- else:
- if value is not None:
- return value
-
- try:
- value = self.context.resolve('zope.app.layers.'+name)
- except (ConfigurationError, ValueError), v:
- try:
- value = self.context.resolve(name)
- except ConfigurationError, v:
- raise zope.schema.ValidationError(v)
-
- self.validate(value)
- return value
+import zope.deferredimport
+zope.deferredimport.deprecated(
+ "It will no longer be available in Zope 3.5. Layers are just simple "
+ "interfaces now; use the GlobalInterface field instead.",
+ LayerField = 'zope.app.component.back35:LayerField',
+ )
Modified: Zope3/branches/jim-adapter/src/zope/app/component/metadirectives.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/component/metadirectives.py 2006-04-23 19:28:23 UTC (rev 67558)
+++ Zope3/branches/jim-adapter/src/zope/app/component/metadirectives.py 2006-04-24 05:00:45 UTC (rev 67559)
@@ -23,7 +23,7 @@
import zope.schema
from zope.component.zcml import IBasicComponentInformation
-import zope.app.component.fields
+from zope.app.component.back35 import LayerField
from zope.app.i18n import ZopeMessageFactory as _
class IDefaultViewName(zope.interface.Interface):
@@ -59,7 +59,7 @@
)
# BBB 2006/02/18, to be removed after 12 months
- layer = zope.app.component.fields.LayerField(
+ layer = LayerField(
title=_("The layer the view is in."),
description=_("""
A skin is composed of layers. It is common to put skin
@@ -186,7 +186,7 @@
"""Register a resource"""
# BBB 2006/02/18, to be removed after 12 months
- layer = zope.app.component.fields.LayerField(
+ layer = LayerField(
title=_("The layer the resource is in. This argument has been "
"deprecated and will be removed in Zope 3.5. Use the "
"'type' argument instead."),
Modified: Zope3/branches/jim-adapter/src/zope/app/component/tests/test_fields.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/component/tests/test_fields.py 2006-04-23 19:28:23 UTC (rev 67558)
+++ Zope3/branches/jim-adapter/src/zope/app/component/tests/test_fields.py 2006-04-24 05:00:45 UTC (rev 67559)
@@ -21,7 +21,7 @@
def test_suite():
return unittest.TestSuite((
- DocTestSuite('zope.app.component.fields',
+ DocTestSuite('zope.app.component.back35',
setUp=placelesssetup.setUp,
tearDown=placelesssetup.tearDown),
))
Modified: Zope3/branches/jim-adapter/src/zope/app/container/browser/metaconfigure.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/container/browser/metaconfigure.py 2006-04-23 19:28:23 UTC (rev 67558)
+++ Zope3/branches/jim-adapter/src/zope/app/container/browser/metaconfigure.py 2006-04-24 05:00:45 UTC (rev 67559)
@@ -26,7 +26,7 @@
from zope.app.publisher.browser.viewmeta import page, view
from zope.app.container.browser.contents import Contents
from zope.app.container.browser.adding import Adding
-from zope.app.component.fields import LayerField
+from zope.app.component.back35 import LayerField
from zope.app.i18n import ZopeMessageFactory as _
Modified: Zope3/branches/jim-adapter/src/zope/app/form/browser/metadirectives.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/form/browser/metadirectives.py 2006-04-23 19:28:23 UTC (rev 67558)
+++ Zope3/branches/jim-adapter/src/zope/app/form/browser/metadirectives.py 2006-04-24 05:00:45 UTC (rev 67559)
@@ -23,7 +23,7 @@
from zope.configuration.fields import MessageID
from zope.schema import Text, TextLine, Id
from zope.security.zcml import Permission
-from zope.app.component.fields import LayerField
+from zope.app.component.back35 import LayerField
from zope.app.publisher.browser.fields import MenuField
class ICommonInformation(Interface):
Modified: Zope3/branches/jim-adapter/src/zope/app/publisher/browser/metadirectives.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/publisher/browser/metadirectives.py 2006-04-23 19:28:23 UTC (rev 67558)
+++ Zope3/branches/jim-adapter/src/zope/app/publisher/browser/metadirectives.py 2006-04-24 05:00:45 UTC (rev 67559)
@@ -24,7 +24,7 @@
from zope.security.zcml import Permission
from zope.app.component.metadirectives import IBasicViewInformation
-from zope.app.component.fields import LayerField
+from zope.app.component.back35 import LayerField
from zope.app.publisher.browser.fields import MenuField
#
More information about the Zope3-Checkins
mailing list