diff options
author | Jelmer Vernooij <jelmer@jelmer.uk> | 2016-07-09 21:20:29 +0000 |
---|---|---|
committer | Jelmer Vernooij <jelmer@jelmer.uk> | 2016-07-09 21:20:29 +0000 |
commit | 314297fc40434cfcb65fcac951f21009a2745993 (patch) | |
tree | 40ef4843d909eae9374c28f6c7e84b64f4d907fb /subvertpy | |
parent | ef0906bcb02ed629a363ab86fa92a00d05e6d99f (diff) |
Add wrapper for converting unicode/bytes objects for SVN use.
Diffstat (limited to 'subvertpy')
-rw-r--r-- | subvertpy/_ra.c | 29 | ||||
-rw-r--r-- | subvertpy/client.c | 14 | ||||
-rw-r--r-- | subvertpy/util.c | 15 | ||||
-rw-r--r-- | subvertpy/util.h | 2 |
4 files changed, 44 insertions, 16 deletions
diff --git a/subvertpy/_ra.c b/subvertpy/_ra.c index 4f204c84..0e900b08 100644 --- a/subvertpy/_ra.c +++ b/subvertpy/_ra.c @@ -567,7 +567,8 @@ static PyObject *ra_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) char *kwnames[] = { "url", "progress_cb", "auth", "config", "client_string_func", "open_tmp_file_func", "uuid", NULL }; - char *url = NULL, *uuid = NULL; + char *uuid = NULL; + PyObject *py_url; PyObject *progress_cb = Py_None; AuthObject *auth = (AuthObject *)Py_None; PyObject *config = Py_None; @@ -578,7 +579,7 @@ static PyObject *ra_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) svn_auth_baton_t *auth_baton; svn_error_t *err; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|OOOOOz", kwnames, &url, + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|OOOOOz", kwnames, &py_url, &progress_cb, (PyObject **)&auth, &config, &client_string_func, &open_tmp_file_func, &uuid)) @@ -588,6 +589,15 @@ static PyObject *ra_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) if (ret == NULL) return NULL; + ret->client_string_func = client_string_func; + ret->open_tmp_file_func = open_tmp_file_func; + Py_INCREF(client_string_func); + + Py_INCREF(progress_cb); + ret->progress_func = progress_cb; + + ret->auth = NULL; + ret->root = NULL; ret->pool = Pool(NULL); if (ret->pool == NULL) { @@ -595,7 +605,7 @@ static PyObject *ra_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) return NULL; } - ret->url = svn_uri_canonicalize(url, ret->pool); + ret->url = py_object_to_svn_uri(py_url, ret->pool); if (ret->url == NULL) { Py_DECREF(ret); return NULL; @@ -622,16 +632,11 @@ static PyObject *ra_new(PyTypeObject *type, PyObject *args, PyObject *kwargs) return NULL; } - ret->client_string_func = client_string_func; - ret->open_tmp_file_func = open_tmp_file_func; - Py_INCREF(client_string_func); + callbacks2->progress_baton = (void *)ret; callbacks2->progress_func = py_progress_func; callbacks2->auth_baton = auth_baton; callbacks2->open_tmp_file = py_open_tmp_file; callbacks2->cancel_func = py_cancel_check; - Py_INCREF(progress_cb); - ret->progress_func = progress_cb; - callbacks2->progress_baton = (void *)ret; #if ONLY_SINCE_SVN(1, 5) callbacks2->get_client_string = py_get_client_string; #endif @@ -694,11 +699,11 @@ static PyObject *ra_get_uuid(PyObject *self) /** Switch to a different url. */ static PyObject *ra_reparent(PyObject *self, PyObject *args) { - char *url; + PyObject *py_url; apr_pool_t *temp_pool; RemoteAccessObject *ra = (RemoteAccessObject *)self; - if (!PyArg_ParseTuple(args, "s:reparent", &url)) + if (!PyArg_ParseTuple(args, "O:reparent", &py_url)) return NULL; if (ra_check_busy(ra)) @@ -707,7 +712,7 @@ static PyObject *ra_reparent(PyObject *self, PyObject *args) temp_pool = Pool(NULL); if (temp_pool == NULL) return NULL; - ra->url = svn_uri_canonicalize(url, ra->pool); + ra->url = py_object_to_svn_uri(py_url, ra->pool); RUN_RA_WITH_POOL(temp_pool, ra, svn_ra_reparent(ra->ra, ra->url, temp_pool)); apr_pool_destroy(temp_pool); Py_RETURN_NONE; diff --git a/subvertpy/client.c b/subvertpy/client.c index 5fc29991..1b240d17 100644 --- a/subvertpy/client.c +++ b/subvertpy/client.c @@ -529,12 +529,13 @@ static PyObject *client_checkout(PyObject *self, PyObject *args, PyObject *kwarg char *kwnames[] = { "url", "path", "rev", "peg_rev", "recurse", "ignore_externals", "allow_unver_obstructions", NULL }; svn_revnum_t result_rev; svn_opt_revision_t c_peg_rev, c_rev; - char *url, *path; + char *path, *url; + PyObject *py_url = NULL; apr_pool_t *temp_pool; PyObject *peg_rev=Py_None, *rev=Py_None; bool recurse=true, ignore_externals=false, allow_unver_obstructions=false; - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ss|OObbb", kwnames, &url, &path, &rev, &peg_rev, &recurse, &ignore_externals, &allow_unver_obstructions)) + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Os|OObbb", kwnames, &py_url, &path, &rev, &peg_rev, &recurse, &ignore_externals, &allow_unver_obstructions)) return NULL; if (!to_opt_revision(peg_rev, &c_peg_rev)) @@ -545,8 +546,13 @@ static PyObject *client_checkout(PyObject *self, PyObject *args, PyObject *kwarg temp_pool = Pool(NULL); if (temp_pool == NULL) return NULL; + + url = py_object_to_svn_uri(py_url, temp_pool); + if (url == NULL) + return NULL; + #if ONLY_SINCE_SVN(1, 5) - RUN_SVN_WITH_POOL(temp_pool, svn_client_checkout3(&result_rev, svn_uri_canonicalize(url, temp_pool), + RUN_SVN_WITH_POOL(temp_pool, svn_client_checkout3(&result_rev, url, svn_dirent_canonicalize(path, temp_pool), &c_peg_rev, &c_rev, recurse?svn_depth_infinity:svn_depth_files, ignore_externals, allow_unver_obstructions, client->client, temp_pool)); @@ -558,7 +564,7 @@ static PyObject *client_checkout(PyObject *self, PyObject *args, PyObject *kwarg return NULL; } - RUN_SVN_WITH_POOL(temp_pool, svn_client_checkout2(&result_rev, svn_uri_canonicalize(url, temp_pool), + RUN_SVN_WITH_POOL(temp_pool, svn_client_checkout2(&result_rev, url, svn_dirent_canonicalize(path, temp_pool), &c_peg_rev, &c_rev, recurse, ignore_externals, client->client, temp_pool)); diff --git a/subvertpy/util.c b/subvertpy/util.c index 03f497ac..71fe420e 100644 --- a/subvertpy/util.c +++ b/subvertpy/util.c @@ -68,6 +68,21 @@ svn_dirent_canonicalize(const char *dirent, } #endif +char *py_object_to_svn_uri(PyObject *obj, apr_pool_t *pool) +{ + if (PyUnicode_Check(obj)) { + obj = PyUnicode_AsUTF8String(obj); + } + + if (PyBytes_Check(obj)) { + return svn_uri_canonicalize(PyBytes_AsString(obj), pool); + } else { + PyErr_SetString(PyExc_TypeError, + "URIs need to be UTF-8 bytestrings or unicode strings"); + return NULL; + } +} + apr_pool_t *Pool(apr_pool_t *parent) { apr_status_t status; diff --git a/subvertpy/util.h b/subvertpy/util.h index baaa8825..672a5a49 100644 --- a/subvertpy/util.h +++ b/subvertpy/util.h @@ -152,4 +152,6 @@ svn_relpath_canonicalize(const char *relpath, apr_pool_t *result_pool); #endif +char *py_object_to_svn_uri(PyObject *obj, apr_pool_t *pool); + #endif /* _SUBVERTPY_UTIL_H_ */ |