Rev 2513: Further simplifications and doc updates. in file:///v/home/vila/src/experimental/reuse.transports/

Vincent Ladeuil v.ladeuil+lp at free.fr
Sat Jun 2 16:22:37 BST 2007


At file:///v/home/vila/src/experimental/reuse.transports/

------------------------------------------------------------
revno: 2513
revision-id: v.ladeuil+lp at free.fr-20070602152234-ry0ngv0zbx9yxse0
parent: v.ladeuil+lp at free.fr-20070602144026-bvhq9zlis7l6qe7j
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: reuse.transports
timestamp: Sat 2007-06-02 17:22:34 +0200
message:
  Further simplifications and doc updates.
  
  * bzrlib/transport/__init__.py:
  (ConnectedTransport._urlencode_abspath): Deleted. Useless now.
  (ConnectedTransport._urldecode_abspath): Deleted. Useless now.
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/transport/__init__.py   transport.py-20050711165921-4978aa7ce1285ad5
  bzrlib/transport/http/__init__.py http_transport.py-20050711212304-506c5fd1059ace96
-------------- next part --------------
=== modified file 'NEWS'
--- a/NEWS	2007-05-30 07:10:06 +0000
+++ b/NEWS	2007-06-02 15:22:34 +0000
@@ -8,6 +8,11 @@
       is specified, and are labelled "revision-id:", as per mainline
       revisions, instead of "merged:". (Kent Gibson)
 
+    * Refactoring of transport classes connected to a remote server.
+     transport.split_url have been deprecated, use the static method on the
+     object instead (SFTP needs to override the default handling for home
+     directories). URL tests have been refactored too.  (Vincent Ladeuil)
+
   IMPROVEMENTS:
   
     * There are two new help topics, working-trees and repositories that
@@ -55,12 +60,11 @@
       the root of the source tree and allows HACKING to be split into multiple
       files. (Robert Collins, Alexander Belchenko)
 
-    * ``bzr init`` should only connect to the remote location one time.
-      We have been connecting several times because we forget to pass
-      around the Transport object. This modifies
-      ``BzrDir.create_branch_convenience``, so that we can pass in the
-      Transport that we already have.
-     (John Arbash Meinel, Vincent Ladeuil, #111702)
+    * ``bzr init`` should only connect to the remote location one time.  We
+      have been connecting several times because we forget to pass around the
+      Transport object. This modifies ``BzrDir.create_branch_convenience``,
+      so that we can pass in the Transport that we already have.
+      (John Arbash Meinel, Vincent Ladeuil, #111702)
 
 bzr 0.16rc2  2007-04-30
 

=== modified file 'bzrlib/transport/__init__.py'
--- a/bzrlib/transport/__init__.py	2007-06-01 20:26:46 +0000
+++ b/bzrlib/transport/__init__.py	2007-06-02 15:22:34 +0000
@@ -1032,12 +1032,21 @@
 class ConnectedTransport(Transport):
     """A transport connected to a remote server.
 
-    Base class for transports that connect to a remote server
-    with optional user and password. Cloning preserves existing
-    connection and credentials.
+    This class provide the basis to implement transports that need to connect
+    to a remote server.
+
+    Host and credentials are available as private attributes, cloning preserves
+    them and share the underlying, protocol specific, connection.
     """
 
     def __init__(self, base, from_transport=None):
+        """Constructor.
+
+        :param base: transport root URL
+
+        :param from_transport: optional transport to build from. The built
+            transport will share the connection with this transport.
+        """
         if base[-1] != '/':
             base += '/'
         (self._scheme,
@@ -1045,13 +1054,14 @@
          self._host, self._port,
          self._path) = self._initial_split_url(base)
         if from_transport is not None:
-            # Copy the password as it does not appear in base
+            # Copy the password as it does not appear in base and will be lost
+            # otherwise.
             self._password = from_transport._password
 
         base = self._unsplit_url(self._scheme,
                                  self._user, self._password,
                                  self._host, self._port,
-                                 self._urlencode_abspath(self._path))
+                                 self._path)
 
         super(ConnectedTransport, self).__init__(base)
         if from_transport is not None:
@@ -1072,6 +1082,17 @@
             return self.__class__(self.abspath(offset), self)
 
     def _split_url(self, url):
+        """
+        Extract the server address, the credentials and the path from the url.
+
+        user, password, host and path should be quoted if they contain reserved
+        chars.
+
+        :param url: an quoted url
+
+        :return: (scheme, user, password, host, port, path) tuple, all fields
+            are unquoted.
+        """
         if isinstance(url, unicode):
             raise errors.InvalidURL('should be ascii:\n%r' % url)
         url = url.encode('utf-8')
@@ -1095,14 +1116,38 @@
                 raise errors.InvalidURL('invalid port number %s in url:\n%s' %
                                         (port, url))
         host = urllib.unquote(host)
-        path = self._urldecode_abspath(path)
+        path = urllib.unquote(path)
 
         return (scheme, user, password, host, port, path)
 
     _initial_split_url = _split_url
-    """Hook for daughter classes that needs a special processing"""
+    """Hook for daughter classes that needs a special processing.
+
+    This method is called during transport construction against
+    the provided base.
+    """
 
     def _unsplit_url(self, scheme, user, password, host, port, path):
+        """
+        Build the full URL for the given already URL encoded path.
+
+        user, password, host and path will be quoted if they contain reserved
+        chars.
+
+        :param scheme: protocol
+
+        :param user: login
+
+        :param password: associated password
+
+        :param host: the server address
+
+        :param port: the associated port
+
+        :param path: the absolute path on the server
+
+        :return: The corresponding URL.
+        """
         netloc = urllib.quote(host)
         if user is not None:
             # Note that we don't put the password back even if we
@@ -1111,16 +1156,12 @@
             netloc = '%s@%s' % (urllib.quote(user), netloc)
         if port is not None:
             netloc = '%s:%d' % (netloc, port)
+        path = urllib.quote(path)
         return urlparse.urlunparse((scheme, netloc, path, None, None, None))
 
-    def _urlencode_abspath(self, abspath):
-        return urllib.quote(abspath)
-
-    def _urldecode_abspath(self, abspath):
-        return urllib.unquote(abspath)
-
     def relpath(self, abspath):
-        scheme, user, password, host, port, path = self._split_url(abspath)
+        """Return the local path portion from a given absolute path."""
+       scheme, user, password, host, port, path = self._split_url(abspath)
         error = []
         if (scheme != self._scheme):
             error.append('scheme mismatch')
@@ -1142,18 +1183,25 @@
         """Return the full url to the given relative path.
         
         :param relpath: the relative path urlencoded
+
         :returns: the Unicode version of the absolute path for relpath.
         """
         relative = urlutils.unescape(relpath).encode('utf-8')
         path = self._combine_paths(self._path, relative)
         return self._unsplit_url(self._scheme, self._user, self._password,
                                  self._host, self._port,
-                                 self._urlencode_abspath(path))
+                                 path)
 
     def _remote_path(self, relpath):
         """Return the absolute path part of the url to the given relative path.
-        
-        :param relpath: is a urlencoded string.
+
+        This is the path that the remote server expect to receive in the
+        requests, daughter classes should redefine this method if needed and
+        use the result to build their requests.
+
+        :param relpath: the path relative to the transport base urlencoded.
+
+        :return: the absolute Unicode path on the server,
         """
         relative = urlutils.unescape(relpath).encode('utf-8')
         remote_path = self._combine_paths(self._path, relative)
@@ -1166,10 +1214,9 @@
     def set_connection(self, connection):
         """Set the transport specific connection object.
 
-        Note: daughter classes should ensure that the connection
-        is still shared if the connection is reset during the
-        transport lifetime (using a list containing the single
-        connection can help avoid aliasing bugs).
+        Note: daughter classes should ensure that the connection is still
+        shared if the connection is reset during the transport lifetime (using
+        a list containing the single connection can help avoid aliasing bugs).
         """
         self._connection = connection
 

=== modified file 'bzrlib/transport/http/__init__.py'
--- a/bzrlib/transport/http/__init__.py	2007-06-01 20:26:46 +0000
+++ b/bzrlib/transport/http/__init__.py	2007-06-02 15:22:34 +0000
@@ -159,7 +159,7 @@
         return self._unsplit_url(self._unqualified_scheme,
                                  self._user, self._password,
                                  self._host, self._port,
-                                 self._urlencode_abspath(path))
+                                 path)
 
     def has(self, relpath):
         raise NotImplementedError("has() is abstract on %r" % self)



More information about the bazaar-commits mailing list