equal
deleted
inserted
replaced
178 |
178 |
179 def insert_index(self): |
179 def insert_index(self): |
180 """return the index of the lastest instance which is not a |
180 """return the index of the lastest instance which is not a |
181 LateOperation instance |
181 LateOperation instance |
182 """ |
182 """ |
183 for i, op in enumerate(self.session.pending_operations): |
183 # faster by inspecting operation in reverse order for heavy transactions |
|
184 i = None |
|
185 for i, op in enumerate(reversed(self.session.pending_operations)): |
184 if isinstance(op, (LateOperation, SingleLastOperation)): |
186 if isinstance(op, (LateOperation, SingleLastOperation)): |
185 return i |
187 continue |
186 return None |
188 return -i or None |
|
189 if i is None: |
|
190 return None |
|
191 return -(i + 1) |
187 |
192 |
188 def handle_event(self, event): |
193 def handle_event(self, event): |
189 """delegate event handling to the opertaion""" |
194 """delegate event handling to the opertaion""" |
190 getattr(self, event)() |
195 getattr(self, event)() |
191 |
196 |
236 """ |
241 """ |
237 def insert_index(self): |
242 def insert_index(self): |
238 """return the index of the lastest instance which is not a |
243 """return the index of the lastest instance which is not a |
239 SingleLastOperation instance |
244 SingleLastOperation instance |
240 """ |
245 """ |
241 for i, op in enumerate(self.session.pending_operations): |
246 # faster by inspecting operation in reverse order for heavy transactions |
|
247 i = None |
|
248 for i, op in enumerate(reversed(self.session.pending_operations)): |
242 if isinstance(op, SingleLastOperation): |
249 if isinstance(op, SingleLastOperation): |
243 return i |
250 continue |
244 return None |
251 return -i or None |
|
252 if i is None: |
|
253 return None |
|
254 return -(i + 1) |
245 |
255 |
246 |
256 |
247 class SingleOperation(Operation): |
257 class SingleOperation(Operation): |
248 """special operation which should be called once""" |
258 """special operation which should be called once""" |
249 def register(self, session): |
259 def register(self, session): |
259 session.add_operation(self, self.insert_index()) |
269 session.add_operation(self, self.insert_index()) |
260 return equivalent |
270 return equivalent |
261 |
271 |
262 def equivalent_index(self, operations): |
272 def equivalent_index(self, operations): |
263 """return the index of the equivalent operation if any""" |
273 """return the index of the equivalent operation if any""" |
264 equivalents = [i for i, op in enumerate(operations) |
274 for i, op in enumerate(reversed(operations)): |
265 if op.__class__ is self.__class__] |
275 if op.__class__ is self.__class__: |
266 if equivalents: |
276 return -(i+1) |
267 return equivalents[0] |
|
268 return None |
277 return None |
269 |
278 |
270 |
279 |
271 class SingleLastOperation(SingleOperation): |
280 class SingleLastOperation(SingleOperation): |
272 """special operation which should be called once and after all other |
281 """special operation which should be called once and after all other |