Commit 703ff9f1 authored by Jim Fulton's avatar Jim Fulton

New-style class dictionaries are immutable. Changed some class-update

code to use setattr rather thah class-dictionary modifications.
parent 29f85016
...@@ -16,7 +16,7 @@ from Persistence import Persistent ...@@ -16,7 +16,7 @@ from Persistence import Persistent
import Globals import Globals
from DateTime import DateTime from DateTime import DateTime
Persistent.__dict__['__class_init__']=default__class_init__ Persistent.__class_init__ = default__class_init__
class PersistentUtil: class PersistentUtil:
...@@ -69,4 +69,7 @@ class PersistentUtil: ...@@ -69,4 +69,7 @@ class PersistentUtil:
except: return 0 except: return 0
return 1 return 1
for k, v in PersistentUtil.__dict__.items(): Persistent.__dict__[k]=v for k, v in PersistentUtil.__dict__.items():
if k[0] != '_':
setattr(Persistent, k, v)
...@@ -166,8 +166,10 @@ class ProductContext: ...@@ -166,8 +166,10 @@ class ProductContext:
fd = pack.__FactoryDispatcher__ = __FactoryDispatcher__ fd = pack.__FactoryDispatcher__ = __FactoryDispatcher__
if not hasattr(pack, '_m'): pack._m=fd.__dict__ if not hasattr(pack, '_m'):
m=pack._m pack._m = AttrDict(fd)
m = pack._m
if interfaces is _marker: if interfaces is _marker:
if instance_class is None: if instance_class is None:
...@@ -341,3 +343,11 @@ class ProductContext: ...@@ -341,3 +343,11 @@ class ProductContext:
continue continue
ht=APIHelpTopic.APIHelpTopic(file, '', os.path.join(path, file)) ht=APIHelpTopic.APIHelpTopic(file, '', os.path.join(path, file))
self.registerHelpTopic(file, ht) self.registerHelpTopic(file, ht)
class AttrDict:
def __init__(self, ob):
self.ob = ob
def __setitem__(self, name, v):
setattr(self.ob, name, v)
...@@ -46,10 +46,12 @@ def default__class_init__(self): ...@@ -46,10 +46,12 @@ def default__class_init__(self):
d['__name__']=name 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):
setattr(self, name, ('Manager',))
elif name=='manage' or name[:7]=='manage_' and type(v) is ft: elif name=='manage' or name[:7]=='manage_' and type(v) is ft:
name=name+'__roles__' name=name+'__roles__'
if not have(name): dict[name]='Manager', if not have(name):
setattr(self, name, ('Manager',))
# Look for a SecurityInfo object on the class. If found, call its # Look for a SecurityInfo object on the class. If found, call its
# apply() method to generate __ac_permissions__ for the class. We # apply() method to generate __ac_permissions__ for the class. We
...@@ -59,7 +61,7 @@ def default__class_init__(self): ...@@ -59,7 +61,7 @@ def default__class_init__(self):
if hasattr(value, '__security_info__'): if hasattr(value, '__security_info__'):
security_info=value security_info=value
security_info.apply(self) security_info.apply(self)
del dict[key] delattr(self, key)
break break
if self.__dict__.has_key('__ac_permissions__'): if self.__dict__.has_key('__ac_permissions__'):
...@@ -72,4 +74,4 @@ def default__class_init__(self): ...@@ -72,4 +74,4 @@ def default__class_init__(self):
else: else:
pr=PermissionRole(pname) pr=PermissionRole(pname)
for mname in mnames: for mname in mnames:
dict[mname+'__roles__']=pr setattr(self, mname+'__roles__', pr)
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
# FOR A PARTICULAR PURPOSE # FOR A PARTICULAR PURPOSE
# #
############################################################################## ##############################################################################
'''$Id: DT_Util.py,v 1.89 2003/02/27 17:31:27 fdrake Exp $''' '''$Id: DT_Util.py,v 1.90 2003/11/28 16:45:22 jim Exp $'''
__version__='$Revision: 1.89 $'[11:-2] __version__='$Revision: 1.90 $'[11:-2]
import re, os import re, os
from html_quote import html_quote, ustr # for import by other modules, dont remove! from html_quote import html_quote, ustr # for import by other modules, dont remove!
...@@ -42,7 +42,8 @@ try: ...@@ -42,7 +42,8 @@ try:
import ExtensionClass import ExtensionClass
from cDocumentTemplate import InstanceDict, TemplateDict, \ from cDocumentTemplate import InstanceDict, TemplateDict, \
render_blocks, safe_callable, join_unicode render_blocks, safe_callable, join_unicode
except: from pDocumentTemplate import InstanceDict, TemplateDict, \ except:
from pDocumentTemplate import InstanceDict, TemplateDict, \
render_blocks, safe_callable, join_unicode render_blocks, safe_callable, join_unicode
functype = type(int_param) functype = type(int_param)
...@@ -51,21 +52,18 @@ class NotBindable: ...@@ -51,21 +52,18 @@ class NotBindable:
def __init__(self, f): def __init__(self, f):
self.__call__ = f self.__call__ = f
d = TemplateDict.__dict__
for name, f in safe_builtins.items() + utility_builtins.items(): for name, f in safe_builtins.items() + utility_builtins.items():
if type(f) is functype: if type(f) is functype:
d[name] = NotBindable(f) f = NotBindable(f)
else: setattr(TemplateDict, name, f)
d[name] = f
if LIMITED_BUILTINS: if LIMITED_BUILTINS:
# Replace certain builtins with limited versions. # Replace certain builtins with limited versions.
from RestrictedPython.Limits import limited_builtins from RestrictedPython.Limits import limited_builtins
for name, f in limited_builtins.items(): for name, f in limited_builtins.items():
if type(f) is functype: if type(f) is functype:
d[name] = NotBindable(f) f = NotBindable(f)
else: setattr(TemplateDict, name, f)
d[name] = f
try: try:
# Wrap the string module so it can deal with TaintedString strings. # Wrap the string module so it can deal with TaintedString strings.
...@@ -104,7 +102,7 @@ try: ...@@ -104,7 +102,7 @@ try:
retval = TaintedString(retval) retval = TaintedString(retval)
return retval return retval
d['string'] = StringModuleWrapper() TemplateDict.string = StringModuleWrapper()
except ImportError: except ImportError:
# Use the string module already defined in RestrictedPython.Utilities # Use the string module already defined in RestrictedPython.Utilities
...@@ -138,8 +136,8 @@ def careful_hasattr(md, inst, name): ...@@ -138,8 +136,8 @@ def careful_hasattr(md, inst, name):
else: else:
return 1 return 1
d['getattr']=careful_getattr TemplateDict.getattr = careful_getattr
d['hasattr']=careful_hasattr TemplateDict.hasattr = careful_hasattr
def namespace(self, **kw): def namespace(self, **kw):
"""Create a tuple consisting of a single instance whose attributes are """Create a tuple consisting of a single instance whose attributes are
...@@ -152,7 +150,7 @@ def namespace(self, **kw): ...@@ -152,7 +150,7 @@ def namespace(self, **kw):
information may contain more details.)''' information may contain more details.)'''
return self(**kw) return self(**kw)
d['namespace']=namespace TemplateDict.namespace = namespace
def render(self, v): def render(self, v):
"Render an object in the way done by the 'name' attribute" "Render an object in the way done by the 'name' attribute"
...@@ -167,7 +165,7 @@ def render(self, v): ...@@ -167,7 +165,7 @@ def render(self, v):
v = v() v = v()
return v return v
d['render']=render TemplateDict.render = render
class Eval(RestrictionCapableEval): class Eval(RestrictionCapableEval):
......
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