~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/memory.py

  • Committer: Robert Collins
  • Date: 2006-04-02 22:42:19 UTC
  • mto: (1634.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 1635.
  • Revision ID: robertc@robertcollins.net-20060402224219-d5a818dc987491fe
Refactor the FakeNFS support into a TransportDecorator.
 * Move the existing boilerplate ReadOnly decorator logic in to a base class
   'bzrlib.transport.decorator.TransportDecorator.'
 * Do the same to the ReadOnlyServer to create
   'bzrlib.transport.decorator.DecoratorServer'.
 * Use the new decorator support to create a trivial FakeNFSTransportDecorator
   class in bzrlib.transport.fakenfs.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from cStringIO import StringIO
29
29
 
30
30
from bzrlib.trace import mutter
31
 
from bzrlib.errors import (TransportError, NoSuchFile, FileExists, LockError,
32
 
                           ResourceBusy)
 
31
from bzrlib.errors import TransportError, NoSuchFile, FileExists, LockError
33
32
from bzrlib.transport import Transport, register_transport, Server
34
33
 
 
34
 
35
35
class MemoryStat(object):
36
36
 
37
37
    def __init__(self, size, is_dir, perms):
234
234
        return self._cwd + relpath
235
235
 
236
236
 
237
 
class FakeNFSTransport(MemoryTransport):
238
 
    """A transport that behaves like NFS, for testing"""
239
 
    def rename(self, rel_from, rel_to):
240
 
        try:
241
 
            MemoryTransport.rename(self, rel_from, rel_to)
242
 
        except FileExists, e:
243
 
            abs_to = self._abspath(rel_to)
244
 
            if abs_to in self._dirs:
245
 
                raise ResourceBusy(rel_to)
246
 
            else:
247
 
                raise
248
 
 
249
 
 
250
237
class _MemoryLock(object):
251
238
    """This makes a lock."""
252
239
 
272
259
class MemoryServer(Server):
273
260
    """Server for the MemoryTransport for testing with."""
274
261
 
275
 
    def setUp(self, scheme=None, transport_class=None):
 
262
    def setUp(self):
276
263
        """See bzrlib.transport.Server.setUp."""
277
264
        self._dirs = {}
278
265
        self._files = {}
279
266
        self._locks = {}
280
 
        if scheme is not None:
281
 
            self._scheme = scheme
282
 
        else:            
283
 
            self._scheme = "memory+%s:" % id(self)
284
 
        if transport_class is None:
285
 
            transport_class = MemoryTransport
 
267
        self._scheme = "memory+%s:" % id(self)
286
268
        def memory_factory(url):
287
 
            result = transport_class(url)
 
269
            result = MemoryTransport(url)
288
270
            result._dirs = self._dirs
289
271
            result._files = self._files
290
272
            result._locks = self._locks
300
282
        return self._scheme
301
283
 
302
284
 
303
 
class FakeNFSServer(MemoryServer):
304
 
    """A fake NFS server to use with the fake transport"""
305
 
    def setUp(self):
306
 
        MemoryServer.setUp(self, "fnfs+%s:" % id(self), FakeNFSTransport)
307
 
 
308
 
 
309
285
def get_test_permutations():
310
286
    """Return the permutations to be used in testing."""
311
 
    return [(MemoryTransport, MemoryServer), (FakeNFSTransport, FakeNFSServer),
 
287
    return [(MemoryTransport, MemoryServer),
312
288
            ]