1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
10 class Gettable(object):
11 '''Allows a Future to accept a callable as a delegate. Wraps |f| in a .Get
12 interface required by Future.
14 def __init__(self
, f
, *args
):
15 self
._g
= lambda: f(*args
)
21 '''Stores a value, error, or delegate to be used later.
23 def __init__(self
, value
=_no_value
, delegate
=None, exc_info
=None):
25 self
._delegate
= delegate
26 self
._exc
_info
= exc_info
27 if (self
._value
is _no_value
and
28 self
._delegate
is None and
29 self
._exc
_info
is None):
30 raise ValueError('Must have either a value, error, or delegate.')
33 '''Gets the stored value, error, or delegate contents.
35 if self
._value
is not _no_value
:
37 if self
._exc
_info
is not None:
40 self
._value
= self
._delegate
.Get()
43 self
._exc
_info
= sys
.exc_info()
47 exc_info
= self
._exc
_info
48 raise exc_info
[0], exc_info
[1], exc_info
[2]