/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/store/text.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 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 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
20
20
do any sort of delta compression.
21
21
"""
22
22
 
 
23
from __future__ import absolute_import
 
24
 
23
25
import gzip
24
26
import os
25
 
from cStringIO import StringIO
26
 
 
27
 
from bzrlib import osutils
28
 
from bzrlib.errors import BzrError, NoSuchFile, FileExists
29
 
import bzrlib.store
30
 
from bzrlib.trace import mutter
31
 
 
32
 
 
33
 
 
34
 
class TextStore(bzrlib.store.TransportStore):
 
27
 
 
28
from .. import osutils
 
29
from ..errors import BzrError, NoSuchFile, FileExists
 
30
from ..sixish import (
 
31
    BytesIO,
 
32
    )
 
33
from . import TransportStore
 
34
from ..trace import mutter
 
35
 
 
36
 
 
37
 
 
38
class TextStore(TransportStore):
35
39
    """Store that holds files indexed by unique names.
36
40
 
37
41
    Files can be added, but not modified once they are in.  Typically
42
46
    """
43
47
 
44
48
    def _add_compressed(self, fn, f):
45
 
        from cStringIO import StringIO
46
 
        from bzrlib.osutils import pumpfile
47
 
 
48
 
        if isinstance(f, basestring):
49
 
            f = StringIO(f)
50
 
 
51
 
        sio = StringIO()
 
49
        from ..osutils import pumpfile
 
50
 
 
51
        if isinstance(f, bytes):
 
52
            f = BytesIO(f)
 
53
 
 
54
        sio = BytesIO()
52
55
        gf = gzip.GzipFile(mode='wb', fileobj=sio)
53
56
        # if pumpfile handles files that don't fit in ram,
54
57
        # so will this function
115
118
        f = self._transport.get(filename)
116
119
        # gzip.GzipFile.read() requires a tell() function
117
120
        # but some transports return objects that cannot seek
118
 
        # so buffer them in a StringIO instead
 
121
        # so buffer them in a BytesIO instead
119
122
        if getattr(f, 'tell', None) is not None:
120
123
            return gzip.GzipFile(mode='rb', fileobj=f)
121
 
        else:
122
 
            from cStringIO import StringIO
123
 
            sio = StringIO(f.read())
 
124
        try:
 
125
            sio = BytesIO(f.read())
124
126
            return gzip.GzipFile(mode='rb', fileobj=sio)
 
127
        finally:
 
128
            f.close()