~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/memory.py

  • Committer: Robert Collins
  • Date: 2006-09-17 21:03:04 UTC
  • mfrom: (2018 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2019.
  • Revision ID: robertc@robertcollins.net-20060917210304-3a697132f5fb68ac
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
so this is primarily useful for testing.
21
21
"""
22
22
 
23
 
from copy import copy
24
23
import os
25
24
import errno
26
25
import re
59
58
        if url[-1] != '/':
60
59
            url = url + '/'
61
60
        super(MemoryTransport, self).__init__(url)
62
 
        self._cwd = url[url.find(':') + 3:]
 
61
        split = url.find(':') + 3
 
62
        self._scheme = url[:split]
 
63
        self._cwd = url[split:]
63
64
        # dictionaries from absolute path to file mode
64
65
        self._dirs = {'/':None}
65
66
        self._files = {}
67
68
 
68
69
    def clone(self, offset=None):
69
70
        """See Transport.clone()."""
70
 
        if offset is None or offset == '':
71
 
            return copy(self)
72
 
        segments = offset.split('/')
73
 
        cwdsegments = self._cwd.split('/')[:-1]
74
 
        while len(segments):
75
 
            segment = segments.pop(0)
76
 
            if segment == '.':
77
 
                continue
78
 
            if segment == '..':
79
 
                if len(cwdsegments) > 1:
80
 
                    cwdsegments.pop()
81
 
                continue
82
 
            cwdsegments.append(segment)
83
 
        url = self.base[:self.base.find(':') + 3] + '/'.join(cwdsegments) + '/'
 
71
        path = self._combine_paths(self._cwd, offset)
 
72
        if len(path) == 0 or path[-1] != '/':
 
73
            path += '/'
 
74
        url = self._scheme + path
84
75
        result = MemoryTransport(url)
85
76
        result._dirs = self._dirs
86
77
        result._files = self._files
236
227
        relpath = urlutils.unescape(relpath)
237
228
        if relpath.find('..') != -1:
238
229
            raise AssertionError('relpath contains ..')
 
230
        if relpath == '':
 
231
            return '/'
 
232
        if relpath[0] == '/':
 
233
            return relpath
239
234
        if relpath == '.':
240
235
            if (self._cwd == '/'):
241
236
                return self._cwd