Python3 portability fixes.
authorJelmer Vernooij <jelmer@jelmer.uk>
Fri, 25 May 2018 20:05:40 +0000 (21:05 +0100)
committerJelmer Vernooij <jelmer@jelmer.uk>
Fri, 25 May 2018 20:05:40 +0000 (21:05 +0100)
subvertpy/_ra.c
subvertpy/tests/test_wc.py
subvertpy/util.c
subvertpy/wc_adm.c

index c9bc18b7e41b96aea7350350becf87824afe48bd..3fb1b52cedfc1dd9bf447d09b756af65516888bd 100644 (file)
@@ -1346,15 +1346,16 @@ static PyObject *get_commit_editor(PyObject *self, PyObject *args, PyObject *kwa
                hash_lock_tokens = NULL;
        } else {
                Py_ssize_t idx = 0;
+               char *key, *val;
                PyObject *k, *v;
                hash_lock_tokens = apr_hash_make(pool);
                while (PyDict_Next(lock_tokens, &idx, &k, &v)) {
-                       if (!PyBytes_Check(k)) {
-                               PyErr_SetString(PyExc_TypeError, "token not bytes");
+                       key = py_object_to_svn_string(k, pool);
+                       if (key == NULL) {
                                goto fail_prep;
                        }
-                       apr_hash_set(hash_lock_tokens, PyBytes_AsString(k),
-                                                PyBytes_Size(k), PyBytes_AsString(v));
+                       val = apr_pmemdup(pool, PyBytes_AsString(v), PyBytes_Size(v));
+                       apr_hash_set(hash_lock_tokens, key, strlen(key), val);
                }
        }
 
index 4350a82858a4cf483213a2e0dfab268e1555b7fc..62cd675b2df4fe1bf75be7051a872f80b008ab85 100644 (file)
@@ -161,12 +161,9 @@ class AdmObjTests(SubversionTestCase):
         self.client_set_prop("checkout/bar", "svn:keywords", "Id\n")
         self.client_commit("checkout", "foo")
         adm = wc.Adm(None, "checkout", True)
-        path = os.path.join(self.test_dir, "checkout/bar")
-        stream = adm.translated_stream(path, path, wc.TRANSLATE_TO_NF)
-        if wc.api_version() < (1, 6):
-            self.assertRaises(NotImplementedError, stream.read)
-        else:
-            self.assertTrue(stream.read().startswith(b"My id: $Id: "))
+        stream = adm.translated_stream('checkout/bar', 'checkout/bar', wc.TRANSLATE_TO_NF)
+        body = stream.read()
+        self.assertTrue(body.startswith(b"My id: $Id: "), body)
 
     def test_text_modified(self):
         self.make_client("repos", "checkout")
@@ -295,7 +292,7 @@ class AdmObjTests(SubversionTestCase):
         self.assertEqual("bar", bar.name)
         self.assertEqual(NODE_FILE, bar.kind)
         self.assertEqual(wc.SCHEDULE_NORMAL, bar.schedule)
-        self.assertIn(bar.checksum, (None, hashlib.md5('blala').hexdigest()))
+        self.assertIn(bar.checksum, (None, hashlib.md5(b'blala').hexdigest()))
         self.assertEqual(1, bar.cmt_rev)
         self.assertEqual(1, bar.revision)
 
index 8fe7407aaf2fad573fff0c995e76f6fb8beb01e8..715f9c829389d2b9a54dd5f8015bfaeeac504afb 100644 (file)
@@ -522,9 +522,7 @@ PyObject *prop_hash_to_dict(apr_hash_t *props)
                if (PyDict_SetItem(py_props, py_key, py_val) != 0) {
                        Py_DECREF(py_key);
                        Py_DECREF(py_val);
-                       Py_DECREF(py_props);
-                       apr_pool_destroy(pool);
-                       return NULL;
+                       goto fail_item;
                }
                Py_DECREF(py_key);
                Py_DECREF(py_val);
@@ -560,17 +558,10 @@ apr_hash_t *prop_dict_to_hash(apr_pool_t *pool, PyObject *py_props)
 
        while (PyDict_Next(py_props, &idx, &k, &v)) {
                char *key, *val;
-               Py_ssize_t key_size, val_size;
-               if (PyUnicode_Check(k)) {
-                       k = PyUnicode_AsUTF8String(k);
-               } else {
-                       Py_INCREF(k);
-               }
+               Py_ssize_t val_size;
 
-               if (!PyBytes_Check(k)) {
-                       PyErr_SetString(PyExc_TypeError,
-                                                       "property name should be unicode or byte string");
-                       Py_DECREF(k);
+               key = py_object_to_svn_string(k, pool);
+               if (key == NULL) {
                        return NULL;
                }
 
@@ -580,26 +571,17 @@ apr_hash_t *prop_dict_to_hash(apr_pool_t *pool, PyObject *py_props)
                        Py_INCREF(v);
                }
 
-               if (PyBytes_AsStringAndSize(k, &key, &key_size) == -1) {
-                       PyErr_SetString(PyExc_TypeError,
-                                                       "property key should be unicode or byte string");
-                       Py_DECREF(k);
-                       Py_DECREF(v);
-                       return NULL;
-               }
-
                if (PyBytes_AsStringAndSize(v, &val, &val_size) == -1) {
                        PyErr_SetString(PyExc_TypeError,
                                                        "property value should be unicode or byte string");
-                       Py_DECREF(k);
-                       Py_DECREF(v);
                        return NULL;
                }
 
                val_string = svn_string_ncreate(val, val_size, pool);
-               apr_hash_set(hash_props, key, key_size, val_string);
-               Py_DECREF(k);
+
                Py_DECREF(v);
+
+               apr_hash_set(hash_props, key, strlen(key), val_string);
        }
 
        return hash_props;
index edea6d8dd9517c387fee2780d93c052e1882d0bd..6ced3c1b21224222eadc98664af6ce55a639b4df 100644 (file)
@@ -1780,7 +1780,7 @@ static PyMethodDef adm_methods[] = {
     { "get_ancestry", (PyCFunction)get_ancestry, METH_VARARGS,
         "S.get_ancestry(path) -> (url, rev)" },
     { "maybe_set_repos_root", (PyCFunction)maybe_set_repos_root, METH_VARARGS, "S.maybe_set_repos_root(path, repos)" },
-    { "add_repos_file", (PyCFunction)add_repos_file, METH_KEYWORDS,
+    { "add_repos_file", (PyCFunction)add_repos_file, METH_KEYWORDS|METH_VARARGS,
         "S.add_repos_file(dst_path, new_base_contents, new_contents, new_base_props, new_props, copyfrom_url=None, copyfrom_rev=-1, notify_func=None)" },
     { "mark_missing_deleted", (PyCFunction)mark_missing_deleted, METH_VARARGS,
         "S.mark_missing_deleted(path)" },