~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/memory.py

  • Committer: Jelmer Vernooij
  • Date: 2010-12-20 11:57:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5577.
  • Revision ID: jelmer@samba.org-20101220115714-2ru3hfappjweeg7q
Don't use no-plugins.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
1
# Copyright (C) 2005-2010 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
17
"""Implementation of Transport that uses memory for its storage.
18
18
 
27
27
from cStringIO import StringIO
28
28
import warnings
29
29
 
 
30
from bzrlib import (
 
31
    transport,
 
32
    urlutils,
 
33
    )
30
34
from bzrlib.errors import (
31
35
    FileExists,
32
36
    LockError,
39
43
    AppendBasedFileStream,
40
44
    _file_streams,
41
45
    LateReadError,
42
 
    register_transport,
43
 
    Server,
44
 
    Transport,
45
46
    )
46
 
import bzrlib.urlutils as urlutils
47
47
 
48
48
 
49
49
 
61
61
            self.st_mode = S_IFDIR | perms
62
62
 
63
63
 
64
 
class MemoryTransport(Transport):
 
64
class MemoryTransport(transport.Transport):
65
65
    """This is an in memory file system for transient data storage."""
66
66
 
67
67
    def __init__(self, url=""):
85
85
        if len(path) == 0 or path[-1] != '/':
86
86
            path += '/'
87
87
        url = self._scheme + path
88
 
        result = MemoryTransport(url)
 
88
        result = self.__class__(url)
89
89
        result._dirs = self._dirs
90
90
        result._files = self._files
91
91
        result._locks = self._locks
183
183
        for file in self._files:
184
184
            if file.startswith(self._cwd):
185
185
                yield urlutils.escape(file[len(self._cwd):])
186
 
    
 
186
 
187
187
    def list_dir(self, relpath):
188
188
        """See Transport.list_dir()."""
189
189
        _abspath = self._abspath(relpath)
222
222
                    del container[path]
223
223
        do_renames(self._files)
224
224
        do_renames(self._dirs)
225
 
    
 
225
 
226
226
    def rmdir(self, relpath):
227
227
        """See Transport.rmdir."""
228
228
        _abspath = self._abspath(relpath)
243
243
        """See Transport.stat()."""
244
244
        _abspath = self._abspath(relpath)
245
245
        if _abspath in self._files:
246
 
            return MemoryStat(len(self._files[_abspath][0]), False, 
 
246
            return MemoryStat(len(self._files[_abspath][0]), False,
247
247
                              self._files[_abspath][1])
248
248
        elif _abspath in self._dirs:
249
249
            return MemoryStat(0, True, self._dirs[_abspath])
261
261
    def _abspath(self, relpath):
262
262
        """Generate an internal absolute path."""
263
263
        relpath = urlutils.unescape(relpath)
264
 
        if relpath == '':
265
 
            return '/'
266
 
        if relpath[0] == '/':
 
264
        if relpath[:1] == '/':
267
265
            return relpath
268
266
        cwd_parts = self._cwd.split('/')
269
267
        rel_parts = relpath.split('/')
285
283
    """This makes a lock."""
286
284
 
287
285
    def __init__(self, path, transport):
288
 
        assert isinstance(transport, MemoryTransport)
289
286
        self.path = path
290
287
        self.transport = transport
291
288
        if self.path in self.transport._locks:
303
300
        self.transport = None
304
301
 
305
302
 
306
 
class MemoryServer(Server):
 
303
class MemoryServer(transport.Server):
307
304
    """Server for the MemoryTransport for testing with."""
308
305
 
309
 
    def setUp(self):
310
 
        """See bzrlib.transport.Server.setUp."""
 
306
    def start_server(self):
311
307
        self._dirs = {'/':None}
312
308
        self._files = {}
313
309
        self._locks = {}
314
310
        self._scheme = "memory+%s:///" % id(self)
315
311
        def memory_factory(url):
316
 
            result = MemoryTransport(url)
 
312
            from bzrlib.transport import memory
 
313
            result = memory.MemoryTransport(url)
317
314
            result._dirs = self._dirs
318
315
            result._files = self._files
319
316
            result._locks = self._locks
320
317
            return result
321
 
        register_transport(self._scheme, memory_factory)
 
318
        self._memory_factory = memory_factory
 
319
        transport.register_transport(self._scheme, self._memory_factory)
322
320
 
323
 
    def tearDown(self):
324
 
        """See bzrlib.transport.Server.tearDown."""
 
321
    def stop_server(self):
325
322
        # unregister this server
 
323
        transport.unregister_transport(self._scheme, self._memory_factory)
326
324
 
327
325
    def get_url(self):
328
326
        """See bzrlib.transport.Server.get_url."""
329
327
        return self._scheme
330
328
 
 
329
    def get_bogus_url(self):
 
330
        raise NotImplementedError
 
331
 
331
332
 
332
333
def get_test_permutations():
333
334
    """Return the permutations to be used in testing."""