subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdo...@apache.org
Subject svn commit: r1392038 - in /subversion/trunk/subversion/bindings/swig: core.i python/libsvn_swig_py/swigutil_py.c python/libsvn_swig_py/swigutil_py.h python/tests/core.py
Date Sun, 30 Sep 2012 15:36:22 GMT
Author: rdonch
Date: Sun Sep 30 15:36:22 2012
New Revision: 1392038

URL: http://svn.apache.org/viewvc?rev=1392038&view=rev
Log:
Implemented svn_config_enumerate2 in the SWIG Python bindings.

[in subversion/bindings/swig]

* python/libsvn_swig_py/swigutil_py.c,
  python/libsvn_swig_py/swigutil_py.h:
  (svn_swig_py_config_enumerator2): New function.

* core.i:
  Use svn_swig_py_config_enumerator2 in the corresponding typemap.

* python/tests/core.py:
  (SubversionCoreTestCase.test_config_enumerate2),
  (SubversionCoreTestCase.test_config_enumerate2_exception): New tests.


Modified:
    subversion/trunk/subversion/bindings/swig/core.i
    subversion/trunk/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
    subversion/trunk/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.h
    subversion/trunk/subversion/bindings/swig/python/tests/core.py

Modified: subversion/trunk/subversion/bindings/swig/core.i
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/core.i?rev=1392038&r1=1392037&r2=1392038&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/core.i (original)
+++ subversion/trunk/subversion/bindings/swig/core.i Sun Sep 30 15:36:22 2012
@@ -658,12 +658,14 @@ svn_swig_pl_set_current_pool (apr_pool_t
                   )
 #endif
 
-#ifdef SWIGRUBY
+#ifndef SWIGPERL
 %callback_typemap(svn_config_enumerator2_t callback, void *baton,
-                  ,
+                  svn_swig_py_config_enumerator2,
                   ,
                   svn_swig_rb_config_enumerator)
+#endif
 
+#ifdef SWIGRUBY
 %callback_typemap(svn_config_section_enumerator2_t callback, void *baton,
                   ,
                   ,

Modified: subversion/trunk/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c?rev=1392038&r1=1392037&r2=1392038&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c (original)
+++ subversion/trunk/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c Sun Sep
30 15:36:22 2012
@@ -4191,3 +4191,47 @@ svn_swig_py_setup_wc_diff_callbacks2(voi
   callbacks->dir_props_changed  = wc_diff_callbacks2_dir_props_changed;
   return callbacks;
 }
+
+svn_boolean_t
+svn_swig_py_config_enumerator2(const char *name,
+                               const char *value,
+                               void *baton,
+                               apr_pool_t *pool)
+{
+  PyObject *function = baton;
+  PyObject *result;
+  svn_error_t *err = SVN_NO_ERROR;
+  svn_boolean_t c_result;
+
+  svn_swig_py_acquire_py_lock();
+
+  if ((result = PyObject_CallFunction(function,
+                                      (char *)"ssO&",
+                                      name,
+                                      value,
+                                      make_ob_pool, pool)) == NULL)
+    {
+      err = callback_exception_error();
+    }
+  else if (!PyBool_Check(result))
+    {
+      err = callback_bad_return_error("Not bool");
+      Py_DECREF(result);
+    }
+
+  if (err)
+    {
+      /* We can't return the error, but let's at least stop enumeration. */
+      svn_error_clear(err);
+      c_result = FALSE;
+    }
+  else
+    {
+      c_result = result == Py_True;
+      Py_DECREF(result);
+    }
+
+  svn_swig_py_release_py_lock();
+
+  return c_result;
+}

Modified: subversion/trunk/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.h
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.h?rev=1392038&r1=1392037&r2=1392038&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.h (original)
+++ subversion/trunk/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.h Sun Sep
30 15:36:22 2012
@@ -529,6 +529,13 @@ svn_error_t *svn_swig_py_ra_lock_callbac
 SVN_SWIG_SWIGUTIL_EXPORT
 extern const svn_ra_reporter2_t swig_py_ra_reporter2;
 
+SVN_SWIG_SWIGUTIL_EXPORT
+svn_boolean_t
+svn_swig_py_config_enumerator2(const char *name,
+                               const char *value,
+                               void *baton,
+                               apr_pool_t *pool);
+
 #ifdef __cplusplus
 }
 #endif /* __cplusplus */

Modified: subversion/trunk/subversion/bindings/swig/python/tests/core.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/python/tests/core.py?rev=1392038&r1=1392037&r2=1392038&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/python/tests/core.py (original)
+++ subversion/trunk/subversion/bindings/swig/python/tests/core.py Sun Sep 30 15:36:22 2012
@@ -105,6 +105,44 @@ class SubversionCoreTestCase(unittest.Te
       del ctx
       t.cleanup()
 
+  def test_config_enumerate2(self):
+    cfg = svn.core.svn_config_create(False)
+    entries = {
+      'one': 'one-value',
+      'two': 'two-value',
+      'three': 'three-value'
+    }
+
+    for (name, value) in entries.iteritems():
+      svn.core.svn_config_set(cfg, "section", name, value)
+
+    received_entries = {}
+    def enumerator(name, value, pool):
+      received_entries[name] = value
+      return len(received_entries) < 2
+
+    svn.core.svn_config_enumerate2(cfg, "section", enumerator)
+
+    self.assertEqual(len(received_entries), 2)
+    for (name, value) in received_entries.iteritems():
+      self.assertTrue(name in entries)
+      self.assertEqual(value, entries[name])
+
+  def test_config_enumerate2_exception(self):
+    cfg = svn.core.svn_config_create(False)
+    svn.core.svn_config_set(cfg, "section", "one", "one-value")
+    svn.core.svn_config_set(cfg, "section", "two", "two-value")
+
+    received_entries = {}
+
+    def enumerator(name, value, pool):
+      received_entries[name] = value
+      raise Exception
+
+    svn.core.svn_config_enumerate2(cfg, "section", enumerator)
+    # the exception is swallowed, but enumeration must be stopped
+    self.assertEqual(len(received_entries), 1)
+
 def suite():
     return unittest.defaultTestLoader.loadTestsFromTestCase(
       SubversionCoreTestCase)



Mime
View raw message