~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/memory.py

  • Committer: Andrew Bennetts
  • Date: 2010-10-08 08:15:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101008081514-dviqzrdfwyzsqbz2
Split NEWS into per-release doc/en/release-notes/bzr-*.txt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2011, 2016 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
 
 
25
23
import os
26
24
import errno
 
25
import re
27
26
from stat import S_IFREG, S_IFDIR
28
27
from cStringIO import StringIO
 
28
import warnings
29
29
 
30
30
from bzrlib import (
31
31
    transport,
36
36
    LockError,
37
37
    InProcessTransport,
38
38
    NoSuchFile,
 
39
    TransportError,
39
40
    )
 
41
from bzrlib.trace import mutter
40
42
from bzrlib.transport import (
41
43
    AppendBasedFileStream,
42
44
    _file_streams,
79
81
 
80
82
    def clone(self, offset=None):
81
83
        """See Transport.clone()."""
82
 
        path = urlutils.URL._combine_paths(self._cwd, offset)
 
84
        path = self._combine_paths(self._cwd, offset)
83
85
        if len(path) == 0 or path[-1] != '/':
84
86
            path += '/'
85
87
        url = self._scheme + path
148
150
        """See Transport.put_file()."""
149
151
        _abspath = self._abspath(relpath)
150
152
        self._check_parent(_abspath)
151
 
        raw_bytes = f.read()
152
 
        self._files[_abspath] = (raw_bytes, mode)
153
 
        return len(raw_bytes)
 
153
        bytes = f.read()
 
154
        if type(bytes) is not str:
 
155
            # Although not strictly correct, we raise UnicodeEncodeError to be
 
156
            # compatible with other transports.
 
157
            raise UnicodeEncodeError(
 
158
                'undefined', bytes, 0, 1,
 
159
                'put_file must be given a file of bytes, not unicode.')
 
160
        self._files[_abspath] = (bytes, mode)
 
161
        return len(bytes)
154
162
 
155
163
    def mkdir(self, relpath, mode=None):
156
164
        """See Transport.mkdir()."""
281
289
            raise LockError('File %r already locked' % (self.path,))
282
290
        self.transport._locks[self.path] = self
283
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
 
284
298
    def unlock(self):
285
299
        del self.transport._locks[self.path]
286
300
        self.transport = None