~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/weavefile.py

  • Committer: John Arbash Meinel
  • Date: 2011-05-11 11:35:28 UTC
  • mto: This revision was merged to the branch mainline in revision 5851.
  • Revision ID: john@arbash-meinel.com-20110511113528-qepibuwxicjrbb2h
Break compatibility with python <2.6.

This includes auditing the code for places where we were doing
explicit 'sys.version' checks and removing them as appropriate.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005 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
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
# Author: Martin Pool <mbp@canonical.com>
18
18
 
72
72
 
73
73
    for l in weave._weave:
74
74
        if isinstance(l, tuple):
75
 
            assert l[0] in '{}[]'
76
75
            if l[0] == '}':
77
76
                f.write('}\n')
78
77
            else:
81
80
            if not l:
82
81
                f.write(', \n')
83
82
            elif l[-1] == '\n':
84
 
                assert l.find('\n', 0, -1) == -1
85
83
                f.write('. ' + l)
86
84
            else:
87
 
                assert l.find('\n') == -1
88
85
                f.write(', ' + l + '\n')
89
86
 
90
87
    f.write('W\n')
102
99
 
103
100
def _read_weave_v5(f, w):
104
101
    """Private helper routine to read a weave format 5 file into memory.
105
 
    
 
102
 
106
103
    This is only to be used by read_weave and WeaveFile.__init__.
107
104
    """
108
105
    #  200   0   2075.5080   1084.0360   bzrlib.weavefile:104(_read_weave_v5)
118
115
    #  200   0    851.7250    501.1120   bzrlib.weavefile:104(_read_weave_v5)
119
116
    # +59363 0    311.8780    311.8780   +<method 'append' of 'list' objects>
120
117
    # +200   0     30.2500     30.2500   +<method 'readlines' of 'file' objects>
121
 
                  
 
118
 
122
119
    from weave import WeaveFormatError
123
120
 
124
 
    lines = iter(f.readlines())
125
 
    
 
121
    try:
 
122
        lines = iter(f.readlines())
 
123
    finally:
 
124
        f.close()
 
125
 
126
126
    try:
127
127
        l = lines.next()
128
128
    except StopIteration:
140
140
                w._parents.append(map(int, l[2:].split(' ')))
141
141
            else:
142
142
                w._parents.append([])
143
 
 
144
143
            l = lines.next()[:-1]
145
 
            assert '1 ' == l[0:2]
146
144
            w._sha1s.append(l[2:])
147
 
                
148
145
            l = lines.next()
149
 
            assert 'n ' == l[0:2]
150
146
            name = l[2:-1]
151
 
            assert name not in w._name_map
152
147
            w._names.append(name)
153
148
            w._name_map[name] = ver
154
 
                
155
149
            l = lines.next()
156
 
            assert l == '\n'
157
 
 
158
150
            ver += 1
159
151
        elif l == 'w\n':
160
152
            break
173
165
        elif l == '}\n':
174
166
            w._weave.append(('}', None))
175
167
        else:
176
 
            assert l[0] in '{[]', l
177
 
            assert l[1] == ' ', l
178
168
            w._weave.append((intern(l[0]), int(l[2:])))
179
 
 
180
169
    return w
181