~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/memory.py

  • Committer: Andrew Bennetts
  • Date: 2009-08-24 10:07:40 UTC
  • mto: This revision was merged to the branch mainline in revision 4657.
  • Revision ID: andrew.bennetts@canonical.com-20090824100740-6lhu58wlc7kiz4k3
MoreĀ docstrings.

Show diffs side-by-side

added added

removed removed

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