subversion-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From troycurti...@apache.org
Subject svn commit: r1819202 - in /subversion/branches/swig-py3/subversion/bindings/swig: include/ python/libsvn_swig_py/ python/tests/ python/tests/trac/versioncontrol/tests/
Date Sun, 24 Dec 2017 04:47:31 GMT
Author: troycurtisjr
Date: Sun Dec 24 04:47:31 2017
New Revision: 1819202

URL: http://svn.apache.org/viewvc?rev=1819202&view=rev
Log:
On branch swig-py3: Fix additional Bytes versus String inconsistencies.

Be explicit about UTF-8 conversions between bytes and strings. All
swig unit tests now pass under both Python 2 and 3.

* subversion/bindings/swig/include/svn_types.swg
  (typemap(argout) unsigned char digest[ANY], unsigned char *digest):
  Treat checksum digest data correctly as bytes, not a string.

* subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
  (write_handler_pyio): Create a compatibility definition, SVN_SWIG_BYTES_FMT, to
   ensure raw file data is treated as bytes in Python 3 and string in Python2.

* subversion/bindings/swig/python/tests/delta.py,
  subversion/bindings/swig/python/tests/ra.py,
  subversion/bindings/swig/python/tests/repository.py,
  subversion/bindings/swig/python/tests/utils.py,
  subversion/bindings/swig/python/tests/wc.py,
  subversion/bindings/swig/python/tests/trac/versioncontrol/tests/svn_fs.py
  (DeltaTestCase.testTxWindowHandler,
   DeltaTestCase.testTxdeltaWindowT,
   SubversionRepositoryAccessTestCase.test_get_file,
   SubversionRepositoryTestCase.test_dump_fs2,
   Temper.alloc_known_repo,
   SubversionWorkingCopyTestCase.test_diff_editor4.write_diff,
   SubversionRepositoryTestSetup.setUp):
  Use BytesIO instead of StringIO to servce as a source of raw binary data.

  (SubversionRepositoryTestCase.test_parse_fns3):
  Open raw data file in binary mode.

  (SubversionWorkingCopyTestCase.test_commit):
  Explicity encode data being written to a file opened in binary mode and
  decode binary data in the result from binascii.b2a_hex().


Modified:
    subversion/branches/swig-py3/subversion/bindings/swig/include/svn_types.swg
    subversion/branches/swig-py3/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
    subversion/branches/swig-py3/subversion/bindings/swig/python/tests/delta.py
    subversion/branches/swig-py3/subversion/bindings/swig/python/tests/ra.py
    subversion/branches/swig-py3/subversion/bindings/swig/python/tests/repository.py
    subversion/branches/swig-py3/subversion/bindings/swig/python/tests/trac/versioncontrol/tests/svn_fs.py
    subversion/branches/swig-py3/subversion/bindings/swig/python/tests/utils.py
    subversion/branches/swig-py3/subversion/bindings/swig/python/tests/wc.py

Modified: subversion/branches/swig-py3/subversion/bindings/swig/include/svn_types.swg
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/include/svn_types.swg?rev=1819202&r1=1819201&r2=1819202&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/include/svn_types.swg (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/include/svn_types.swg Sun Dec 24
04:47:31 2017
@@ -1098,7 +1098,7 @@ svn_ ## TYPE ## _swig_rb_closed(VALUE se
 #ifdef SWIGPYTHON
 %typemap(argout) unsigned char digest[ANY]
 {
-  %append_output(PyStr_FromStringAndSize((const char *)$1, APR_MD5_DIGESTSIZE));
+  %append_output(PyBytes_FromStringAndSize((const char *)$1, APR_MD5_DIGESTSIZE));
 }
 #endif
 
@@ -1171,7 +1171,7 @@ svn_ ## TYPE ## _swig_rb_closed(VALUE se
     if ($input == Py_None) {
         $1 = NULL;
     } else {
-        $1 = (unsigned char *) PyStr_AsString($input);
+        $1 = (unsigned char *) PyBytes_AsString($input);
         if ($1 == NULL) SWIG_fail;
     }
 }

