|
* Add a typemap for svn_client_prompt_t
||* Add a typemap for log_message_receiver_t
* Add a python wrapper ||svn_stream_from_pyio around svn_stream_t for
passing python objects that have read & write methods
||* Supply a return type mapping for type svn_stream_t **
* Fix a comment in svn_client.i
Index: bindings/swig/core.i
===================================================================
--- bindings/swig/core.i (revision 6538)
+++ bindings/swig/core.i (working copy)
@@ -90,6 +90,10 @@
svn_auth_baton_t **
}
+%apply SWIGTYPE **OUTPARAM {
+ svn_stream_t **
+}
+
/* -----------------------------------------------------------------------
apr_size_t * is always an IN/OUT parameter in svn_io.h
*/
@@ -217,6 +221,8 @@
void apr_pool_destroy(apr_pool_t *p);
+svn_stream_t* svn_stream_from_pyio(PyObject *py_io, apr_pool_t *pool);
+
/*
----------------------------------------------------------------------- */
%include svn_types.h
Index: bindings/swig/svn_client.i
===================================================================
--- bindings/swig/svn_client.i (revision 6538)
+++ bindings/swig/svn_client.i (working copy)
@@ -152,6 +152,12 @@
handle svn_client_prompt_t/baton pairs
*/
+%typemap(python,in) (svn_client_prompt_t prompt_func,
+ void *prompt_baton) {
+ $1 = svn_swig_py_client_prompt_func;
+ $2 = $input;
+}
+
%typemap(java,memberin) (svn_client_prompt_t prompt_func,
void *prompt_baton) {
//$1 = svn_swig_java_client_prompt_func;
@@ -170,9 +176,15 @@
%typemap(java, javain) svn_client_prompt_t "$javainput"
/* -----------------------------------------------------------------------
- handle svn_client_get_commit_log_t/baton pairs
+ handle svn_log_message_receiver_t/baton pairs
*/
+%typemap(python,in) (svn_log_message_receiver_t receiver,
+ void *receiver_baton) {
+ $1 = svn_swig_py_log_message_receiver;
+ $2 = $input;
+}
+
%typemap(java,in) (svn_log_message_receiver_t receiver,
void *receiver_baton) {
Index: bindings/swig/swigutil_py.c
===================================================================
--- bindings/swig/swigutil_py.c (revision 6538)
+++ bindings/swig/swigutil_py.c (working copy)
@@ -226,7 +226,16 @@
PyObject *svn_swig_py_prophash_to_dict(apr_hash_t *hash)
{
- return convert_hash(hash, convert_svn_string_t, NULL);
+ PyObject *ret;
+
+ if(!hash)
+ {
+ ret = Py_None;
+ Py_INCREF(ret);
+ } else {
+ ret = convert_hash(hash, convert_svn_string_t, NULL);
+ }
+ return ret;
}
PyObject *svn_swig_py_convert_hash(apr_hash_t *hash, swig_type_info *type)
@@ -904,6 +913,100 @@
return apr_file;
}
+static svn_error_t *
+read_handler_pyio (void *baton, char *buffer, apr_size_t *len)
+{
+ PyObject *result;
+ PyObject *py_io = baton;
+ apr_size_t bytes;
+ svn_error_t *err = SVN_NO_ERROR;
+
+ acquire_py_lock();
+ if ((result = PyObject_CallFunction(py_io, "read", "i", *len)) == NULL)
+ {
+ err = convert_python_error();
+ }
+ else if (PyString_Check(result))
+ {
+ bytes = PyString_GET_SIZE(result);
+ if (bytes>*len)
+ {
+ PyErr_SetString(PyExc_TypeError,
+ "read_handler_pyio returned too many bytes");
+ err = convert_python_error();
+ }
+ else if (bytes<*len)
+ {
+ PyErr_SetString(PyExc_TypeError,
+ "read_handler_pyio returned not enough bytes");
+ err = convert_python_error();
+ *len = bytes;
+ }
+
+ memcpy(buffer, PyString_AS_STRING(result), *len);
+ }
+ else
+ {
+ PyErr_SetString(PyExc_TypeError, "not a string");
+ err = convert_python_error();
+ }
+
+ Py_XDECREF(result);
+ release_py_lock();
+
+ return err;
+}
+
+
+static svn_error_t *
+write_handler_pyio (void *baton, const char *data, apr_size_t *len)
+{
+ PyObject *result;
+ PyObject *py_io = baton;
+ svn_error_t *err = SVN_NO_ERROR;
+
+ acquire_py_lock();
+ if ((result = PyObject_CallMethod(py_io, "write", "s#", data, *len))
== NULL)
+ {
+ err = convert_python_error();
+ }
+
+ Py_XDECREF(result);
+ release_py_lock();
+
+ return err;
+}
+
+static svn_error_t *
+close_handler_pyio (void *baton)
+{
+ PyObject *py_io = baton;
+
+ acquire_py_lock();
+ Py_XDECREF(py_io);
+ release_py_lock();
+
+ return SVN_NO_ERROR;
+}
+
+svn_stream_t *
+svn_stream_from_pyio (PyObject *py_io, apr_pool_t *pool)
+{
+ svn_stream_t *stream;
+
+ acquire_py_lock();
+ Py_INCREF(py_io);
+
+ stream = svn_stream_create (py_io, pool);
+ svn_stream_set_read (stream, read_handler_pyio);
+ svn_stream_set_write (stream, write_handler_pyio);
+ svn_stream_set_close (stream, close_handler_pyio);
+
+ release_py_lock();
+
+ return stream;
+}
+
void svn_swig_py_notify_func(void *baton,
const char *path,
svn_wc_notify_action_t action,
@@ -1026,7 +1129,79 @@
return err;
}
+svn_error_t *
+svn_swig_py_client_prompt_func(const char **info,
+ const char *prompt,
+ svn_boolean_t hide,
+ void *baton,
+ apr_pool_t *pool)
+{
+ PyObject *function = baton;
+ PyObject *result;
+ svn_error_t *err = SVN_NO_ERROR;
+ acquire_py_lock();
+
+ if ((result = PyObject_CallFunction(function, (char *)"UiO&",
+ prompt,
+ hide,
+ make_ob_pool, pool)) == NULL)
+ {
+ err = convert_python_error();
+ }
+ else if (result == Py_None)
+ {
+ *info = NULL;
+ }
+ else if (PyString_Check(result))
+ {
+ *info = apr_pstrdup(pool, PyString_AS_STRING(result));
+ }
+ else
+ {
+ PyErr_SetString(PyExc_TypeError, "not a string");
+ err = convert_python_error();
+ }
+ Py_XDECREF(result);
+
+ release_py_lock();
+
+ return err;
+}
+
+
+svn_error_t *
+svn_swig_py_log_message_receiver (void *baton,
+ apr_hash_t *changed_paths,
+ svn_revnum_t revision,
+ const char *author,
+ const char *date,
+ const char *message,
+ apr_pool_t *pool)
+{
+ PyObject *function = baton;
+ PyObject *result;
+ svn_error_t *err = SVN_NO_ERROR;
+
+ acquire_py_lock();
+
+ if ((result = PyObject_CallFunction(function, (char *)"O&lsssO&",
+ svn_swig_py_prophash_to_dict,
changed_paths,
+ revision,
+ author,
+ date,
+ message,
+ make_ob_pool, pool)) == NULL)
+ {
+ err = convert_python_error();
+ }
+
+ Py_XDECREF(result);
+ release_py_lock();
+
+ return err;
+}
+
/*** Other Wrappers for SVN Functions ***/
Index: bindings/swig/swigutil_py.h
===================================================================
--- bindings/swig/swigutil_py.h (revision 6538)
+++ bindings/swig/swigutil_py.h (working copy)
@@ -97,6 +97,8 @@
apr_file_t *svn_swig_py_make_file(PyObject *py_file,
apr_pool_t *pool);
+svn_stream_t *svn_stream_from_pyio(PyObject *py_io, apr_pool_t *pool);
+
/* a notify function that executes a Python function that is passed in
via the baton argument */
void svn_swig_py_notify_func(void *baton,
@@ -119,6 +121,23 @@
void *baton,
apr_pool_t *pool);
+/* thunked client prompter */
+svn_error_t *
+svn_swig_py_client_prompt_func (const char **info,
+ const char *prompt,
+ svn_boolean_t hide,
+ void *baton,
+ apr_pool_t *pool);
+
+svn_error_t *
+svn_swig_py_log_message_receiver (void *baton,
+ apr_hash_t *changed_paths,
+ svn_revnum_t revision,
+ const char *author,
+ const char *date,
+ const char *message,
+ apr_pool_t *pool);
+
/* thunked log receiver function. */
svn_error_t * svn_swig_py_thunk_log_receiver(void *py_receiver,
apr_hash_t *changed_paths,
|
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Wed Jul 23 09:04:06 2003