Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2013-2015 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 from __future__ import absolute_import | 5 from __future__ import absolute_import |
| 6 import contextlib | 6 import contextlib |
| 7 import keyword | 7 import keyword |
| 8 import re | 8 import re |
| 9 import types | 9 import types |
| 10 | 10 |
| 11 from functools import wraps | 11 from functools import wraps |
| (...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 227 with context({'aggregated_result': None, 'ran_step': [False]}): | 227 with context({'aggregated_result': None, 'ran_step': [False]}): |
| 228 try: | 228 try: |
| 229 ret = func(*a, **kw) | 229 ret = func(*a, **kw) |
| 230 if not _STEP_CONTEXT.get('ran_step', [False])[0]: | 230 if not _STEP_CONTEXT.get('ran_step', [False])[0]: |
| 231 return ret | 231 return ret |
| 232 agg.add_success(ret) | 232 agg.add_success(ret) |
| 233 return DeferredResult(ret, None) | 233 return DeferredResult(ret, None) |
| 234 except StepFailure as ex: | 234 except StepFailure as ex: |
| 235 agg.add_failure(ex) | 235 agg.add_failure(ex) |
| 236 return DeferredResult(None, ex) | 236 return DeferredResult(None, ex) |
| 237 _inner.__original = func | |
|
martiniss
2016/04/25 23:44:19
Umm. Is this legit? It works, but.....
iannucci
2016/05/28 00:38:17
it's as legit as anything else :/. Python's gone b
| |
| 237 return _inner | 238 return _inner |
| 238 | 239 |
| 239 | 240 |
| 240 def composite_step(func): | 241 def composite_step(func): |
| 241 """A decorator which makes this step act as a single step, for the purposes of | 242 """A decorator which makes this step act as a single step, for the purposes of |
| 242 the defer_results function. | 243 the defer_results function. |
| 243 | 244 |
| 244 This means that this function will not quit during the middle of its execution | 245 This means that this function will not quit during the middle of its execution |
| 245 because of a StepFailure, if there is an aggregator active. | 246 because of a StepFailure, if there is an aggregator active. |
| 246 | 247 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 264 # written in the same style (e.g. with exceptions) no matter how func is | 265 # written in the same style (e.g. with exceptions) no matter how func is |
| 265 # being called. | 266 # being called. |
| 266 with context({'aggregated_result': None}): | 267 with context({'aggregated_result': None}): |
| 267 try: | 268 try: |
| 268 ret = func(*a, **kw) | 269 ret = func(*a, **kw) |
| 269 agg.add_success(ret) | 270 agg.add_success(ret) |
| 270 return DeferredResult(ret, None) | 271 return DeferredResult(ret, None) |
| 271 except StepFailure as ex: | 272 except StepFailure as ex: |
| 272 agg.add_failure(ex) | 273 agg.add_failure(ex) |
| 273 return DeferredResult(None, ex) | 274 return DeferredResult(None, ex) |
| 275 _inner.__original = func | |
| 274 return _inner | 276 return _inner |
| 275 | 277 |
| 276 | 278 |
| 277 @contextlib.contextmanager | 279 @contextlib.contextmanager |
| 278 def defer_results(): | 280 def defer_results(): |
| 279 """ | 281 """ |
| 280 Use this to defer step results in your code. All steps which would previously | 282 Use this to defer step results in your code. All steps which would previously |
| 281 return a result or throw an exception will instead return a DeferredResult. | 283 return a result or throw an exception will instead return a DeferredResult. |
| 282 | 284 |
| 283 Any exceptions which were thrown during execution will be thrown when either: | 285 Any exceptions which were thrown during execution will be thrown when either: |
| (...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 636 """ | 638 """ |
| 637 Gets the BoundProperty version of this Property. Requires a name. | 639 Gets the BoundProperty version of this Property. Requires a name. |
| 638 """ | 640 """ |
| 639 return BoundProperty( | 641 return BoundProperty( |
| 640 self._default, self.help, self.kind, name, property_type, module, | 642 self._default, self.help, self.kind, name, property_type, module, |
| 641 self.param_name) | 643 self.param_name) |
| 642 | 644 |
| 643 class UndefinedPropertyException(TypeError): | 645 class UndefinedPropertyException(TypeError): |
| 644 pass | 646 pass |
| 645 | 647 |
| OLD | NEW |