Commit 6150e9df authored by Shane Hathaway's avatar Shane Hathaway

The _need__name__ protocol assigns a name to DTMLMethods implicitly

so that ExtensionClass can find the correct <name>__roles__ attribute
of the method's class.  However it was discovered that this protocol
has a flaw: if a DTMLMethod is bound to multiple names, there is no
way for default__class_init__ to tell which name is the right one.

This change adds code that detects the condition and makes the name
explicit in all places where it occurs in the Zope core.  There are
likely products out there that have the same condition so they will
need a small correction.  For now this is a warning but it might be
appropriate to later make the condition an error.
parent ff0e3677
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
############################################################################## ##############################################################################
"""Access control package""" """Access control package"""
__version__='$Revision: 1.150 $'[11:-2] __version__='$Revision: 1.151 $'[11:-2]
import Globals, socket, SpecialUsers,re import Globals, socket, SpecialUsers,re
import os import os
...@@ -746,6 +746,7 @@ class BasicUserFolder(Implicit, Persistent, Navigation, Tabs, RoleManager, ...@@ -746,6 +746,7 @@ class BasicUserFolder(Implicit, Persistent, Navigation, Tabs, RoleManager,
_editUser=DTMLFile('dtml/editUser', globals(), _editUser=DTMLFile('dtml/editUser', globals(),
remote_user_mode__=_remote_user_mode) remote_user_mode__=_remote_user_mode)
manage=manage_main=_mainUser manage=manage_main=_mainUser
manage_main._setName('manage_main')
def domainSpecValidate(self, spec): def domainSpecValidate(self, spec):
for ob in spec: for ob in spec:
......
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
# #
############################################################################## ##############################################################################
__doc__="""System management components""" __doc__="""System management components"""
__version__='$Revision: 1.73 $'[11:-2] __version__='$Revision: 1.74 $'[11:-2]
import sys,os,time,string,Globals, Acquisition, os, Undo import sys,os,time,string,Globals, Acquisition, os, Undo
...@@ -111,6 +111,7 @@ class Fake: ...@@ -111,6 +111,7 @@ class Fake:
class DatabaseManager(Fake, SimpleItem.Item, Acquisition.Implicit): class DatabaseManager(Fake, SimpleItem.Item, Acquisition.Implicit):
"""Database management""" """Database management"""
manage=manage_main=DTMLFile('dtml/dbMain', globals()) manage=manage_main=DTMLFile('dtml/dbMain', globals())
manage_main._setName('manage_main')
id ='DatabaseManagement' id ='DatabaseManagement'
name=title='Database Management' name=title='Database Management'
meta_type ='Database Management' meta_type ='Database Management'
...@@ -138,6 +139,7 @@ Globals.default__class_init__(DatabaseManager) ...@@ -138,6 +139,7 @@ Globals.default__class_init__(DatabaseManager)
class VersionManager(Fake, SimpleItem.Item, Acquisition.Implicit): class VersionManager(Fake, SimpleItem.Item, Acquisition.Implicit):
"""Version management""" """Version management"""
manage=manage_main=DTMLFile('dtml/versionManager', globals()) manage=manage_main=DTMLFile('dtml/versionManager', globals())
manage_main._setName('manage_main')
id ='Versions' id ='Versions'
name=title='Version Management' name=title='Version Management'
meta_type ='Version Management' meta_type ='Version Management'
...@@ -162,6 +164,7 @@ _v_rst=None ...@@ -162,6 +164,7 @@ _v_rst=None
class DebugManager(Fake, SimpleItem.Item, Acquisition.Implicit): class DebugManager(Fake, SimpleItem.Item, Acquisition.Implicit):
"""Debug and profiling information""" """Debug and profiling information"""
manage=manage_main=DTMLFile('dtml/debug', globals()) manage=manage_main=DTMLFile('dtml/debug', globals())
manage_main._setName('manage_main')
id ='DebugInfo' id ='DebugInfo'
name=title='Debug Information' name=title='Debug Information'
meta_type = name meta_type = name
...@@ -270,6 +273,7 @@ class ApplicationManager(Folder,CacheManager): ...@@ -270,6 +273,7 @@ class ApplicationManager(Folder,CacheManager):
DavLocks = DavLockManager() DavLocks = DavLockManager()
manage=manage_main=DTMLFile('dtml/cpContents', globals()) manage=manage_main=DTMLFile('dtml/cpContents', globals())
manage_main._setName('manage_main')
def version_txt(self): def version_txt(self):
if not hasattr(self, '_v_version_txt'): if not hasattr(self, '_v_version_txt'):
......
...@@ -83,7 +83,7 @@ ...@@ -83,7 +83,7 @@
# #
############################################################################## ##############################################################################
__version__ = "$Revision: 1.4 $"[11:-2] __version__ = "$Revision: 1.5 $"[11:-2]
import OFS, Acquisition, Globals import OFS, Acquisition, Globals
from AccessControl import getSecurityManager, ClassSecurityInfo from AccessControl import getSecurityManager, ClassSecurityInfo
...@@ -103,6 +103,7 @@ class DavLockManager(OFS.SimpleItem.Item, Acquisition.Implicit): ...@@ -103,6 +103,7 @@ class DavLockManager(OFS.SimpleItem.Item, Acquisition.Implicit):
manage_davlocks=manage_main=manage=Globals.DTMLFile( manage_davlocks=manage_main=manage=Globals.DTMLFile(
'dtml/davLockManager', globals()) 'dtml/davLockManager', globals())
manage_davlocks._setName('manage_davlocks')
manage_options = ( manage_options = (
{'label': 'Write Locks', 'action': 'manage_main', {'label': 'Write Locks', 'action': 'manage_main',
......
...@@ -98,8 +98,24 @@ def default__class_init__(self): ...@@ -98,8 +98,24 @@ def default__class_init__(self):
dict_items=dict.items() dict_items=dict.items()
for name, v in dict_items: for name, v in dict_items:
if hasattr(v,'_need__name__') and v._need__name__: if getattr(v, '_need__name__', 0):
v.__dict__['__name__']=name d = v.__dict__
oldname = d.get('__name__', '')
if d.get('_implicit__name__', 0):
# Already supplied a name.
if name != oldname:
# Tried to implicitly assign a different name!
try: classname = '%s.%s' % (
self.__module__, self.__name__)
except AttributeError: classname = `self`
from zLOG import LOG, WARNING
LOG('Init', WARNING, 'Ambiguous name for method of %s: '
'"%s" != "%s"' % (classname, d['__name__'], name))
else:
# Supply a name implicitly so that the method can
# find the security assertions on its container.
d['_implicit__name__'] = 1
d['__name__']=name
if name=='manage' or name[:7]=='manage_': if name=='manage' or name[:7]=='manage_':
name=name+'__roles__' name=name+'__roles__'
if not have(name): dict[name]=('Manager',) if not have(name): dict[name]=('Manager',)
......
...@@ -121,6 +121,10 @@ class ClassicHTMLFile(DocumentTemplate.HTMLFile,MethodObject.Method,): ...@@ -121,6 +121,10 @@ class ClassicHTMLFile(DocumentTemplate.HTMLFile,MethodObject.Method,):
self.cook() self.cook()
if not changed: self.__changed__(0) if not changed: self.__changed__(0)
def _setName(self, name):
self.__name__ = name
self._need__name__ = 0
def __call__(self, *args, **kw): def __call__(self, *args, **kw):
self._cook_check() self._cook_check()
return apply(HTMLFile.inheritedAttribute('__call__'), return apply(HTMLFile.inheritedAttribute('__call__'),
......
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
############################################################################## ##############################################################################
"""DTML Method objects.""" """DTML Method objects."""
__version__='$Revision: 1.65 $'[11:-2] __version__='$Revision: 1.66 $'[11:-2]
import History import History
from Globals import HTML, DTMLFile, MessageDialog from Globals import HTML, DTMLFile, MessageDialog
...@@ -265,6 +265,7 @@ class DTMLMethod(HTML, Acquisition.Implicit, RoleManager, ...@@ -265,6 +265,7 @@ class DTMLMethod(HTML, Acquisition.Implicit, RoleManager,
return full_read_guard(ob) return full_read_guard(ob)
manage_editForm=DTMLFile('dtml/documentEdit', globals()) manage_editForm=DTMLFile('dtml/documentEdit', globals())
manage_editForm._setName('manage_editForm')
# deprecated! # deprecated!
manage_uploadForm=manage_editForm manage_uploadForm=manage_editForm
......
...@@ -84,7 +84,7 @@ ...@@ -84,7 +84,7 @@
############################################################################## ##############################################################################
"""Image object""" """Image object"""
__version__='$Revision: 1.129 $'[11:-2] __version__='$Revision: 1.130 $'[11:-2]
import Globals, string, struct import Globals, string, struct
from OFS.content_types import guess_content_type from OFS.content_types import guess_content_type
...@@ -146,7 +146,7 @@ class File(Persistent, Implicit, PropertyManager, ...@@ -146,7 +146,7 @@ class File(Persistent, Implicit, PropertyManager,
manage_editForm =DTMLFile('dtml/fileEdit',globals(), manage_editForm =DTMLFile('dtml/fileEdit',globals(),
Kind='File',kind='file') Kind='File',kind='file')
manage_editForm._setName('manage_editForm')
manage=manage_main=manage_editForm manage=manage_main=manage_editForm
manage_uploadForm=manage_editForm manage_uploadForm=manage_editForm
...@@ -736,7 +736,7 @@ class Image(File): ...@@ -736,7 +736,7 @@ class Image(File):
manage_editForm =DTMLFile('dtml/imageEdit',globals(), manage_editForm =DTMLFile('dtml/imageEdit',globals(),
Kind='Image',kind='image') Kind='Image',kind='image')
view_image_or_file =DTMLFile('dtml/imageView',globals()) view_image_or_file =DTMLFile('dtml/imageView',globals())
manage_editForm._setName('manage_editForm')
manage=manage_main=manage_editForm manage=manage_main=manage_editForm
manage_uploadForm=manage_editForm manage_uploadForm=manage_editForm
......
...@@ -84,8 +84,8 @@ ...@@ -84,8 +84,8 @@
############################################################################## ##############################################################################
"""SMTP mail objects """SMTP mail objects
$Id: MailHost.py,v 1.60 2001/01/11 15:03:52 chrism Exp $""" $Id: MailHost.py,v 1.61 2001/06/07 22:18:44 shane Exp $"""
__version__ = "$Revision: 1.60 $"[11:-2] __version__ = "$Revision: 1.61 $"[11:-2]
from Globals import Persistent, DTMLFile, HTML, MessageDialog from Globals import Persistent, DTMLFile, HTML, MessageDialog
from smtplib import SMTP from smtplib import SMTP
...@@ -128,6 +128,7 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager): ...@@ -128,6 +128,7 @@ class MailBase(Acquisition.Implicit, OFS.SimpleItem.Item, RoleManager):
'a mailhost...?' 'a mailhost...?'
meta_type='Mail Host' meta_type='Mail Host'
manage=manage_main=DTMLFile('dtml/manageMailHost', globals()) manage=manage_main=DTMLFile('dtml/manageMailHost', globals())
manage_main._setName('manage_main')
index_html=None index_html=None
icon='misc_/MailHost/MHIcon' icon='misc_/MailHost/MHIcon'
......
...@@ -89,7 +89,7 @@ This product provides support for Script objects containing restricted ...@@ -89,7 +89,7 @@ This product provides support for Script objects containing restricted
Python code. Python code.
""" """
__version__='$Revision: 1.28 $'[11:-2] __version__='$Revision: 1.29 $'[11:-2]
import sys, os, traceback, re, marshal import sys, os, traceback, re, marshal
from Globals import DTMLFile, MessageDialog, package_home from Globals import DTMLFile, MessageDialog, package_home
...@@ -183,6 +183,7 @@ class PythonScript(Script, Historical, Cacheable): ...@@ -183,6 +183,7 @@ class PythonScript(Script, Historical, Cacheable):
ZPythonScriptHTML_editForm = DTMLFile('www/pyScriptEdit', globals()) ZPythonScriptHTML_editForm = DTMLFile('www/pyScriptEdit', globals())
manage = manage_main = ZPythonScriptHTML_editForm manage = manage_main = ZPythonScriptHTML_editForm
ZPythonScriptHTML_editForm._setName('ZPythonScriptHTML_editForm')
security.declareProtected('Change Python Scripts', security.declareProtected('Change Python Scripts',
'ZPythonScriptHTML_editAction', 'ZPythonScriptHTML_editAction',
......
...@@ -77,6 +77,7 @@ class SiteRoot(Traverser, Implicit): ...@@ -77,6 +77,7 @@ class SiteRoot(Traverser, Implicit):
manage_options=({'label':'Edit', 'action':'manage_main', 'help': ('SiteAccess', 'SiteRoot_Edit.stx')},) manage_options=({'label':'Edit', 'action':'manage_main', 'help': ('SiteAccess', 'SiteRoot_Edit.stx')},)
manage = manage_main = DTMLFile('www/SiteRootEdit', globals()) manage = manage_main = DTMLFile('www/SiteRootEdit', globals())
manage_main._setName('manage_main')
def __init__(self, title, base, path): def __init__(self, title, base, path):
'''Title''' '''Title'''
......
...@@ -203,6 +203,7 @@ class OldCatalogWrapperObject(SimpleItem, Implicit): ...@@ -203,6 +203,7 @@ class OldCatalogWrapperObject(SimpleItem, Implicit):
) )
manage_main = DTMLFile('dtml/manageOldindex',globals()) manage_main = DTMLFile('dtml/manageOldindex',globals())
manage_main._setName('manage_main')
manage_workspace = manage_main manage_workspace = manage_main
def __init__(self, o): def __init__(self, o):
......
...@@ -85,8 +85,8 @@ ...@@ -85,8 +85,8 @@
__doc__='''SQL Methods __doc__='''SQL Methods
$Id: SQL.py,v 1.18 2001/03/07 15:13:57 brian Exp $''' $Id: SQL.py,v 1.19 2001/06/07 22:18:45 shane Exp $'''
__version__='$Revision: 1.18 $'[11:-2] __version__='$Revision: 1.19 $'[11:-2]
import Shared.DC.ZRDB.DA import Shared.DC.ZRDB.DA
from Globals import DTMLFile from Globals import DTMLFile
...@@ -193,6 +193,7 @@ class SQL(Shared.DC.ZRDB.DA.DA): ...@@ -193,6 +193,7 @@ class SQL(Shared.DC.ZRDB.DA.DA):
meta_type='Z SQL Method' meta_type='Z SQL Method'
manage=manage_main=DTMLFile('dtml/edit', globals()) manage=manage_main=DTMLFile('dtml/edit', globals())
manage_main._setName('manage_main')
__ac_permissions__=( __ac_permissions__=(
('Change Database Methods', ('manage', 'manage_main')), ('Change Database Methods', ('manage', 'manage_main')),
......
...@@ -388,6 +388,7 @@ class ZInstanceSheetsSheet(OFS.Traversable.Traversable, ...@@ -388,6 +388,7 @@ class ZInstanceSheetsSheet(OFS.Traversable.Traversable,
manage=Globals.DTMLFile('OFS/dtml/main', manage=Globals.DTMLFile('OFS/dtml/main',
management_view='Property Sheets') management_view='Property Sheets')
manage_main = manage manage_main = manage
manage_main._setName('manage_main')
manage_addCommonSheetForm=Globals.DTMLFile('dtml/addCommonSheet', manage_addCommonSheetForm=Globals.DTMLFile('dtml/addCommonSheet',
globals()) globals())
......
...@@ -85,7 +85,7 @@ ...@@ -85,7 +85,7 @@
"""WebDAV support - null resource objects.""" """WebDAV support - null resource objects."""
__version__='$Revision: 1.28 $'[11:-2] __version__='$Revision: 1.29 $'[11:-2]
import sys, os, string, mimetypes, Globals, davcmds import sys, os, string, mimetypes, Globals, davcmds
import Acquisition, OFS.content_types import Acquisition, OFS.content_types
...@@ -299,6 +299,7 @@ class LockNullResource(NullResource, OFS.SimpleItem.Item_w__name__): ...@@ -299,6 +299,7 @@ class LockNullResource(NullResource, OFS.SimpleItem.Item_w__name__):
manage = manage_main = DTMLFile('dtml/locknullmain', globals()) manage = manage_main = DTMLFile('dtml/locknullmain', globals())
manage_workspace = manage manage_workspace = manage
manage_main._setName('manage_main') # explicit
def __no_valid_write_locks__(self): def __no_valid_write_locks__(self):
# A special hook (for better or worse) called when there are no # A special hook (for better or worse) called when there are no
......
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