Adapt to splitup of “urllib” in Python 3
authorYonggang Luo <luoyonggang@gmail.com>
Thu, 18 Oct 2012 11:11:25 +0000 (19:11 +0800)
committerJelmer Vernooij <jelmer@jelmer.uk>
Fri, 8 Jul 2016 11:29:08 +0000 (11:29 +0000)
subvertpy/ra.py
subvertpy/ra_svn.py
subvertpy/tests/__init__.py

index 89a9d100d4c1c9ef06341f9bbfc287fc5b8060cc..9963edda728cc27e82a37cb6809131e24342a949 100644 (file)
@@ -23,7 +23,10 @@ from subvertpy import _ra
 from subvertpy._ra import *
 from subvertpy import ra_svn
 
-import urllib
+try:
+    from urllib2 import splittype
+except ImportError:
+    from urllib.parse import splittype
 
 url_handlers = {
         "svn": _ra.RemoteAccess,
@@ -43,7 +46,7 @@ def RemoteAccess(url, *args, **kwargs):
     """
     if isinstance(url, bytes):
         url = url.decode("utf-8")
-    (type, opaque) = urllib.splittype(url)
+    (type, opaque) = splittype(url)
     if not type in url_handlers:
         raise SubversionException("Unknown URL type '%s'" % type, ERR_BAD_URL)
     return url_handlers[type](url, *args, **kwargs)
index ddf0c2ce13c30733658ba493f1b67044ac0bdf14..04213e81d0d457487949abc477034a4116ec3c28 100644 (file)
@@ -22,8 +22,11 @@ import base64
 import os
 import socket
 import subprocess
-import urllib
 from errno import EPIPE
+try:
+    import urlparse
+except ImportError:
+    import urllib.parse as urlparse
 
 from subvertpy import (
     ERR_RA_SVN_UNKNOWN_CMD,
@@ -420,9 +423,9 @@ class SVNClient(SVNConnection):
     def __init__(self, url, progress_cb=None, auth=None, config=None, 
                  client_string_func=None, open_tmp_file_func=None):
         self.url = url
-        (type, opaque) = urllib.splittype(url)
+        (type, opaque) = urlparse.splittype(url)
         assert type in ("svn", "svn+ssh")
-        (host, path) = urllib.splithost(opaque)
+        (host, path) = urlparse.splithost(opaque)
         self._progress_cb = progress_cb
         self._auth = auth
         self._config = config
@@ -468,7 +471,7 @@ class SVNClient(SVNConnection):
     _recv_ack = _unpack
 
     def _connect(self, host):
-        (host, port) = urllib.splitnport(host, SVN_PORT)
+        (host, port) = urlparse.splitnport(host, SVN_PORT)
         sockaddrs = socket.getaddrinfo(host, port, socket.AF_UNSPEC,
                socket.SOCK_STREAM, 0, 0)
         self._socket = None
@@ -476,7 +479,7 @@ class SVNClient(SVNConnection):
             try:
                 self._socket = socket.socket(family, socktype, proto)
                 self._socket.connect(sockaddr)
-            except socket.error:
+            except socket.error as err:
                 if self._socket is not None:
                     self._socket.close()
                 self._socket = None
@@ -488,12 +491,12 @@ class SVNClient(SVNConnection):
         return (self._socket.recv, self._socket.send)
 
     def _connect_ssh(self, host):
-        (user, host) = urllib.splituser(host)
+        (user, host) = urlparse.splituser(host)
         if user is not None:
-            (user, password) = urllib.splitpassword(user)
+            (user, password) = urlparse.splitpassword(user)
         else:
             password = None
-        (host, port) = urllib.splitnport(host, 22)
+        (host, port) = urlparse.splitnport(host, 22)
         self._tunnel = get_ssh_vendor().connect_ssh(user, password, host, port, ["svnserve", "-t"])
         return (self._tunnel.recv, self._tunnel.send)
 
@@ -916,7 +919,7 @@ class SVNServer(SVNConnection):
         self.send_success()
 
     def open_backend(self, url):
-        (rooturl, location) = urllib.splithost(url)
+        (rooturl, location) = urlparse.splithost(url)
         self.repo_backend, self.relpath = self.backend.open_repository(location)
 
     def reparent(self, parent):
index b1f34565492f3b19918b5c33bf0540c5561123e5..c668bc8e01904da1c84346ca323051015844e0b1 100644 (file)
@@ -26,12 +26,14 @@ import stat
 import sys
 import tempfile
 import unittest
-import urllib2
-import urllib
 try:
     import urlparse
 except ImportError:
     import urllib.parse as urlparse
+try:
+    from urllib import pathname2url
+except ImportError:
+    from urllib.request import pathname2url
 
 from subvertpy import (
     client,
@@ -106,7 +108,7 @@ class TestFileEditor(object):
 
     def modify(self, contents=None):
         if contents is None:
-            contents = urllib2.randombytes(100)
+            contents = os.urandom(100)
         txdelta = self.file.apply_textdelta()
         delta.send_stream(BytesIO(contents), txdelta)
 
@@ -248,7 +250,7 @@ class SubversionTestCase(TestCaseInTempDir):
                 os.chmod(revprop_hook, os.stat(revprop_hook).st_mode | 0o111)
 
         if sys.platform == 'win32':
-            return 'file:%s' % urllib.pathname2url(abspath)
+            return 'file:%s' % pathname2url(abspath)
         else:
             return "file://%s" % abspath