[Zope-Checkins] CVS: Releases/Zope/lib/python/Products/PythonScripts - standard.py:1.12
Evan Simpson
evan@zope.com
Wed, 4 Dec 2002 13:55:16 -0500
Update of /cvs-repository/Releases/Zope/lib/python/Products/PythonScripts
In directory cvs.zope.org:/tmp/cvs-serv5016/lib/python/Products/PythonScripts
Modified Files:
standard.py
Log Message:
Merge Object changes from 2.6 branch
=== Releases/Zope/lib/python/Products/PythonScripts/standard.py 1.11 => 1.12 ===
--- Releases/Zope/lib/python/Products/PythonScripts/standard.py:1.11 Wed Sep 4 18:19:09 2002
+++ Releases/Zope/lib/python/Products/PythonScripts/standard.py Wed Dec 4 13:55:16 2002
@@ -61,10 +61,30 @@
class _Object(record):
_guarded_writes = 1
+ def __init__(self, **kw):
+ self.update(kw)
+
def __setitem__(self, key, value):
- self.__dict__[str(key)] = value
+ key = str(key)
+ if key.startswith('_'):
+ raise ValueError, ('Object key %s is invalid. '
+ 'Keys may not begin with an underscore.' % `key`)
+ self.__dict__[key] = value
+
+ def update(self, d):
+ for key in d.keys():
+ # Ignore invalid keys, rather than raising an exception.
+ try:
+ skey = str(key)
+ except:
+ continue
+ if skey==key and not skey.startswith('_'):
+ self.__dict__[skey] = d[key]
+
+ def __hash__(self):
+ return id(self)
-def Object():
- return _Object()
+def Object(**kw):
+ return _Object(**kw)
security.apply(globals())