You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by cm...@apache.org on 2018/12/07 23:30:19 UTC
svn commit: r1848425 - in /subversion/trunk/subversion/bindings/swig:
include/svn_types.swg python/tests/delta.py
Author: cmpilato
Date: Fri Dec 7 23:30:19 2018
New Revision: 1848425
URL: http://svn.apache.org/viewvc?rev=1848425&view=rev
Log:
swig-py: allow svn.core.svn_stream_t proxy objects and svn.core.Stream
wrapper objects as input to APIs which consume svn_stream_t *.
* subversion/bindings/swig/include/svn_types.swg
(%typemap(in) svn_stream_t *WRAPPED_STREAM): Allow
svn.core.svn_stream_t proxy object for svn_stream_t * in args.
this typemap is used by _client, _delta, _diff, _fs, _ra, and
_repos modules.
* subversion/bindings/swig/python/tests/delta.py
(DeltaTestCase.testTxWindowHandler_stream_IF): New test for
svn_stream_t * interface wrapper accept svn.core.svn_stream_t
proxy object.
(DeltaTestCase.testTxWindowHandler_Stream_IF): New test for
svn_stream_t * interface wrapper accept svn.core.Stream wrapper
object.
Patch by: Yasuhito FUTATSUKI <futatuki at yf.bsdclub.org>
Modified:
subversion/trunk/subversion/bindings/swig/include/svn_types.swg
subversion/trunk/subversion/bindings/swig/python/tests/delta.py
Modified: subversion/trunk/subversion/bindings/swig/include/svn_types.swg
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/include/svn_types.swg?rev=1848425&r1=1848424&r2=1848425&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/include/svn_types.swg (original)
+++ subversion/trunk/subversion/bindings/swig/include/svn_types.swg Fri Dec 7 23:30:19 2018
@@ -941,7 +941,62 @@ svn_ ## TYPE ## _swig_rb_closed(VALUE se
#ifdef SWIGPYTHON
%typemap(in) svn_stream_t *WRAPPED_STREAM {
- $1 = svn_swig_py_make_stream ($input, _global_pool);
+ if ($input == Py_None) {
+ $1 = NULL;
+ }
+ else {
+ PyObject *libsvn_core;
+ PyObject *py_stream_t;
+ libsvn_core = PyImport_ImportModule("libsvn.core");
+ if (PyErr_Occurred()) {
+ Py_XDECREF(libsvn_core);
+ SWIG_fail;
+ }
+ py_stream_t = PyObject_GetAttrString(libsvn_core, "svn_stream_t");
+ if (PyErr_Occurred()) {
+ Py_XDECREF(py_stream_t);
+ Py_DECREF(libsvn_core);
+ SWIG_fail;
+ }
+ if (PyObject_IsInstance($input, py_stream_t)) {
+ $1 = (svn_stream_t *)svn_swig_py_must_get_ptr(
+ $input, $1_descriptor, $argnum);
+ if (PyErr_Occurred()) {
+ Py_DECREF(py_stream_t);
+ Py_DECREF(libsvn_core);
+ SWIG_fail;
+ }
+ Py_DECREF(py_stream_t);
+ Py_DECREF(libsvn_core);
+ }
+ else if (PyObject_HasAttrString($input, "_stream")){
+ PyObject *_stream = PyObject_GetAttrString($input, "_stream");
+ if (PyObject_IsInstance(_stream, py_stream_t)) {
+ $1 = (svn_stream_t *)svn_swig_py_must_get_ptr(
+ _stream, $1_descriptor,
+ $argnum);
+ if (PyErr_Occurred()) {
+ PyErr_Clear();
+ $1 = NULL;
+ }
+ Py_DECREF(_stream);
+ Py_DECREF(py_stream_t);
+ Py_DECREF(libsvn_core);
+ }
+ }
+ if ($1 == NULL) {
+ if ( PyObject_HasAttrString($input, "read")
+ || PyObject_HasAttrString($input, "write")) {
+ $1 = svn_swig_py_make_stream ($input, _global_pool);
+ }
+ else {
+ PyErr_SetString(PyExc_TypeError,
+ "expecting a svn_stream_t"
+ " or file like object");
+ SWIG_fail;
+ }
+ }
+ }
}
#endif
Modified: subversion/trunk/subversion/bindings/swig/python/tests/delta.py
URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/bindings/swig/python/tests/delta.py?rev=1848425&r1=1848424&r2=1848425&view=diff
==============================================================================
--- subversion/trunk/subversion/bindings/swig/python/tests/delta.py (original)
+++ subversion/trunk/subversion/bindings/swig/python/tests/delta.py Fri Dec 7 23:30:19 2018
@@ -19,6 +19,8 @@
#
#
import unittest, setup_path
+import os
+import tempfile
import svn.delta
import svn.core
from sys import version_info # For Python version check
@@ -47,6 +49,59 @@ class DeltaTestCase(unittest.TestCase):
svn.delta.tx_apply(src_stream, target_stream, None)
window_handler(None, baton)
+ def testTxWindowHandler_stream_IF(self):
+ """Test tx_invoke_window_handler, with svn.core.svn_stream_t object"""
+ pool = svn.core.Pool()
+ in_str = "hello world"
+ src_stream = svn.core.svn_stream_from_stringbuf(in_str)
+ content_str = "bye world"
+ content_stream = svn.core.svn_stream_from_stringbuf(content_str)
+ fd, fname = tempfile.mkstemp()
+ os.close(fd)
+ try:
+ target_stream = svn.core.svn_stream_from_aprfile2(fname, False)
+ window_handler, baton = \
+ svn.delta.tx_apply(src_stream, target_stream, None)
+ svn.delta.tx_send_stream(content_stream, window_handler, baton, pool)
+ fp = open(fname, 'rb')
+ out_str = fp.read()
+ fp.close()
+ self.assertEqual(content_str, out_str)
+ finally:
+ del pool
+ try:
+ os.remove(fname)
+ except OSError:
+ pass
+
+ def testTxWindowHandler_Stream_IF(self):
+ """Test tx_invoke_window_handler, with svn.core.Stream object"""
+ pool = svn.core.Pool()
+ in_str = "hello world"
+ src_stream = svn.core.Stream(
+ svn.core.svn_stream_from_stringbuf(in_str))
+ content_str = "bye world"
+ content_stream = svn.core.Stream(
+ svn.core.svn_stream_from_stringbuf(content_str))
+ fd, fname = tempfile.mkstemp()
+ os.close(fd)
+ try:
+ target_stream = svn.core.Stream(
+ svn.core.svn_stream_from_aprfile2(fname, False))
+ window_handler, baton = \
+ svn.delta.tx_apply(src_stream, target_stream, None)
+ svn.delta.tx_send_stream(content_stream, window_handler, baton, None)
+ fp = open(fname, 'rb')
+ out_str = fp.read()
+ fp.close()
+ self.assertEqual(content_str, out_str)
+ finally:
+ del pool
+ try:
+ os.remove(fname)
+ except OSError:
+ pass
+
def testTxdeltaWindowT(self):
"""Test the svn_txdelta_window_t wrapper."""
a = StringIO("abc\ndef\n")