[Checkins] SVN: zope.generic/trunk/src/zope/generic/configuration/
add none-persistent error handling
Dominik Huber
dominik.huber at perse.ch
Fri Jul 28 05:57:52 EDT 2006
Log message for revision 69283:
add none-persistent error handling
Changed:
U zope.generic/trunk/src/zope/generic/configuration/README.txt
U zope.generic/trunk/src/zope/generic/configuration/adapter.py
-=-
Modified: zope.generic/trunk/src/zope/generic/configuration/README.txt
===================================================================
--- zope.generic/trunk/src/zope/generic/configuration/README.txt 2006-07-28 09:42:42 UTC (rev 69282)
+++ zope.generic/trunk/src/zope/generic/configuration/README.txt 2006-07-28 09:57:51 UTC (rev 69283)
@@ -419,3 +419,13 @@
>>> config.bar['d'].foo
u'bla D'
+
+Exception handling during the update
+------------------------------------
+
+If an error occurs during the update the last state of the configuration is
+rolled back:
+
+ TODO
+
+
Modified: zope.generic/trunk/src/zope/generic/configuration/adapter.py
===================================================================
--- zope.generic/trunk/src/zope/generic/configuration/adapter.py 2006-07-28 09:42:42 UTC (rev 69282)
+++ zope.generic/trunk/src/zope/generic/configuration/adapter.py 2006-07-28 09:57:51 UTC (rev 69283)
@@ -100,35 +100,43 @@
return
updated_data = {}
+ existing_data = {}
errors = []
-
- for name in keyface:
- field = keyface[name]
+ try:
+ for name in keyface:
+ field = keyface[name]
+
+ # readonly attribute cannot be updated
+ if field.readonly:
+ raise ValueError(name, 'Data is readonly.')
+
+ if isconfig:
+ value = getattr(data, name, field.missing_value)
+ # assume dict
+ else:
+ try:
+ value = data[name]
+ except KeyError:
+ continue
+ existing_value = getattr(current_config, name, field.missing_value)
+ if value != existing_value:
+ existing_data[name] = existing_value
+ setattr(current_config, name, value)
+ updated_data[name] = value
+
+ # notify update
+ parent = self.__parent__
+ if updated_data and ILocation.providedBy(parent) and parent.__parent__ is not None:
+ notify(ObjectConfiguredEvent(parent,
+ Configuration(keyface, updated_data)))
- # readonly attribute cannot be updated
- if field.readonly:
- raise ValueError(name, 'Data is readonly.')
-
- if isconfig:
- value = getattr(data, name, field.missing_value)
- # assume dict
- else:
- try:
- value = data[name]
- except KeyError:
- continue
-
- if value != getattr(current_config, name, field.missing_value):
+ except:
+ # set the values back to the last valid configuration
+ for name, value in existing_data.items():
setattr(current_config, name, value)
- updated_data[name] = value
+ raise
- # notify update
- parent = self.__parent__
- if updated_data and ILocation.providedBy(parent) and parent.__parent__ is not None:
- notify(ObjectConfiguredEvent(parent,
- Configuration(keyface, updated_data)))
-
def __setitem__(self, keyface, value):
# preconditions
if not IConfigurationType.providedBy(keyface):
More information about the Checkins
mailing list