~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/memory.py

  • Committer: Tarmac
  • Author(s): Vincent Ladeuil
  • Date: 2017-01-30 14:42:05 UTC
  • mfrom: (6620.1.1 trunk)
  • Revision ID: tarmac-20170130144205-r8fh2xpmiuxyozpv
Merge  2.7 into trunk including fix for bug #1657238 [r=vila]

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011, 2016 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
31
    transport,
36
36
    LockError,
37
37
    InProcessTransport,
38
38
    NoSuchFile,
39
 
    TransportError,
40
39
    )
41
 
from bzrlib.trace import mutter
42
40
from bzrlib.transport import (
43
41
    AppendBasedFileStream,
44
42
    _file_streams,
81
79
 
82
80
    def clone(self, offset=None):
83
81
        """See Transport.clone()."""
84
 
        path = self._combine_paths(self._cwd, offset)
 
82
        path = urlutils.URL._combine_paths(self._cwd, offset)
85
83
        if len(path) == 0 or path[-1] != '/':
86
84
            path += '/'
87
85
        url = self._scheme + path
150
148
        """See Transport.put_file()."""
151
149
        _abspath = self._abspath(relpath)
152
150
        self._check_parent(_abspath)
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)
 
151
        raw_bytes = f.read()
 
152
        self._files[_abspath] = (raw_bytes, mode)
 
153
        return len(raw_bytes)
162
154
 
163
155
    def mkdir(self, relpath, mode=None):
164
156
        """See Transport.mkdir()."""
289
281
            raise LockError('File %r already locked' % (self.path,))
290
282
        self.transport._locks[self.path] = self
291
283
 
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
 
 
298
284
    def unlock(self):
299
285
        del self.transport._locks[self.path]
300
286
        self.transport = None