Author: troycurtisjr
Date: Fri Dec 22 03:52:59 2017
New Revision: 1818995
URL: http://svn.apache.org/viewvc?rev=1818995&view=rev
Log:
On branch swig-py3: Correctly manage swig objects with Python new style classes.
* subversion/bindings/swig/include/proxy.py
(__getattr__): Replace __getattr__ with __getattribute__ to correctly
intercept attribute access, even when swig uses descriptors for new style
classes (which are the only type available in Python 3).
* build/ac-macros/swig.m4
(SVN_FIND_SWIG):
Request that swig generate new style classes, even for Python 2, to reduce
differences with Python 3.
* subversion/bindings/swig/include/proxy.swg
(_copy_metadata_deep): Remove iteritems() use to make compatible with both
Python 2 and 3.
(_assert_valid_deep): Remove itervalues() use and add type check to be
compatible with both Python 2 and 3.
Modified:
subversion/branches/swig-py3/build/ac-macros/swig.m4
subversion/branches/swig-py3/subversion/bindings/swig/include/proxy.py
subversion/branches/swig-py3/subversion/bindings/swig/include/proxy.swg
Modified: subversion/branches/swig-py3/build/ac-macros/swig.m4
URL:
http://svn.apache.org/viewvc/subversion/branches/swig-py3/build/ac-macros/swig.m4?rev=1818995&r1=1818994&r2=1818995&view=diff
==============================================================================
--- subversion/branches/swig-py3/build/ac-macros/swig.m4 (original)
+++ subversion/branches/swig-py3/build/ac-macros/swig.m4 Fri Dec 22 03:52:59
2017
@@ -143,7 +143,7 @@ AC_DEFUN(SVN_FIND_SWIG,
if test "$ac_cv_python_is_py3" = "yes"; then
SWIG_PY_OPTS="-python -py3"
else
- SWIG_PY_OPTS="-python -classic"
+ SWIG_PY_OPTS="-python"
fi
dnl Sun Forte adds an extra space before substituting APR_INT64_T_FMT
Modified: subversion/branches/swig-py3/subversion/bindings/swig/include/proxy.py
URL:
http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/include/proxy.py?rev=1818995&r1=1818994&r2=1818995&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/include/proxy.py
(original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/include/proxy.py Fri
Dec 22 03:52:59 2017
@@ -12,17 +12,36 @@
if "_is_valid" in self.__dict__:
assert self.__dict__["_is_valid"](), "Variable has already been deleted"
- def __getattr__(self, name):
- """Get an attribute from this object"""
- self.assert_valid()
+ def __getattribute__(self, name):
+ """Manage access to all attributes of this object."""
- value = _swig_getattr(self, self.__class__, name)
+ # Start by mimicing __getattr__ behavior: immediately return __dict__ or
+ # items directly present in __dict__
+ mydict = object.__getattribute__(self, '__dict__')
+ if name == "__dict__":
+ return mydict
+
+ if name in mydict:
+ return mydict[name]
+
+ object.__getattribute__(self, 'assert_valid')()
+
+ try:
+ value = object.__getattribute__(self, name)
+ except AttributeError:
+ value = _swig_getattr(self,
+ object.__getattribute__(self, '__class__'),
+ name)
# If we got back a different object than we have, we need to copy all our
# metadata into it, so that it looks identical
- members = self.__dict__.get("_members")
- if members is not None:
- _copy_metadata_deep(value, members.get(name))
+ try:
+ members = object.__getattribute__(self, '_members')
+ if name in members:
+ _copy_metadata_deep(value, members[name])
+ # Verify that the new object is good
+ except AttributeError:
+ pass
# Verify that the new object is good
_assert_valid_deep(value)
Modified:
subversion/branches/swig-py3/subversion/bindings/swig/include/proxy.swg
URL:
http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/include/proxy.swg?rev=1818995&r1=1818994&r2=1818995&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/include/proxy.swg
(original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/include/proxy.swg Fri
Dec 22 03:52:59 2017
@@ -36,8 +36,8 @@
if value is None or old_value is None or value is old_value: return
if isinstance(value, dict):
- for k, v in value.iteritems():
- _copy_metadata_deep(v, old_value[k])
+ for k in value:
+ _copy_metadata_deep(value[k], old_value[k])
elif isinstance(value, list):
for v, old_v in zip(value, old_value):
_copy_metadata_deep(v, old_v)
@@ -50,13 +50,14 @@
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)
+ for k in value:
+ _assert_valid_deep(value[k])
elif isinstance(value, list):
for v in value:
_assert_valid_deep(v)
- else:
- if hasattr(value, "assert_valid"):
+ # Ensure that the passed in value isn't a type, which could have an
+ # assert_valid attribute, but it can not be called without an instance.
+ elif type(value) != type and hasattr(value, "assert_valid"):
value.assert_valid()
%}