PageRenderTime 20ms CodeModel.GetById 12ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/src/djapian/utils/commiter.py

http://djapian.googlecode.com/
Python | 42 lines | 31 code | 11 blank | 0 comment | 4 complexity | 14a8681c74aeb8adcc643c866d0f495d MD5 | raw file
 1class Commiter(object):
 2    def __init__(self, begin, commit, cancel):
 3        self._begin = begin
 4        self._commit = commit
 5        self._cancel = cancel
 6
 7    def begin_page(self):
 8        pass
 9
10    def begin_object(self):
11        pass
12
13    def commit_page(self):
14        pass
15
16    def commit_object(self):
17        pass
18
19    def cancel_page(self):
20        pass
21
22    def cancel_object(self):
23        pass
24
25    @classmethod
26    def create(cls, commit_each):
27        class _ConcreteCommiter(cls):
28            pass
29
30        prefix = commit_each and 'object' or 'page'
31
32        for name in ('begin', 'commit', 'cancel'):
33            def make_method(name):
34                return lambda self: getattr(self, '_%s' % name)()
35
36            setattr(
37                _ConcreteCommiter,
38                '%s_%s' % (name, prefix),
39                make_method(name)
40            )
41
42        return _ConcreteCommiter