~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/decorators.py

MergeĀ fromĀ old-hpss-branch-implementation-test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
           ]
23
23
 
24
24
 
 
25
import sys
 
26
 
 
27
 
25
28
def _get_parameters(func):
26
29
    """Recreate the parameters for a function using introspection.
27
30
 
89
92
def %(name)s_read_locked(%(params)s):
90
93
    self.lock_read()
91
94
    try:
92
 
        return unbound(%(passed_params)s)
93
 
    finally:
 
95
        result = unbound(%(passed_params)s)
 
96
    except:
 
97
        import sys
 
98
        exc_info = sys.exc_info()
 
99
        try:
 
100
            self.unlock()
 
101
        finally:
 
102
            raise exc_info[0], exc_info[1], exc_info[2]
 
103
    else:
94
104
        self.unlock()
 
105
        return result
95
106
read_locked = %(name)s_read_locked
96
107
"""
97
108
    params, passed_params = _get_parameters(unbound)
124
135
    def read_locked(self, *args, **kwargs):
125
136
        self.lock_read()
126
137
        try:
127
 
            return unbound(self, *args, **kwargs)
128
 
        finally:
 
138
            result = unbound(self, *args, **kwargs)
 
139
        except:
 
140
            import sys
 
141
            exc_info = sys.exc_info()
 
142
            try:
 
143
                self.unlock()
 
144
            finally:
 
145
                raise exc_info[0], exc_info[1], exc_info[2]
 
146
        else:
129
147
            self.unlock()
 
148
            return result
130
149
    read_locked.__doc__ = unbound.__doc__
131
150
    read_locked.__name__ = unbound.__name__
132
151
    return read_locked
138
157
def %(name)s_write_locked(%(params)s):
139
158
    self.lock_write()
140
159
    try:
141
 
        return unbound(%(passed_params)s)
142
 
    finally:
 
160
        result = unbound(%(passed_params)s)
 
161
    except:
 
162
        import sys
 
163
        exc_info = sys.exc_info()
 
164
        try:
 
165
            self.unlock()
 
166
        finally:
 
167
            raise exc_info[0], exc_info[1], exc_info[2]
 
168
    else:
143
169
        self.unlock()
 
170
        return result
144
171
write_locked = %(name)s_write_locked
145
172
"""
146
173
    params, passed_params = _get_parameters(unbound)
162
189
    def write_locked(self, *args, **kwargs):
163
190
        self.lock_write()
164
191
        try:
165
 
            return unbound(self, *args, **kwargs)
166
 
        finally:
 
192
            result = unbound(self, *args, **kwargs)
 
193
        except:
 
194
            exc_info = sys.exc_info()
 
195
            try:
 
196
                self.unlock()
 
197
            finally:
 
198
                raise exc_info[0], exc_info[1], exc_info[2]
 
199
        else:
167
200
            self.unlock()
 
201
            return result
168
202
    write_locked.__doc__ = unbound.__doc__
169
203
    write_locked.__name__ = unbound.__name__
170
204
    return write_locked