Package pike :: Module core :: Class Let
[hide private]
[frames] | no frames]

Class Let

source code

object --+
         |
        Let


A Let allows for temporarily storing passed arguments in the _settings
member of a target object for the duration of the contextmanager's scope

Implementation on a factory class

class MyThingFactory(object):
    def __init__(self):
        self._settings = {}
    def generate_thing(self):
        # do something here
        new_obj = Thing()
        for k,v in self._settings.iteritems():
            setattr(new_obj, k, v)
        return new_obj
    def let(self, **kwds):
        return Let(self, kwds)

Calling code that wants to temporarily customize the Thing objects that are
returned by the factory:

fac = MyThingFactory()
with fac.let(this="that", foo="bar"):
    a_thing = fac.generate_thing()
    self.assertEqual(a_thing.this, "that")

Instance Methods [hide private]
 
__init__(self, target, settings_dict)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
__enter__(self) source code
 
__exit__(self, exc_type, exc_val, exc_tb) source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, target, settings_dict)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)