Modified: subversion/branches/swig-py3/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c?rev=1819202&r1=1819201&r2=1819202&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
(original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/python/libsvn_swig_py/swigutil_py.c
Sun Dec 24 04:47:31 2017
@@ -59,6 +59,15 @@
 #undef PyLong_FromSize_t
 #undef PyLong_AsLong
 #undef PyInt_Check
+
+/* In Python 3 use the bytes format character for raw data */
+#define SVN_SWIG_BYTES_FMT "y"
+
+#else
+
+/* In Python 2 use the string format character for raw data */
+#define SVN_SWIG_BYTES_FMT "s"
+
 #endif
 
 #include <py3c.h>
@@ -2579,7 +2588,8 @@ write_handler_pyio(void *baton, const ch
     {
       svn_swig_py_acquire_py_lock();
       if ((result = PyObject_CallMethod(py_io, (char *)"write",
-                                        (char *)"s#", data, *len)) == NULL)
+                                       (char *) SVN_SWIG_BYTES_FMT "#",
+                                       data, *len)) == NULL)
         {
           err = callback_exception_error();
         }

Modified: subversion/branches/swig-py3/subversion/bindings/swig/python/tests/delta.py
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/python/tests/delta.py?rev=1819202&r1=1819201&r2=1819202&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/python/tests/delta.py (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/python/tests/delta.py Sun Dec 24
04:47:31 2017
@@ -22,20 +22,15 @@ import unittest, setup_path
 import svn.delta
 import svn.core
 from sys import version_info # For Python version check
-if version_info[0] >= 3:
-  # Python >=3.0
-  from io import StringIO
-else:
-  # Python <3.0
-  from cStringIO import StringIO
+from io import BytesIO
 
 # Test case for svn.delta
 class DeltaTestCase(unittest.TestCase):
 
   def testTxWindowHandler(self):
     """Test tx_invoke_window_handler"""
-    src_stream = StringIO("hello world")
-    target_stream = StringIO("bye world")
+    src_stream = BytesIO("hello world".encode('UTF-8'))
+    target_stream = BytesIO("bye world".encode('UTF-8'))
 
     # Invoke the window_handler using a helper function
     window_handler, baton = \
@@ -49,8 +44,8 @@ class DeltaTestCase(unittest.TestCase):
 
   def testTxdeltaWindowT(self):
     """Test the svn_txdelta_window_t wrapper."""
-    a = StringIO("abc\ndef\n")
-    b = StringIO("def\nghi\n")
+    a = BytesIO("abc\ndef\n".encode('UTF-8'))
+    b = BytesIO("def\nghi\n".encode('UTF-8'))
 
     delta_stream = svn.delta.svn_txdelta(a, b)
     window = svn.delta.svn_txdelta_next_window(delta_stream)

Modified: subversion/branches/swig-py3/subversion/bindings/swig/python/tests/ra.py
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/python/tests/ra.py?rev=1819202&r1=1819201&r2=1819202&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/python/tests/ra.py (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/python/tests/ra.py Sun Dec 24 04:47:31
2017
@@ -22,12 +22,7 @@ import unittest, setup_path
 
 from svn import core, repos, fs, delta, ra
 from sys import version_info # For Python version check
-if version_info[0] >= 3:
-  # Python >=3.0
-  from io import StringIO
-else:
-  # Python <3.0
-  from StringIO import StringIO
+from io import BytesIO
 
 import utils
 
@@ -64,10 +59,10 @@ class SubversionRepositoryAccessTestCase
     self.assertEqual(properties["svn:mime-type"], "text/plain")
 
     # Test getting the contents of a file
-    filestream = StringIO()
+    filestream = BytesIO()
     rev, properties = ra.get_file(self.ra_ctx, "trunk/README2.txt",
                                   fs_revnum, filestream)
-    self.assertEqual("A test.\n", filestream.getvalue())
+    self.assertEqual("A test.\n", filestream.getvalue().decode('UTF-8'))
 
   def test_get_repos_root(self):
     root = ra.get_repos_root(self.ra_ctx)

Modified: subversion/branches/swig-py3/subversion/bindings/swig/python/tests/repository.py
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/python/tests/repository.py?rev=1819202&r1=1819201&r2=1819202&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/python/tests/repository.py (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/python/tests/repository.py Sun Dec
24 04:47:31 2017
@@ -20,12 +20,7 @@
 #
 import unittest, setup_path, os, sys
 from sys import version_info # For Python version check
-if version_info[0] >= 3:
-  # Python >=3.0
-  from io import StringIO
-else:
-  # Python <3.0
-  from StringIO import StringIO
+from io import BytesIO
 from svn import core, repos, fs, delta
 from svn.core import SubversionException
 import utils
@@ -130,14 +125,14 @@ class SubversionRepositoryTestCase(unitt
       self.callback_calls += 1
       return None
 
-    dumpstream = StringIO()
-    feedbackstream = StringIO()
+    dumpstream = BytesIO()
+    feedbackstream = BytesIO()
     repos.dump_fs2(self.repos, dumpstream, feedbackstream, 0, self.rev, 0, 0,
                    is_cancelled)
 
     # Check that we can dump stuff
-    dump = dumpstream.getvalue()
-    feedback = feedbackstream.getvalue()
+    dump = dumpstream.getvalue().decode("UTF-8")
+    feedback = feedbackstream.getvalue().decode("UTF-8")
     expected_feedback = "* Dumped revision " + str(self.rev)
     self.assertEqual(dump.count("Node-path: trunk/README.txt"), 2)
     self.assertEqual(feedback.count(expected_feedback), 1)
@@ -154,17 +149,17 @@ class SubversionRepositoryTestCase(unitt
     self.assertRaises(ValueError, repos.dump_fs2,
       self.repos, dumpstream, feedbackstream, 0, self.rev, 0, 0, None)
 
-    dumpstream = StringIO()
-    feedbackstream = StringIO()
+    dumpstream = BytesIO()
+    feedbackstream = BytesIO()
 
     # Check that we can grab the feedback stream, but not the dumpstream
     repos.dump_fs2(self.repos, None, feedbackstream, 0, self.rev, 0, 0, None)
-    feedback = feedbackstream.getvalue()
+    feedback = feedbackstream.getvalue().decode('UTF-8')
     self.assertEqual(feedback.count(expected_feedback), 1)
 
     # Check that we can grab the dumpstream, but not the feedbackstream
     repos.dump_fs2(self.repos, dumpstream, None, 0, self.rev, 0, 0, None)
-    dump = dumpstream.getvalue()
+    dump = dumpstream.getvalue().decode('UTF-8')
     self.assertEqual(dump.count("Node-path: trunk/README.txt"), 2)
 
     # Check that we can ignore both the dumpstream and the feedbackstream
@@ -182,7 +177,7 @@ class SubversionRepositoryTestCase(unitt
       return None
     dump_path = os.path.join(os.path.dirname(sys.argv[0]),
         "trac/versioncontrol/tests/svnrepos.dump")
-    stream = open(dump_path)
+    stream = open(dump_path, 'rb')
     dsp = DumpStreamParser()
     ptr, baton = repos.make_parse_fns3(dsp)
     repos.parse_dumpstream3(stream, ptr, baton, False, is_cancelled)

Modified: subversion/branches/swig-py3/subversion/bindings/swig/python/tests/trac/versioncontrol/tests/svn_fs.py
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/python/tests/trac/versioncontrol/tests/svn_fs.py?rev=1819202&r1=1819201&r2=1819202&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/python/tests/trac/versioncontrol/tests/svn_fs.py
(original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/python/tests/trac/versioncontrol/tests/svn_fs.py
Sun Dec 24 04:47:31 2017
@@ -53,7 +53,7 @@ import shutil
 import sys
 import tempfile
 import unittest
-from io import StringIO
+from io import BytesIO
 
 if sys.version_info[0] >= 3:
   # Python >=3.0
@@ -94,7 +94,7 @@ class SubversionRepositoryTestSetup(Test
             self.tearDown()
 
             r = repos.svn_repos_create(REPOS_PATH, '', '', None, None)
-            repos.svn_repos_load_fs2(r, dumpfile, StringIO(),
+            repos.svn_repos_load_fs2(r, dumpfile, BytesIO(),
                                     repos.svn_repos_load_uuid_ignore, '',
                                     0, 0, None)
 

Modified: subversion/branches/swig-py3/subversion/bindings/swig/python/tests/utils.py
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/python/tests/utils.py?rev=1819202&r1=1819201&r2=1819202&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/python/tests/utils.py (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/python/tests/utils.py Sun Dec 24
04:47:31 2017
@@ -20,13 +20,12 @@
 #
 import os.path, sys, tempfile
 from svn import core, repos
+from io import BytesIO
 try:
   # Python >=3.0
-  from io import StringIO
   from urllib.request import pathname2url
 except ImportError:
   # Python <3.0
-  from cStringIO import StringIO
   from urllib import pathname2url
 
 class Temper(object):
@@ -69,7 +68,7 @@ class Temper(object):
     dump_path = os.path.join(os.path.dirname(sys.argv[0]), repo_id)
     (handle, repo_path, repo_uri) = self.alloc_empty_repo(suffix=suffix)
     with open(dump_path, 'rb') as dump_fp:
-      repos.svn_repos_load_fs2(handle, dump_fp, StringIO(),
+      repos.svn_repos_load_fs2(handle, dump_fp, BytesIO(),
                                repos.load_uuid_default, None, False, False, None)
     return (handle, repo_path, repo_uri)
 

Modified: subversion/branches/swig-py3/subversion/bindings/swig/python/tests/wc.py
URL: http://svn.apache.org/viewvc/subversion/branches/swig-py3/subversion/bindings/swig/python/tests/wc.py?rev=1819202&r1=1819201&r2=1819202&view=diff
==============================================================================
--- subversion/branches/swig-py3/subversion/bindings/swig/python/tests/wc.py (original)
+++ subversion/branches/swig-py3/subversion/bindings/swig/python/tests/wc.py Sun Dec 24 04:47:31
2017
@@ -19,12 +19,7 @@
 #
 #
 from sys import version_info # For Python version check
-if version_info[0] >= 3:
-  # Python >=3.0
-  from io import StringIO
-else:
-  # Python <3.0
-  from cStringIO import StringIO
+from io import BytesIO
 import unittest, os, tempfile, setup_path, binascii
 import svn.diff
 from svn import core, repos, wc, client
@@ -229,7 +224,7 @@ class SubversionWorkingCopyTestCase(unit
     # exact contents even on Windows, and therefore the MD5 checksum.
     readme_path = '%s/trunk/README.txt' % self.path
     fp = open(readme_path, 'wb')
-    fp.write('hello\n')
+    fp.write('hello\n'.encode('UTF-8'))
     fp.close()
 
     # Setup ra_ctx.
@@ -270,7 +265,7 @@ class SubversionWorkingCopyTestCase(unit
     (commit_info,) = commit_info
 
     # Assert the commit.
-    self.assertEqual(binascii.b2a_hex(checksum),
+    self.assertEqual(binascii.b2a_hex(checksum).decode('UTF-8'),
                       'b1946ac92492d2347c6235b4d2611184')
     self.assertEqual(commit_info.revision, 13)
 
@@ -346,13 +341,13 @@ class SubversionWorkingCopyTestCase(unit
       original_header = modified_header = ''
       encoding = 'utf8'
       relative_to_dir = None
-      sio = StringIO()
-      svn.diff.file_output_unified3(sio, diff,
+      bio = BytesIO()
+      svn.diff.file_output_unified3(bio, diff,
                                     left, right,
                                     original_header, modified_header,
                                     encoding, relative_to_dir,
                                     options.show_c_function, pool)
-      got_diffs[path[len(self.path) + 1:]] = sio.getvalue().splitlines()
+      got_diffs[path[len(self.path) + 1:]] = bio.getvalue().decode('UTF-8').splitlines()
 
     # Diff callbacks that call props_changed and write_diff.
     contentstate = propstate = state = wc.notify_state_unknown



Mime
View raw message