/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/transport/memory.py

  • Committer: Martin
  • Date: 2017-06-09 16:31:49 UTC
  • mto: This revision was merged to the branch mainline in revision 6673.
  • Revision ID: gzlist@googlemail.com-20170609163149-liveiasey25480q6
Make InventoryDeltaError use string formatting, and repr for fileids

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
 
from cStringIO import StringIO
28
 
import warnings
29
28
 
30
 
from bzrlib import (
 
29
from .. import (
31
30
    transport,
32
31
    urlutils,
33
32
    )
34
 
from bzrlib.errors import (
 
33
from ..errors import (
35
34
    FileExists,
36
35
    LockError,
37
36
    InProcessTransport,
38
37
    NoSuchFile,
39
 
    TransportError,
40
 
    )
41
 
from bzrlib.trace import mutter
42
 
from bzrlib.transport import (
 
38
    )
 
39
from ..sixish import (
 
40
    BytesIO,
 
41
    )
 
42
from ..transport import (
43
43
    AppendBasedFileStream,
44
44
    _file_streams,
45
45
    LateReadError,
53
53
        self.st_size = size
54
54
        if not is_dir:
55
55
            if perms is None:
56
 
                perms = 0644
 
56
                perms = 0o644
57
57
            self.st_mode = S_IFREG | perms
58
58
        else:
59
59
            if perms is None:
60
 
                perms = 0755
 
60
                perms = 0o755
61
61
            self.st_mode = S_IFDIR | perms
62
62
 
63
63
 
81
81
 
82
82
    def clone(self, offset=None):
83
83
        """See Transport.clone()."""
84
 
        path = self._combine_paths(self._cwd, offset)
 
84
        path = urlutils.URL._combine_paths(self._cwd, offset)
85
85
        if len(path) == 0 or path[-1] != '/':
86
86
            path += '/'
87
87
        url = self._scheme + path
131
131
        del self._files[_abspath]
132
132
 
133
133
    def external_url(self):
134
 
        """See bzrlib.transport.Transport.external_url."""
 
134
        """See breezy.transport.Transport.external_url."""
135
135
        # MemoryTransport's are only accessible in-process
136
136
        # so we raise here
137
137
        raise InProcessTransport(self)
144
144
                return LateReadError(relpath)
145
145
            else:
146
146
                raise NoSuchFile(relpath)
147
 
        return StringIO(self._files[_abspath][0])
 
147
        return BytesIO(self._files[_abspath][0])
148
148
 
149
149
    def put_file(self, relpath, f, mode=None):
150
150
        """See Transport.put_file()."""
151
151
        _abspath = self._abspath(relpath)
152
152
        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)
 
153
        raw_bytes = f.read()
 
154
        self._files[_abspath] = (raw_bytes, mode)
 
155
        return len(raw_bytes)
162
156
 
163
157
    def mkdir(self, relpath, mode=None):
164
158
        """See Transport.mkdir()."""
199
193
                if path.startswith(_abspath):
200
194
                    trailing = path[len(_abspath):]
201
195
                    if trailing and '/' not in trailing:
202
 
                        result.append(trailing)
203
 
        return map(urlutils.escape, result)
 
196
                        result.append(urlutils.escape(trailing))
 
197
        return result
204
198
 
205
199
    def rename(self, rel_from, rel_to):
206
200
        """Rename a file or directory; fail if the destination exists"""
289
283
            raise LockError('File %r already locked' % (self.path,))
290
284
        self.transport._locks[self.path] = self
291
285
 
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
286
    def unlock(self):
299
287
        del self.transport._locks[self.path]
300
288
        self.transport = None
309
297
        self._locks = {}
310
298
        self._scheme = "memory+%s:///" % id(self)
311
299
        def memory_factory(url):
312
 
            from bzrlib.transport import memory
 
300
            from . import memory
313
301
            result = memory.MemoryTransport(url)
314
302
            result._dirs = self._dirs
315
303
            result._files = self._files
323
311
        transport.unregister_transport(self._scheme, self._memory_factory)
324
312
 
325
313
    def get_url(self):
326
 
        """See bzrlib.transport.Server.get_url."""
 
314
        """See breezy.transport.Server.get_url."""
327
315
        return self._scheme
328
316
 
329
317
    def get_bogus_url(self):