~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/memory.py

  • Committer: Vincent Ladeuil
  • Date: 2012-03-13 16:42:20 UTC
  • mto: This revision was merged to the branch mainline in revision 6512.
  • Revision ID: v.ladeuil+lp@free.fr-20120313164220-atkou2zprhlspmwg
Mention that a given config option cannot be safely handled via both APIs at the same time.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 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
20
20
so this is primarily useful for testing.
21
21
"""
22
22
 
 
23
from __future__ import absolute_import
 
24
 
23
25
import os
24
26
import errno
25
 
import re
26
27
from stat import S_IFREG, S_IFDIR
27
28
from cStringIO import StringIO
28
 
import warnings
29
29
 
30
30
from bzrlib import (
 
31
    transport,
31
32
    urlutils,
32
33
    )
33
34
from bzrlib.errors import (
35
36
    LockError,
36
37
    InProcessTransport,
37
38
    NoSuchFile,
38
 
    TransportError,
39
39
    )
40
 
from bzrlib.trace import mutter
41
40
from bzrlib.transport import (
42
41
    AppendBasedFileStream,
43
42
    _file_streams,
44
43
    LateReadError,
45
 
    register_transport,
46
 
    Server,
47
 
    Transport,
48
 
    unregister_transport,
49
44
    )
50
45
 
51
46
 
64
59
            self.st_mode = S_IFDIR | perms
65
60
 
66
61
 
67
 
class MemoryTransport(Transport):
 
62
class MemoryTransport(transport.Transport):
68
63
    """This is an in memory file system for transient data storage."""
69
64
 
70
65
    def __init__(self, url=""):
84
79
 
85
80
    def clone(self, offset=None):
86
81
        """See Transport.clone()."""
87
 
        path = self._combine_paths(self._cwd, offset)
 
82
        path = urlutils.URL._combine_paths(self._cwd, offset)
88
83
        if len(path) == 0 or path[-1] != '/':
89
84
            path += '/'
90
85
        url = self._scheme + path
292
287
            raise LockError('File %r already locked' % (self.path,))
293
288
        self.transport._locks[self.path] = self
294
289
 
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
 
 
301
290
    def unlock(self):
302
291
        del self.transport._locks[self.path]
303
292
        self.transport = None
304
293
 
305
294
 
306
 
class MemoryServer(Server):
 
295
class MemoryServer(transport.Server):
307
296
    """Server for the MemoryTransport for testing with."""
308
297
 
309
298
    def start_server(self):
312
301
        self._locks = {}
313
302
        self._scheme = "memory+%s:///" % id(self)
314
303
        def memory_factory(url):
315
 
            result = MemoryTransport(url)
 
304
            from bzrlib.transport import memory
 
305
            result = memory.MemoryTransport(url)
316
306
            result._dirs = self._dirs
317
307
            result._files = self._files
318
308
            result._locks = self._locks
319
309
            return result
320
310
        self._memory_factory = memory_factory
321
 
        register_transport(self._scheme, self._memory_factory)
 
311
        transport.register_transport(self._scheme, self._memory_factory)
322
312
 
323
313
    def stop_server(self):
324
314
        # unregister this server
325
 
        unregister_transport(self._scheme, self._memory_factory)
 
315
        transport.unregister_transport(self._scheme, self._memory_factory)
326
316
 
327
317
    def get_url(self):
328
318
        """See bzrlib.transport.Server.get_url."""
329
319
        return self._scheme
330
320
 
 
321
    def get_bogus_url(self):
 
322
        raise NotImplementedError
 
323
 
331
324
 
332
325
def get_test_permutations():
333
326
    """Return the permutations to be used in testing."""