You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by rd...@apache.org on 2010/02/10 00:12:54 UTC
svn commit: r908275 -
/subversion/trunk/subversion/bindings/swig/include/proxy.swg
Author: rdonch
Date: Tue Feb 9 23:12:51 2010
New Revision: 908275
URL: http://svn.apache.org/viewvc?rev=908275&view=rev
Log:
Expand/fix r907788, so that the even Righter Thing is done.
* subversion/bindings/swig/include/proxy.swg:
(_copy_metadata): Rename to _copy_metadata_deep, add a docstring and fix
a silly bug in the dict branch.
(_assert_valid_deep): New function.
(<proxy>.__getattr__): Use the new names/functions.
Modified:
subversion/trunk/subversion/bindings/swig/include/proxy.swg
Modified: subversion/trunk/subversion/bindings/swig/include/proxy.swg
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/include/proxy.swg?rev=908275&r1=908274&r2=908275&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/include/proxy.swg (original)
+++ subversion/trunk/subversion/bindings/swig/include/proxy.swg Tue Feb 9 23:12:51 2010
@@ -30,20 +30,34 @@
*/
%pythoncode %{
- def _copy_metadata(value, old_value):
+ def _copy_metadata_deep(value, old_value):
+ """Copy all attributes of old_value into value, recursively traversing
+ lists and dicts if needed."""
if value is None or old_value is None or value is old_value: return
if isinstance(value, dict):
- for (k, v) in value:
- _copy_metadata(v, old_value[k])
+ for k, v in value.iteritems():
+ _copy_metadata_deep(v, old_value[k])
elif isinstance(value, list):
for v, old_v in zip(value, old_value):
- _copy_metadata(v, old_v)
+ _copy_metadata_deep(v, old_v)
else:
try:
value.__dict__.update(old_value.__dict__)
except AttributeError:
pass
+
+ def _assert_valid_deep(value):
+ """Assert value's validity, recursively traversing lists and dicts."""
+ if isinstance(value, dict):
+ for v in value.itervalues():
+ _assert_valid_deep(v)
+ elif isinstance(value, list):
+ for v in value:
+ _assert_valid_deep(v)
+ else:
+ if hasattr(value, "assert_valid"):
+ value.assert_valid()
%}
/* Default code for all wrapped proxy classes in Python */
@@ -73,11 +87,10 @@
# metadata into it, so that it looks identical
members = self.__dict__.get("_members")
if members is not None:
- _copy_metadata(value, members.get(name))
+ _copy_metadata_deep(value, members.get(name))
# Verify that the new object is good
- if hasattr(value, "assert_valid"):
- value.assert_valid()
+ _assert_valid_deep(value)
return value