Permalink
Browse files

cleanup copy stuff, use implementer instead of implements

  • Loading branch information...
1 parent f17ab4d commit 77434382d41bf728e22c6323281c83f481351a5c Robert Niederreiter committed May 18, 2012
View
@@ -111,7 +111,7 @@ the documentation of ``plumber`` for details about the plumbing system::
'__sizeof__', '__str__', '__subclasshook__', '__weakref__',
'_nodespaces', '_notify_suppress', 'acquire', 'allow_non_node_childs',
'attribute_access_for_attrs', 'attributes', 'attributes_factory',
- 'attrs', 'clear', 'copy', 'detach', 'events', 'filtereditems',
+ 'attrs', 'clear', 'copy', 'deepcopy', 'detach', 'events', 'filtereditems',
'filtereditervalues', 'filteredvalues', 'get', 'has_key', 'items',
'iteritems', 'iterkeys', 'itervalues', 'keys', 'name', 'noderepr',
'nodespaces', 'parent', 'path', 'pop', 'popitem', 'printtree',
@@ -281,6 +281,17 @@ Contributors
Changes
=======
+0.9.7dev
+--------
+
+- ``node.parts.mapping.ClonableMapping`` nor supports deepcopy.
+ [rnix, 2012-05-18]
+
+- use ``zope.interface.implementer`` instead of ``zope.interface.implements``
+ all over the place.
+ [rnix, 2012-05-18]
+
+
0.9.6
-----
View
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages
import os
-version = '0.9.6'
+version = '0.9.7dev'
shortdesc = "The node"
longdesc = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
longdesc += open(os.path.join(os.path.dirname(__file__), 'LICENSE.rst')).read()
View
@@ -3,7 +3,7 @@
plumber,
Part,
)
-from zope.interface import implements
+from zope.interface import implementer
from zope.interface.common.mapping import (
IEnumerableMapping,
IFullMapping,
@@ -17,12 +17,12 @@
)
+@implementer(IAliaser, IFullMapping)
class DictAliaser(odict):
"""Uses its own dictionary for aliasing.
``__getitem__`` -> unalias
"""
- implements(IAliaser, IFullMapping)
def __init__(self, data=(), strict=True):
super(DictAliaser, self).__init__(data)
@@ -45,12 +45,12 @@ def unalias(self, aliased_key):
raise e
+@implementer(IAliaser)
class PrefixAliaser(object):
"""An aliaser that prefix all keys.
As it never raise KeyError it is not whitelisting.
"""
- implements(IAliaser)
def __init__(self, prefix=None):
self.prefix = prefix
@@ -68,12 +68,12 @@ def unalias(self, prefixed_key):
return prefixed_key[len(prefix):]
+@implementer(IAliaser)
class SuffixAliaser(object):
"""An aliaser that suffixes all keys.
As it never raise KeyError it is not whitelisting.
"""
- implements(IAliaser)
def __init__(self, suffix=None):
self.suffix = suffix
@@ -93,14 +93,14 @@ def unalias(self, suffixed_key):
return suffixed_key[:-len(suffix)]
+@implementer(IAliaser)
class AliaserChain(object):
"""A chain of aliasers.
chain = [aliaser1, aliaser2]
chain.alias(key) == aliaser2.alias(aliaser1.alias(key))
chain.unalias(alias_key) == aliaser2.unalias(aliaser1.unalias(aliased_key))
"""
- implements(IAliaser)
# XXX: we are IEnumerableMapping if one of our childs is, which is
# important as we become a whitelist, eg. for Node.__iter__
View
@@ -5,7 +5,6 @@
default,
extend,
)
-from zope.interface import implements
from node.interfaces import INode
from node.parts import (
Adopt,
View
@@ -40,11 +40,6 @@ Storage related operations of AbstractNode raise ``NotImplementedError``::
...
NotImplementedError
- >>> abstract_copy = abstract.copy()
- Traceback (most recent call last):
- ...
- NotImplementedError
-
>>> abstract.clear()
Traceback (most recent call last):
...
@@ -141,7 +136,6 @@ BaseNode
``update``: OK
``values``: OK
-
OrderedNode
-----------
::
@@ -505,3 +499,97 @@ XXX: decide wether ``aliases`` or ``aliaser`` (still dunno) should be kept in
Traceback (most recent call last):
...
ValueError: It isn't allowed to use classes as values.
+
+
+Copy testing
+============
+
+Shallow copy of BaseNode::
+
+ >>> import copy
+ >>> node = BaseNode()
+ >>> node['child'] = BaseNode()
+
+ >>> copied_node = node.copy()
+ >>> copied_node.printtree()
+ <class 'node.base.BaseNode'>: None
+ <class 'node.base.BaseNode'>: child
+
+ >>> node is copied_node
+ False
+
+ >>> node['child'] is copied_node['child']
+ True
+
+ >>> copied_node = copy.copy(node)
+ >>> node is copied_node
+ False
+
+ >>> node['child'] is copied_node['child']
+ True
+
+Deep copy of base node::
+
+ >>> copied_node = node.deepcopy()
+ >>> copied_node.printtree()
+ <class 'node.base.BaseNode'>: None
+ <class 'node.base.BaseNode'>: child
+
+ >>> node is copied_node
+ False
+
+ >>> node['child'] is copied_node['child']
+ False
+
+ >>> copied_node = copy.deepcopy(node)
+ >>> node is copied_node
+ False
+
+ >>> node['child'] is copied_node['child']
+ False
+
+Shallow copy of ordered node::
+
+ >>> node = OrderedNode()
+ >>> node['child'] = OrderedNode()
+
+ >>> copied_node = node.copy()
+ >>> copied_node.printtree()
+ <class 'node.base.OrderedNode'>: None
+ <class 'node.base.OrderedNode'>: child
+
+ >>> node is copied_node
+ False
+
+ >>> node['child'] is copied_node['child']
+ True
+
+ >>> copied_node = copy.copy(node)
+ >>> node is copied_node
+ False
+
+ >>> node['child'] is copied_node['child']
+ True
+
+Deep copy of ordered node::
+
+ >>> node = OrderedNode()
+ >>> node['child'] = OrderedNode()
+
+ >>> copied_node = node.deepcopy()
+ >>> copied_node.printtree()
+ <class 'node.base.OrderedNode'>: None
+ <class 'node.base.OrderedNode'>: child
+
+ >>> node is copied_node
+ False
+
+ >>> node['child'] is copied_node['child']
+ False
+
+ >>> copied_node = copy.deepcopy(node)
+ >>> node is copied_node
+ False
+
+ >>> node['child'] is copied_node['child']
+ False
View
@@ -2,7 +2,7 @@
import inspect
from odict import odict
from odict.pyodict import _nil
-from zope.interface import implements
+from zope.interface import implementer
from zope.interface.common.mapping import (
IReadMapping,
IFullMapping)
@@ -32,8 +32,8 @@
# original from zodict
###############################################################################
+@implementer(IReadMapping)
class NodeIndex(object):
- implements(IReadMapping)
def __init__(self, index):
self._index = index
@@ -48,6 +48,7 @@ def __contains__(self, key):
return int(key) in self._index
+@implementer(INode)
class _Node(object):
"""Abstract node implementation. Subclass must mixin ``_node_impl()``.
@@ -57,7 +58,6 @@ class _Node(object):
__delitem__
__iter__
"""
- implements(INode)
allow_non_node_childs = False
def _node_impl(self):
@@ -416,11 +416,10 @@ def __init__(self, node):
self._node = node
+@implementer(IAttributedNode)
class AttributedNode(Node):
"""A node that has another nodespace behind self.attrs[]
"""
- implements(IAttributedNode)
-
attributes_factory = NodeAttributes
attribute_aliases = None
@@ -474,8 +473,8 @@ def __delitem__(self, key):
objectEventNotify(self._node.events['modified'](self._node))
+@implementer(ILifecycleNode)
class LifecycleNode(AttributedNode):
- implements(ILifecycleNode)
events = {
'created': NodeCreatedEvent,
View
@@ -2,11 +2,15 @@
# XXX: used in zodict.
-from zope.interface import implements
+# XXX: get rid of!!
+
+from zope.interface import implementer
from odict import odict
from interfaces import IComposition
from bbb import Node
+
+@implementer(IComposition)
class Composition(Node):
"""
A composition is a node that has one or more nodespaces that are the base for
@@ -19,7 +23,6 @@ class Composition(Node):
- real children (composition is child.__parent__), that are compositions
factored on the base of matching children from the nodespaces
"""
- implements(IComposition)
def __init__(self, name=None, nodespaces=None):
# XXX: index support turned off for now
View
@@ -1,4 +1,4 @@
-from zope.interface import implements
+from zope.interface import implementer
try:
from zope.lifecycleevent import (
ObjectCreatedEvent,
@@ -22,17 +22,22 @@ class ObjectRemovedEvent(ObjectEvent): pass #pragma NO COVERAGE
INodeDetachedEvent,
)
-class NodeCreatedEvent(ObjectCreatedEvent):
- implements(INodeCreatedEvent)
-
-class NodeAddedEvent(ObjectAddedEvent):
- implements(INodeAddedEvent)
-class NodeModifiedEvent(ObjectModifiedEvent):
- implements(INodeModifiedEvent)
+@implementer(INodeCreatedEvent)
+class NodeCreatedEvent(ObjectCreatedEvent): pass
-class NodeRemovedEvent(ObjectRemovedEvent):
- implements(INodeRemovedEvent)
-class NodeDetachedEvent(ObjectRemovedEvent):
- implements(INodeDetachedEvent)
+@implementer(INodeAddedEvent)
+class NodeAddedEvent(ObjectAddedEvent): pass
+
+
+@implementer(INodeModifiedEvent)
+class NodeModifiedEvent(ObjectModifiedEvent): pass
+
+
+@implementer(INodeRemovedEvent)
+class NodeRemovedEvent(ObjectRemovedEvent): pass
+
+
+@implementer(INodeDetachedEvent)
+class NodeDetachedEvent(ObjectRemovedEvent): pass
View
@@ -4,10 +4,11 @@
Part,
)
from node.interfaces import IAlias
-from zope.interface import implements
+from zope.interface import implementer
from zope.interface.common.mapping import IEnumerableMapping
+@implementer(IAlias)
class Alias(Part):
"""KeyErrors are caught and reraised with the aliased key.
XXX: Could be configureable: aliased_keyerrors.
@@ -27,7 +28,6 @@ class Alias(Part):
For rerouting we would needs entrance methods, see below in commented
iteritems.
"""
- implements(IAlias)
aliaser = default(None)
@plumb
@@ -13,7 +13,7 @@
from node.parts.nodify import Nodify
from node.parts.storage import OdictStorage
from node.utils import AttributeAccess
-from zope.interface import implements
+from zope.interface import implementer
class NodeAttributes(object):
@@ -43,9 +43,8 @@ def __repr__(self):
# XXX: inherit from nodespaces part
+@implementer(IAttributes)
class Attributes(Part):
- implements(IAttributes)
-
attribute_access_for_attrs = default(False)
attributes_factory = default(NodeAttributes)
Oops, something went wrong.

0 comments on commit 7743438

Please sign in to comment.