Commit b8046958 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Avoid setting method ids starting with __.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@17074 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ce12cdf5
...@@ -1486,50 +1486,33 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn, ...@@ -1486,50 +1486,33 @@ class Folder(CopyContainer, CMFBTreeFolder, CMFHBTreeFolder, Base, FolderMixIn,
# We browse all used class from btree and hbtree and set not implemented # We browse all used class from btree and hbtree and set not implemented
# class if one method defined on a class is not defined on other, thus if # class if one method defined on a class is not defined on other, thus if
# new method appears in one class if will raise in the other one # new method appears in one class if will raise in the other one
class NotImplementedClass: class NotImplementedClass(object):
def __init__(self, method_id): def __init__(self, method_id):
self.__name__ = method_id self.__name__ = method_id
def __call__(self, *args, **kw): def __call__(self, *args, **kw):
raise NotImplementedError, str(self.__name__) raise NotImplementedError, str(self.__name__)
# Check method on HBTree but not on BTree for source_klass, destination_klass in \
hbtree_method_id_list = [x for x in HBTreeFolder2Base.__dict__ (
if callable(getattr(HBTreeFolder2Base, x))] # Check method on HBTree but not on BTree
for method_id in hbtree_method_id_list: (HBTreeFolder2Base, BTreeFolder2Base),
if getattr(BTreeFolder2Base, method_id, None) is None: (HBTreeFolder2, BTreeFolder2),
setattr(BTreeFolder2Base, method_id, NotImplementedClass(method_id)) (CMFHBTreeFolder, CMFBTreeFolder),
# Check method on BTree but not on HBTree
hbtree_method_id_list = [x for x in HBTreeFolder2.__dict__ (BTreeFolder2Base, HBTreeFolder2Base),
if callable(getattr(HBTreeFolder2, x))] (BTreeFolder2, HBTreeFolder2),
for method_id in hbtree_method_id_list: (CMFBTreeFolder, CMFHBTreeFolder),
if getattr(BTreeFolder2, method_id, None) is None: ):
setattr(BTreeFolder2, method_id, NotImplementedClass(method_id)) # It is better to avoid methods starting with ___, because they have
# special meanings in Python or Zope, and lead to strange errors
hbtree_method_id_list = [x for x in CMFHBTreeFolder.__dict__ # when set to an unexpected value. In fact, __implemented__ should not
if callable(getattr(CMFHBTreeFolder, x))] # be set this way, otherwise Zope crashes.
for method_id in hbtree_method_id_list: method_id_list = [x for x in source_klass.__dict__.iterkeys()
if getattr(CMFBTreeFolder, method_id, None) is None: if not x.startswith('__') and callable(getattr(source_klass, x))]
setattr(CMFBTreeFolder, method_id, NotImplementedClass(method_id)) for method_id in method_id_list:
if not hasattr(destination_klass, method_id):
# Check method on BTree but not on HBTree setattr(destination_klass, method_id, NotImplementedClass(method_id))
btree_method_id_list = [x for x in BTreeFolder2Base.__dict__
if callable(getattr(BTreeFolder2Base, x))]
for method_id in btree_method_id_list:
if getattr(HBTreeFolder2Base, method_id, None) is None:
setattr(HBTreeFolder2Base, method_id, NotImplementedClass(method_id))
btree_method_id_list = [x for x in BTreeFolder2.__dict__
if callable(getattr(BTreeFolder2, x))]
for method_id in btree_method_id_list:
if getattr(HBTreeFolder2, method_id, None) is None:
setattr(HBTreeFolder2, method_id, NotImplementedClass(method_id))
btree_method_id_list = [x for x in CMFBTreeFolder.__dict__
if callable(getattr(CMFBTreeFolder, x))]
for method_id in btree_method_id_list:
if getattr(CMFHBTreeFolder, method_id, None) is None:
setattr(CMFHBTreeFolder, method_id, NotImplementedClass(method_id))
# Overwrite Zope setTitle() # Overwrite Zope setTitle()
Folder.setTitle = Base.setTitle Folder.setTitle = Base.setTitle
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment