subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rdo...@apache.org
Subject svn commit: r1392073 - 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 16:45:13 GMT
Author: rdonch
Date: Sun Sep 30 16:45:12 2012
New Revision: 1392073

URL: http://svn.apache.org/viewvc?rev=1392073&view=rev
Log:
Implemented svn_config_enumerate_sections2 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_section_enumerator2): New function.

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

* python/tests/core.py:
  (SubversionCoreTestCase.test_config_enumerate_sections2),
  (SubversionCoreTestCase.test_config_enumerate_sections2_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=1392073&r1=1392072&r2=1392073&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/core.i (original)
+++ subversion/trunk/subversion/bindings/swig/core.i Sun Sep 30 16:45:12 2012
@@ -663,11 +663,9 @@ svn_swig_pl_set_current_pool (apr_pool_t
                   svn_swig_py_config_enumerator2,
                   ,
                   svn_swig_rb_config_enumerator)
-#endif
 
-#ifdef SWIGRUBY
 %callback_typemap(svn_config_section_enumerator2_t callback, void *baton,
-                  ,
+                  svn_swig_py_config_section_enumerator2,
                   ,
                   svn_swig_rb_config_section_enumerator)
 #endif

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=1392073&r1=1392072&r2=1392073&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 16:45:12 2012
@@ -4239,3 +4239,49 @@ svn_swig_py_config_enumerator2(const cha
 
   return c_result;
 }
+
+svn_boolean_t
+svn_swig_py_config_section_enumerator2(const char *name,
+                                       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 *)"sO&",
+                                      name,
+                                      make_ob_pool, pool)) == NULL)
+    {
+      err = callback_exception_error();
+      /* If it's not a SubversionException, we still have to clear it, because
+         otherwise the SWIG wrapper will not check for it, and return a value with an
+         exception pending. */
+      PyErr_Clear();
+    }
+  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=1392073&r1=1392072&r2=1392073&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 16:45:12 2012
@@ -536,6 +536,12 @@ svn_swig_py_config_enumerator2(const cha
                                void *baton,
                                apr_pool_t *pool);
 
+SVN_SWIG_SWIGUTIL_EXPORT
+svn_boolean_t
+svn_swig_py_config_section_enumerator2(const char *name,
+                                       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=1392073&r1=1392072&r2=1392073&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/python/tests/core.py (original)
+++ subversion/trunk/subversion/bindings/swig/python/tests/core.py Sun Sep 30 16:45:12 2012
@@ -140,6 +140,36 @@ class SubversionCoreTestCase(unittest.Te
     self.assertEqual(
       svn.core.svn_config_enumerate2(cfg, "section", enumerator), 1)
 
+  def test_config_enumerate_sections2(self):
+    cfg = svn.core.svn_config_create(False)
+    sections = ['section-one', 'section-two', 'section-three']
+
+    for section in sections:
+      svn.core.svn_config_set(cfg, section, "name", "value")
+
+    received_sections = []
+    def enumerator(section, pool):
+      received_sections.append(section)
+      return len(received_sections) < 2
+
+    svn.core.svn_config_enumerate_sections2(cfg, enumerator)
+
+    self.assertEqual(len(received_sections), 2)
+    for section in received_sections:
+      self.assertIn(section, sections)
+
+  def test_config_enumerate_sections2_exception(self):
+    cfg = svn.core.svn_config_create(False)
+    svn.core.svn_config_set(cfg, "section-one", "name", "value")
+    svn.core.svn_config_set(cfg, "section-two", "name", "value")
+
+    def enumerator(section, pool):
+      raise Exception
+
+    # the exception will be swallowed, but enumeration must be stopped
+    self.assertEqual(
+      svn.core.svn_config_enumerate_sections2(cfg, enumerator), 1)
+
 def suite():
     return unittest.defaultTestLoader.loadTestsFromTestCase(
       SubversionCoreTestCase)



Mime
View raw message