/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/transport/__init__.py

  • Committer: Robert Collins
  • Date: 2006-09-16 06:44:47 UTC
  • mfrom: (2014 +trunk)
  • mto: (2017.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 2018.
  • Revision ID: robertc@robertcollins.net-20060916064447-99a2987e5485b5ea
Merge from bzr.dev, fixing found bugs handling 'has('/')' in MemoryTransport and SFTP transports.

Show diffs side-by-side

added added

removed removed

Lines of Context:
165
165
            port = int(port)
166
166
        except ValueError:
167
167
            # TODO: Should this be ConnectionError?
168
 
            raise errors.TransportError('%s: invalid port number' % port)
 
168
            raise errors.TransportError(
 
169
                'invalid port number %s in url:\n%s' % (port, url))
169
170
    host = urllib.unquote(host)
170
171
 
171
172
    path = urllib.unquote(path)
306
307
 
307
308
    def abspath(self, relpath):
308
309
        """Return the full url to the given relative path.
309
 
        This can be supplied with a string or a list
310
310
 
311
 
        XXX: Robert Collins 20051016 - is this really needed in the public
312
 
             interface ?
 
311
        :param relpath: a string of a relative path
313
312
        """
 
313
 
 
314
        # XXX: Robert Collins 20051016 - is this really needed in the public
 
315
        # interface ?
314
316
        raise NotImplementedError(self.abspath)
315
317
 
 
318
    def _combine_paths(self, base_path, relpath):
 
319
        """Transform a Transport-relative path to a remote absolute path.
 
320
 
 
321
        This does not handle substitution of ~ but does handle '..' and '.'
 
322
        components.
 
323
 
 
324
        Examples::
 
325
 
 
326
            >>> t = Transport('/')
 
327
            >>> t._combine_paths('/home/sarah', 'project/foo')
 
328
            '/home/sarah/project/foo'
 
329
            >>> t._combine_paths('/home/sarah', '../../etc')
 
330
            '/etc'
 
331
 
 
332
        :param base_path: urlencoded path for the transport root; typically a 
 
333
             URL but need not contain scheme/host/etc.
 
334
        :param relpath: relative url string for relative part of remote path.
 
335
        :return: urlencoded string for final path.
 
336
        """
 
337
        # FIXME: share the common code across more transports; variants of
 
338
        # this likely occur in http and sftp too.
 
339
        #
 
340
        # TODO: Also need to consider handling of ~, which might vary between
 
341
        # transports?
 
342
        if not isinstance(relpath, str):
 
343
            raise errors.InvalidURL("not a valid url: %r" % relpath)
 
344
        base_parts = base_path.split('/')
 
345
        if len(base_parts) > 0 and base_parts[-1] == '':
 
346
            base_parts = base_parts[:-1]
 
347
        for p in relpath.split('/'):
 
348
            if p == '..':
 
349
                if len(base_parts) == 0:
 
350
                    # In most filesystems, a request for the parent
 
351
                    # of root, just returns root.
 
352
                    continue
 
353
                base_parts.pop()
 
354
            elif p == '.':
 
355
                continue # No-op
 
356
            elif p != '':
 
357
                base_parts.append(p)
 
358
        path = '/'.join(base_parts)
 
359
        return path
 
360
 
316
361
    def relpath(self, abspath):
317
362
        """Return the local path portion from a given absolute path.
318
363
 
861
906
        WARNING: many transports do not support this, so trying avoid using
862
907
        it if at all possible.
863
908
        """
864
 
        raise errors.TransportNotPossible("This transport has not "
 
909
        raise errors.TransportNotPossible("Transport %r has not "
865
910
                                          "implemented list_dir "
866
911
                                          "(but must claim to be listable "
867
 
                                          "to trigger this error).")
 
912
                                          "to trigger this error)."
 
913
                                          % (self))
868
914
 
869
915
    def lock_read(self, relpath):
870
916
        """Lock the given file for shared (read) access.
871
 
        WARNING: many transports do not support this, so trying avoid using it
 
917
 
 
918
        WARNING: many transports do not support this, so trying avoid using it.
 
919
        These methods may be removed in the future.
 
920
 
 
921
        Transports may raise TransportNotPossible if OS-level locks cannot be
 
922
        taken over this transport.  
872
923
 
873
924
        :return: A lock object, which should contain an unlock() function.
874
925
        """
875
 
        raise NotImplementedError(self.lock_read)
 
926
        raise errors.TransportNotPossible("transport locks not supported on %s" % self)
876
927
 
877
928
    def lock_write(self, relpath):
878
929
        """Lock the given file for exclusive (write) access.
879
 
        WARNING: many transports do not support this, so trying avoid using it
 
930
 
 
931
        WARNING: many transports do not support this, so trying avoid using it.
 
932
        These methods may be removed in the future.
 
933
 
 
934
        Transports may raise TransportNotPossible if OS-level locks cannot be
 
935
        taken over this transport.
880
936
 
881
937
        :return: A lock object, which should contain an unlock() function.
882
938
        """
883
 
        raise NotImplementedError(self.lock_write)
 
939
        raise errors.TransportNotPossible("transport locks not supported on %s" % self)
884
940
 
885
941
    def is_readonly(self):
886
942
        """Return true if this connection cannot be written to."""