~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/memory.py

  • Committer: John Arbash Meinel
  • Date: 2006-10-06 07:13:51 UTC
  • mto: This revision was merged to the branch mainline in revision 2071.
  • Revision ID: john@arbash-meinel.com-20061006071351-e3fdd47eed1c3e7e
lazy import revisionspec and errors for bzrlib.options

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from cStringIO import StringIO
28
28
import warnings
29
29
 
30
 
from bzrlib.errors import (
31
 
    FileExists,
32
 
    LockError,
33
 
    InProcessTransport,
34
 
    NoSuchFile,
35
 
    TransportError,
36
 
    )
 
30
from bzrlib.errors import TransportError, NoSuchFile, FileExists, LockError
37
31
from bzrlib.trace import mutter
38
 
from bzrlib.transport import (
39
 
    LateReadError,
40
 
    register_transport,
41
 
    Server,
42
 
    Transport,
43
 
    )
 
32
from bzrlib.transport import (Transport, register_transport, Server)
44
33
import bzrlib.urlutils as urlutils
45
34
 
46
35
 
128
117
            raise NoSuchFile(relpath)
129
118
        del self._files[_abspath]
130
119
 
131
 
    def external_url(self):
132
 
        """See bzrlib.transport.Transport.external_url."""
133
 
        # MemoryTransport's are only accessible in-process
134
 
        # so we raise here
135
 
        raise InProcessTransport(self)
136
 
 
137
120
    def get(self, relpath):
138
121
        """See Transport.get()."""
139
122
        _abspath = self._abspath(relpath)
140
123
        if not _abspath in self._files:
141
 
            if _abspath in self._dirs:
142
 
                return LateReadError(relpath)
143
 
            else:
144
 
                raise NoSuchFile(relpath)
 
124
            raise NoSuchFile(relpath)
145
125
        return StringIO(self._files[_abspath][0])
146
126
 
147
127
    def put_file(self, relpath, f, mode=None):
148
128
        """See Transport.put_file()."""
149
129
        _abspath = self._abspath(relpath)
150
130
        self._check_parent(_abspath)
151
 
        bytes = f.read()
152
 
        if type(bytes) is not str:
153
 
            # Although not strictly correct, we raise UnicodeEncodeError to be
154
 
            # compatible with other transports.
155
 
            raise UnicodeEncodeError(
156
 
                'undefined', bytes, 0, 1,
157
 
                'put_file must be given a file of bytes, not unicode.')
158
 
        self._files[_abspath] = (bytes, mode)
 
131
        self._files[_abspath] = (f.read(), mode)
159
132
 
160
133
    def mkdir(self, relpath, mode=None):
161
134
        """See Transport.mkdir()."""
180
153
        if _abspath != '/' and _abspath not in self._dirs:
181
154
            raise NoSuchFile(relpath)
182
155
        result = []
183
 
 
184
 
        if not _abspath.endswith('/'):
185
 
            _abspath += '/'
186
 
 
187
 
        for path_group in self._files, self._dirs:
188
 
            for path in path_group:
189
 
                if path.startswith(_abspath):
190
 
                    trailing = path[len(_abspath):]
191
 
                    if trailing and '/' not in trailing:
192
 
                        result.append(trailing)
 
156
        for path in self._files:
 
157
            if (path.startswith(_abspath) and 
 
158
                path[len(_abspath) + 1:].find('/') == -1 and
 
159
                len(path) > len(_abspath)):
 
160
                result.append(path[len(_abspath) + 1:])
 
161
        for path in self._dirs:
 
162
            if (path.startswith(_abspath) and 
 
163
                path[len(_abspath) + 1:].find('/') == -1 and
 
164
                len(path) > len(_abspath) and
 
165
                path[len(_abspath)] == '/'):
 
166
                result.append(path[len(_abspath) + 1:])
193
167
        return map(urlutils.escape, result)
194
168
 
195
169
    def rename(self, rel_from, rel_to):
219
193
        if _abspath in self._files:
220
194
            self._translate_error(IOError(errno.ENOTDIR, relpath), relpath)
221
195
        for path in self._files:
222
 
            if path.startswith(_abspath + '/'):
 
196
            if path.startswith(_abspath):
223
197
                self._translate_error(IOError(errno.ENOTEMPTY, relpath),
224
198
                                      relpath)
225
199
        for path in self._dirs:
226
 
            if path.startswith(_abspath + '/') and path != _abspath:
 
200
            if path.startswith(_abspath) and path != _abspath:
227
201
                self._translate_error(IOError(errno.ENOTEMPTY, relpath), relpath)
228
202
        if not _abspath in self._dirs:
229
203
            raise NoSuchFile(relpath)