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