From commits-return-50033-archive-asf-public=cust-asf.ponee.io@subversion.apache.org Sat Dec 8 00:30:22 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 2EE12180647 for ; Sat, 8 Dec 2018 00:30:22 +0100 (CET) Received: (qmail 87230 invoked by uid 500); 7 Dec 2018 23:30:21 -0000 Mailing-List: contact commits-help@subversion.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@subversion.apache.org Delivered-To: mailing list commits@subversion.apache.org Received: (qmail 87218 invoked by uid 99); 7 Dec 2018 23:30:21 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 07 Dec 2018 23:30:21 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 868D33A006D for ; Fri, 7 Dec 2018 23:30:20 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1848425 - in /subversion/trunk/subversion/bindings/swig: include/svn_types.swg python/tests/delta.py Date: Fri, 07 Dec 2018 23:30:19 -0000 To: commits@subversion.apache.org From: cmpilato@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20181207233020.868D33A006D@svn01-us-west.apache.org> 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 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")