Run the given function under the given contextmanager, simulating the behavior of 'with' to support older Python versions. This is not necessary anymore as we have placed 2.6 as minimum Python version, however some tests are still using this structure.
(ctx, fn, *arg, **kw)
| 154 | |
| 155 | |
| 156 | def run_as_contextmanager(ctx, fn, *arg, **kw): |
| 157 | """Run the given function under the given contextmanager, |
| 158 | simulating the behavior of 'with' to support older |
| 159 | Python versions. |
| 160 | |
| 161 | This is not necessary anymore as we have placed 2.6 |
| 162 | as minimum Python version, however some tests are still using |
| 163 | this structure. |
| 164 | |
| 165 | """ |
| 166 | |
| 167 | obj = ctx.__enter__() |
| 168 | try: |
| 169 | result = fn(obj, *arg, **kw) |
| 170 | ctx.__exit__(None, None, None) |
| 171 | return result |
| 172 | except: |
| 173 | exc_info = sys.exc_info() |
| 174 | raise_ = ctx.__exit__(*exc_info) |
| 175 | if not raise_: |
| 176 | raise |
| 177 | else: |
| 178 | return raise_ |
| 179 | |
| 180 | |
| 181 | def rowset(results): |