summaryrefslogtreecommitdiff
path: root/subversion/bindings/swig/python/tests/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'subversion/bindings/swig/python/tests/utils.py')
-rw-r--r--subversion/bindings/swig/python/tests/utils.py30
1 files changed, 22 insertions, 8 deletions
diff --git a/subversion/bindings/swig/python/tests/utils.py b/subversion/bindings/swig/python/tests/utils.py
index 2223809..c8b7e9d 100644
--- a/subversion/bindings/swig/python/tests/utils.py
+++ b/subversion/bindings/swig/python/tests/utils.py
@@ -18,9 +18,15 @@
# under the License.
#
#
-import os.path, sys, tempfile, urllib
+import os.path, sys, tempfile
from svn import core, repos
-from StringIO import StringIO
+from io import BytesIO
+try:
+ # Python >=3.0
+ from urllib.request import pathname2url
+except ImportError:
+ # Python <3.0
+ from urllib import pathname2url
class Temper(object):
"""Class to simplify allocation and cleanup of dummy Subversion
@@ -41,14 +47,19 @@ class Temper(object):
def alloc_empty_dir(self, suffix = ""):
"""Create an empty temporary directory. Returns its full path
in canonical internal form."""
- temp_dir_name = core.svn_dirent_internal_style(tempfile.mkdtemp(suffix))
+ if isinstance(suffix, bytes):
+ suffix = suffix.decode('UTF-8')
+ temp_dir_name = tempfile.mkdtemp(suffix).encode('UTF-8')
+ temp_dir_name = core.svn_dirent_internal_style(temp_dir_name)
self._cleanup_list.append((temp_dir_name, core.svn_io_remove_dir))
return temp_dir_name
def alloc_empty_repo(self, suffix = ""):
"""Create an empty repository. Returns a tuple of its handle, path and
file: URI in canonical internal form."""
- temp_path = tempfile.mkdtemp(suffix)
+ if isinstance(suffix, bytes):
+ suffix = suffix.decode('UTF-8')
+ temp_path = tempfile.mkdtemp(suffix).encode('UTF-8')
repo_path = core.svn_dirent_internal_style(temp_path)
repo_uri = core.svn_uri_canonicalize(file_uri_for_path(temp_path))
handle = repos.create(repo_path, None, None, None, None)
@@ -61,15 +72,18 @@ class Temper(object):
location. Returns the same as alloc_empty_repo."""
dump_path = os.path.join(os.path.dirname(sys.argv[0]), repo_id)
(handle, repo_path, repo_uri) = self.alloc_empty_repo(suffix=suffix)
- repos.svn_repos_load_fs2(handle, open(dump_path, 'rb'), StringIO(),
- repos.load_uuid_default, None, False, False, None)
+ with open(dump_path, 'rb') as dump_fp:
+ repos.svn_repos_load_fs2(handle, dump_fp, BytesIO(),
+ repos.load_uuid_default, None, False, False, None)
return (handle, repo_path, repo_uri)
def file_uri_for_path(path):
"""Return the file: URI corresponding to the given path."""
- uri_path = urllib.pathname2url(path)
+ if not isinstance(path, str):
+ path = path.decode('UTF-8')
+ uri_path = pathname2url(path).encode('UTF-8')
# pathname2url claims to return the path part of the URI, but on Windows
# it returns both the authority and path parts for no reason, which
# means we have to trim the leading slashes to "normalize" the result.
- return 'file:///' + uri_path.lstrip('/')
+ return b'file:///' + uri_path.lstrip(b'/')