~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to weave.py

  • Committer: Martin Pool
  • Date: 2005-06-28 09:08:12 UTC
  • mto: This revision was merged to the branch mainline in revision 852.
  • Revision ID: mbp@sourcefrog.net-20050628090812-6fd7739078bdafe3
New WeaveError and WeaveFormatError rather than assertions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
        return s
40
40
 
41
41
 
 
42
class WeaveError(Exception):
 
43
    """Exception in processing weave"""
 
44
 
 
45
 
 
46
class WeaveFormatError(WeaveError):
 
47
    """Weave invariant violated"""
 
48
    
 
49
 
42
50
class Weave(object):
43
51
    """weave - versioned text file storage.
44
52
    
215
223
            if isinstance(l, tuple):
216
224
                c, v = l
217
225
                if c == '{':
218
 
                    if istack:
219
 
                        assert istack[-1][1] < v, \
220
 
                               ("improperly nested insertions %d>=%d on line %d" 
221
 
                                % (istack[-1][1], v, lineno))
 
226
                    if istack and (istack[-1][1] >= v):
 
227
                        raise WeaveFormatError("improperly nested insertions %d>=%d on line %d" 
 
228
                                               % (istack[-1][1], v, lineno))
222
229
                    istack.append(l)
223
230
                    isactive = (v in included)
224
231
                elif c == '}':
227
234
                    assert oldv == v
228
235
                    isactive = istack and (istack[-1][1] in included)
229
236
                else:
230
 
                    raise ValueError("invalid processing instruction %r on line %d"
231
 
                                     % (l, lineno))
 
237
                    raise WeaveFormatError("invalid processing instruction %r on line %d"
 
238
                                           % (l, lineno))
232
239
            else:
233
240
                assert isinstance(l, basestring)
234
241
                if not istack:
235
 
                    raise ValueError("literal at top level on line %d"
236
 
                                     % lineno)
 
242
                    raise WeaveFormatError("literal at top level on line %d"
 
243
                                           % lineno)
237
244
                if isactive:
238
245
                    origin = istack[-1][1]
239
246
                    yield origin, lineno, l
240
247
            lineno += 1
241
248
 
242
249
        if istack:
243
 
            raise ValueError("unclosed insertion blocks at end of weave",
244
 
                             istack)
 
250
            raise WeaveFormatError("unclosed insertion blocks at end of weave",
 
251
                                   istack)
245
252
 
246
253
 
247
254
    def getiter(self, index):
267
274
            included = set()
268
275
            for vi in vers_info[0]:
269
276
                if vi < 0 or vi >= index:
270
 
                    raise ValueError("invalid included version %d for index %d"
271
 
                                     % (vi, index))
 
277
                    raise WeaveFormatError("invalid included version %d for index %d"
 
278
                                               % (vi, index))
272
279
                if vi in included:
273
 
                    raise ValueError("repeated included version %d for index %d"
274
 
                                     % (vi, index))
 
280
                    raise WeaveFormatError("repeated included version %d for index %d"
 
281
                                               % (vi, index))
275
282
                included.add(vi)
276
283
 
277
284