~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/memory.py

  • Committer: Vincent Ladeuil
  • Date: 2010-02-03 08:32:14 UTC
  • mfrom: (4797.2.10 2.1)
  • mto: This revision was merged to the branch mainline in revision 5000.
  • Revision ID: v.ladeuil+lp@free.fr-20100203083214-7kwhr0tajktb22bb
Merge 2.1 to trunk, including fix for bug #515597

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007, 2008, 2009, 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
28
28
import warnings
29
29
 
30
30
from bzrlib import (
31
 
    transport,
32
31
    urlutils,
33
32
    )
34
33
from bzrlib.errors import (
43
42
    AppendBasedFileStream,
44
43
    _file_streams,
45
44
    LateReadError,
 
45
    register_transport,
 
46
    Server,
 
47
    Transport,
 
48
    unregister_transport,
46
49
    )
47
50
 
48
51
 
61
64
            self.st_mode = S_IFDIR | perms
62
65
 
63
66
 
64
 
class MemoryTransport(transport.Transport):
 
67
class MemoryTransport(Transport):
65
68
    """This is an in memory file system for transient data storage."""
66
69
 
67
70
    def __init__(self, url=""):
81
84
 
82
85
    def clone(self, offset=None):
83
86
        """See Transport.clone()."""
84
 
        path = urlutils.URL._combine_paths(self._cwd, offset)
 
87
        path = self._combine_paths(self._cwd, offset)
85
88
        if len(path) == 0 or path[-1] != '/':
86
89
            path += '/'
87
90
        url = self._scheme + path
289
292
            raise LockError('File %r already locked' % (self.path,))
290
293
        self.transport._locks[self.path] = self
291
294
 
 
295
    def __del__(self):
 
296
        # Should this warn, or actually try to cleanup?
 
297
        if self.transport:
 
298
            warnings.warn("MemoryLock %r not explicitly unlocked" % (self.path,))
 
299
            self.unlock()
 
300
 
292
301
    def unlock(self):
293
302
        del self.transport._locks[self.path]
294
303
        self.transport = None
295
304
 
296
305
 
297
 
class MemoryServer(transport.Server):
 
306
class MemoryServer(Server):
298
307
    """Server for the MemoryTransport for testing with."""
299
308
 
300
309
    def start_server(self):
303
312
        self._locks = {}
304
313
        self._scheme = "memory+%s:///" % id(self)
305
314
        def memory_factory(url):
306
 
            from bzrlib.transport import memory
307
 
            result = memory.MemoryTransport(url)
 
315
            result = MemoryTransport(url)
308
316
            result._dirs = self._dirs
309
317
            result._files = self._files
310
318
            result._locks = self._locks
311
319
            return result
312
320
        self._memory_factory = memory_factory
313
 
        transport.register_transport(self._scheme, self._memory_factory)
 
321
        register_transport(self._scheme, self._memory_factory)
314
322
 
315
323
    def stop_server(self):
316
324
        # unregister this server
317
 
        transport.unregister_transport(self._scheme, self._memory_factory)
 
325
        unregister_transport(self._scheme, self._memory_factory)
318
326
 
319
327
    def get_url(self):
320
328
        """See bzrlib.transport.Server.get_url."""
321
329
        return self._scheme
322
330
 
323
 
    def get_bogus_url(self):
324
 
        raise NotImplementedError
325
 
 
326
331
 
327
332
def get_test_permutations():
328
333
    """Return the permutations to be used in testing."""