~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/memory.py

  • Committer: Andrew Bennetts
  • Date: 2010-01-15 05:30:30 UTC
  • mto: (4973.1.1 integration)
  • mto: This revision was merged to the branch mainline in revision 4975.
  • Revision ID: andrew.bennetts@canonical.com-20100115053030-1d6qd89pnj8hmb55
Pass kinds (not pairs) to MergeHookParams.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006 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
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
    urlutils,
 
32
    )
30
33
from bzrlib.errors import (
31
34
    FileExists,
32
35
    LockError,
42
45
    register_transport,
43
46
    Server,
44
47
    Transport,
 
48
    unregister_transport,
45
49
    )
46
 
import bzrlib.urlutils as urlutils
47
50
 
48
51
 
49
52
 
85
88
        if len(path) == 0 or path[-1] != '/':
86
89
            path += '/'
87
90
        url = self._scheme + path
88
 
        result = MemoryTransport(url)
 
91
        result = self.__class__(url)
89
92
        result._dirs = self._dirs
90
93
        result._files = self._files
91
94
        result._locks = self._locks
183
186
        for file in self._files:
184
187
            if file.startswith(self._cwd):
185
188
                yield urlutils.escape(file[len(self._cwd):])
186
 
    
 
189
 
187
190
    def list_dir(self, relpath):
188
191
        """See Transport.list_dir()."""
189
192
        _abspath = self._abspath(relpath)
222
225
                    del container[path]
223
226
        do_renames(self._files)
224
227
        do_renames(self._dirs)
225
 
    
 
228
 
226
229
    def rmdir(self, relpath):
227
230
        """See Transport.rmdir."""
228
231
        _abspath = self._abspath(relpath)
243
246
        """See Transport.stat()."""
244
247
        _abspath = self._abspath(relpath)
245
248
        if _abspath in self._files:
246
 
            return MemoryStat(len(self._files[_abspath][0]), False, 
 
249
            return MemoryStat(len(self._files[_abspath][0]), False,
247
250
                              self._files[_abspath][1])
248
251
        elif _abspath in self._dirs:
249
252
            return MemoryStat(0, True, self._dirs[_abspath])
303
306
class MemoryServer(Server):
304
307
    """Server for the MemoryTransport for testing with."""
305
308
 
306
 
    def setUp(self):
307
 
        """See bzrlib.transport.Server.setUp."""
 
309
    def start_server(self):
308
310
        self._dirs = {'/':None}
309
311
        self._files = {}
310
312
        self._locks = {}
315
317
            result._files = self._files
316
318
            result._locks = self._locks
317
319
            return result
318
 
        register_transport(self._scheme, memory_factory)
 
320
        self._memory_factory = memory_factory
 
321
        register_transport(self._scheme, self._memory_factory)
319
322
 
320
 
    def tearDown(self):
321
 
        """See bzrlib.transport.Server.tearDown."""
 
323
    def stop_server(self):
322
324
        # unregister this server
 
325
        unregister_transport(self._scheme, self._memory_factory)
323
326
 
324
327
    def get_url(self):
325
328
        """See bzrlib.transport.Server.get_url."""