简体   繁体   中英

How can I call the svn.client.svn_client_list2 with python SVN API SWIG bindings?

The question

How do I call svn_client_list2 C API function from python via SVN API SWIG bindings?

Problem description

I can find that function from the svn.client module, but calling it is the problem , because the callback function it uses is a typedef svn_client_list_func_t and I don't know how to use that typedef in python.

Although I can find a class for it from svn.client.svn_client_list_func_t along with svn.client.svn_client_list_func_tPtr , but I can't find an example of how to use it.

Incorrect usage of svn.client.svn_client_list2

If you call the svn.client.svn_client_list2 function with a normal python function as callback parameter it gives you an error.

 import svn.core, svn.client path = svn.core.svn_path_canonicalize("/path/to/a/working_copy/") pool = svn.core.Pool() ctx = svn.client.svn_client_create_context(pool) revision = svn.core.svn_opt_revision_t() SVN_DIRENT_ALL = 0xffffffffl def _handle_list(path, dirent, abs_path, pool): print(path, dirent, abs_path, pool) svn.client.svn_client_list2(path, revision, revision, svn.core.svn_depth_infinity, SVN_DIRENT_ALL, True, _handle_list, ctx, pool) 

TypeError: argument number 7: a 'svn_client_list_func_t *' is expected, 'function(<function _handle_list at 0x01365270>)' is received

Incorrect usage of svn.client.svn_client_list_func_t

Trying to initialize the svn.client.svn_client_list_func_t will result to an exception.

 callback_function = svn.client.svn_client_list_func_t() 

RuntimeError: No constructor defined

Ideas how I can proceed?

It looks like you can't really do this at the moment. When I dug into bit into the SWIG bindings code and documentation it says that when you're using target language functions as the callback function, you need a typemap for it as it says in the SWIG documentation :

Although SWIG does not normally allow callback functions to be written in the target language, this can be accomplished with the use of typemaps and other advanced SWIG features.

It looked like it was missing for Python...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM