Rev 2587: * New method ``external_url`` on Transport for obtaining the url to in http://people.ubuntu.com/~robertc/baz2.0/external_url

Robert Collins robertc at robertcollins.net
Thu Jul 5 02:09:37 BST 2007


At http://people.ubuntu.com/~robertc/baz2.0/external_url

------------------------------------------------------------
revno: 2587
revision-id: robertc at robertcollins.net-20070705010911-q93psu3cxxhn8isr
parent: pqm at pqm.ubuntu.com-20070704204059-a1x9jomep52m9arn
committer: Robert Collins <robertc at robertcollins.net>
branch nick: external_url
timestamp: Thu 2007-07-05 11:09:11 +1000
message:
  * New method ``external_url`` on Transport for obtaining the url to
    hand to external processes. (Robert Collins)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/errors.py               errors.py-20050309040759-20512168c4e14fbd
  bzrlib/tests/test_errors.py    test_errors.py-20060210110251-41aba2deddf936a8
  bzrlib/tests/test_transport_implementations.py test_transport_implementations.py-20051227111451-f97c5c7d5c49fce7
  bzrlib/transport/__init__.py   transport.py-20050711165921-4978aa7ce1285ad5
  bzrlib/transport/chroot.py     chroot.py-20061011104729-0us9mgm97z378vnt-1
  bzrlib/transport/decorator.py  decorator.py-20060402223305-e913a0f25319ab42
  bzrlib/transport/ftp.py        ftp.py-20051116161804-58dc9506548c2a53
  bzrlib/transport/http/__init__.py http_transport.py-20050711212304-506c5fd1059ace96
  bzrlib/transport/local.py      local_transport.py-20050711165921-9b1f142bfe480c24
  bzrlib/transport/memory.py     memory.py-20051016101338-cd008dbdf69f04fc
  bzrlib/transport/remote.py     ssh.py-20060608202016-c25gvf1ob7ypbus6-1
  bzrlib/transport/sftp.py       sftp.py-20051019050329-ab48ce71b7e32dfe
=== modified file 'NEWS'
--- a/NEWS	2007-07-04 13:14:50 +0000
+++ b/NEWS	2007-07-05 01:09:11 +0000
@@ -143,6 +143,9 @@
       deprecated in favour of ``MutableTree.smart_add``. (Robert Collins,
       Martin Pool)
 
+    * New method ``external_url`` on Transport for obtaining the url to
+      hand to external processes. (Robert Collins)
+
   TESTING:
 
     * Removed the ``--keep-output`` option from selftest and clean up test

=== modified file 'bzrlib/errors.py'
--- a/bzrlib/errors.py	2007-06-28 16:50:06 +0000
+++ b/bzrlib/errors.py	2007-07-05 01:09:11 +0000
@@ -198,6 +198,15 @@
         self.current = current
 
 
+class InProcessTransport(BzrError):
+
+    _fmt = "The transport '%(transport)s' is only accessible within this " \
+        "process."
+
+    def __init__(self, transport):
+        self.transport = transport
+
+
 class InvalidEntryName(BzrError):
     
     _fmt = "Invalid entry name: %(name)s"

=== modified file 'bzrlib/tests/test_errors.py'
--- a/bzrlib/tests/test_errors.py	2007-06-28 16:50:06 +0000
+++ b/bzrlib/tests/test_errors.py	2007-07-05 01:09:11 +0000
@@ -53,6 +53,12 @@
             'It supports versions "(4, 5, 6)" to "(7, 8, 9)".',
             str(error))
 
+    def test_in_process_transport(self):
+        error = errors.InProcessTransport('fpp')
+        self.assertEqualDiff(
+            "The transport 'fpp' is only accessible within this process.",
+            str(error))
+
     def test_inventory_modified(self):
         error = errors.InventoryModified("a tree to be repred")
         self.assertEqualDiff("The current inventory for the tree 'a tree to "

=== modified file 'bzrlib/tests/test_transport_implementations.py'
--- a/bzrlib/tests/test_transport_implementations.py	2007-06-28 04:57:44 +0000
+++ b/bzrlib/tests/test_transport_implementations.py	2007-07-05 01:09:11 +0000
@@ -135,6 +135,14 @@
         t_b = t_a.clone('b')
         self.assertRaises(NoSuchFile, t_b.ensure_base)
 
+    def test_external_url(self):
+        """.external_url either works or raises InProcessTransport."""
+        t = self.get_transport()
+        try:
+            t.external_url()
+        except errors.InProcessTransport:
+            pass
+
     def test_has(self):
         t = self.get_transport()
 

=== modified file 'bzrlib/transport/__init__.py'
--- a/bzrlib/transport/__init__.py	2007-07-04 09:04:20 +0000
+++ b/bzrlib/transport/__init__.py	2007-07-05 01:09:11 +0000
@@ -291,6 +291,28 @@
         else:
             return True
 
+    def external_url(self):
+        """Return a URL for self that can be given to an external process.
+
+        There is no guarantee that the URL can be accessed from a different
+        machine - e.g. file:/// urls are only usable on the local machine,
+        sftp:/// urls when the server is only bound to localhost are only
+        usable from localhost etc.
+
+        NOTE: This method may remove security wrappers (e.g. on chroot
+        transports) and thus should *only* be used when the result will not
+        be used to obtain a new transport within bzrlib. Ideally chroot
+        transports would know enough to cause the external url to be the exact
+        one used that caused the chrooting in the first place, but that is not
+        currently the case.
+
+        :return: A URL that can be given to another process.
+        :raises InProcessTransport: If the transport is one that cannot be
+            accessed out of the current process (e.g. a MemoryTransport)
+            then InProcessTransport is raised.
+        """
+        raise NotImplementedError(self.external_url)
+
     def should_cache(self):
         """Return True if the data pulled across should be cached locally.
         """

=== modified file 'bzrlib/transport/chroot.py'
--- a/bzrlib/transport/chroot.py	2007-04-13 14:23:26 +0000
+++ b/bzrlib/transport/chroot.py	2007-07-05 01:09:11 +0000
@@ -98,6 +98,15 @@
     def delete_tree(self, relpath):
         return self._call('delete_tree', relpath)
 
+    def external_url(self):
+        """See bzrlib.transport.Transport.external_url."""
+        # Chroots, like MemoryTransport depend on in-process
+        # state and thus the base cannot simply be handed out.
+        # See the base class docstring for more details and
+        # possible directions. For now we return the chrooted
+        # url. 
+        return self.server.backing_transport.external_url()
+
     def get(self, relpath):
         return self._call('get', relpath)
 

=== modified file 'bzrlib/transport/decorator.py'
--- a/bzrlib/transport/decorator.py	2007-04-05 09:35:26 +0000
+++ b/bzrlib/transport/decorator.py	2007-07-05 01:09:11 +0000
@@ -79,6 +79,13 @@
         """See Transport.delete_tree()."""
         return self._decorated.delete_tree(relpath)
 
+    def external_url(self):
+        """See bzrlib.transport.Transport.external_url."""
+        # while decorators are in-process only, they
+        # can be handed back into bzrlib safely, so
+        # its just the base.
+        return self.base
+
     @classmethod
     def _get_url_prefix(self):
         """Return the URL prefix of this decorator."""

=== modified file 'bzrlib/transport/ftp.py'
--- a/bzrlib/transport/ftp.py	2007-07-02 17:35:53 +0000
+++ b/bzrlib/transport/ftp.py	2007-07-05 01:09:11 +0000
@@ -489,6 +489,11 @@
             self._translate_perm_error(e, abspath, 'error deleting',
                 unknown_exc=errors.NoSuchFile)
 
+    def external_url(self):
+        """See bzrlib.transport.Transport.external_url."""
+        # FTP URL's are externally usable.
+        return self.base
+
     def listable(self):
         """See Transport.listable."""
         return True

=== modified file 'bzrlib/transport/http/__init__.py'
--- a/bzrlib/transport/http/__init__.py	2007-07-03 07:03:32 +0000
+++ b/bzrlib/transport/http/__init__.py	2007-07-05 01:09:11 +0000
@@ -439,6 +439,11 @@
         """Delete the item at relpath"""
         raise errors.TransportNotPossible('http does not support delete()')
 
+    def external_url(self):
+        """See bzrlib.transport.Transport.external_url."""
+        # HTTP URL's are externally usable.
+        return self.base
+
     def is_readonly(self):
         """See Transport.is_readonly."""
         return True

=== modified file 'bzrlib/transport/local.py'
--- a/bzrlib/transport/local.py	2007-04-05 09:35:26 +0000
+++ b/bzrlib/transport/local.py	2007-07-05 01:09:11 +0000
@@ -390,6 +390,11 @@
         except (IOError, OSError),e:
             self._translate_error(e, path)
 
+    def external_url(self):
+        """See bzrlib.transport.Transport.external_url."""
+        # File URL's are externally usable.
+        return self.base
+
     def copy_to(self, relpaths, other, mode=None, pb=None):
         """Copy a set of entries from self into another Transport.
 

=== modified file 'bzrlib/transport/memory.py'
--- a/bzrlib/transport/memory.py	2007-04-23 05:03:44 +0000
+++ b/bzrlib/transport/memory.py	2007-07-05 01:09:11 +0000
@@ -27,7 +27,13 @@
 from cStringIO import StringIO
 import warnings
 
-from bzrlib.errors import TransportError, NoSuchFile, FileExists, LockError
+from bzrlib.errors import (
+    FileExists,
+    LockError,
+    InProcessTransport,
+    NoSuchFile,
+    TransportError,
+    )
 from bzrlib.trace import mutter
 from bzrlib.transport import (Transport, register_transport, Server)
 import bzrlib.urlutils as urlutils
@@ -117,6 +123,12 @@
             raise NoSuchFile(relpath)
         del self._files[_abspath]
 
+    def external_url(self):
+        """See bzrlib.transport.Transport.external_url."""
+        # MemoryTransport's are only accessible in-process
+        # so we raise here
+        raise InProcessTransport(self)
+
     def get(self, relpath):
         """See Transport.get()."""
         _abspath = self._abspath(relpath)

=== modified file 'bzrlib/transport/remote.py'
--- a/bzrlib/transport/remote.py	2007-06-27 04:33:04 +0000
+++ b/bzrlib/transport/remote.py	2007-07-05 01:09:11 +0000
@@ -291,6 +291,11 @@
         resp = self._call2('delete', self._remote_path(relpath))
         self._translate_error(resp)
 
+    def external_url(self):
+        """See bzrlib.transport.Transport.external_url."""
+        # the external path for RemoteTransports is the base
+        return self.base
+
     def readv(self, relpath, offsets):
         if not offsets:
             return

=== modified file 'bzrlib/transport/sftp.py'
--- a/bzrlib/transport/sftp.py	2007-04-16 04:24:11 +0000
+++ b/bzrlib/transport/sftp.py	2007-07-05 01:09:11 +0000
@@ -763,6 +763,11 @@
         except (IOError, paramiko.SSHException), e:
             self._translate_io_exception(e, path, ': unable to delete')
             
+    def external_url(self):
+        """See bzrlib.transport.Transport.external_url."""
+        # the external path for SFTP is the base
+        return self.base
+
     def listable(self):
         """Return True if this store supports listing."""
         return True



More information about the bazaar-commits mailing list