def __enter__(self):
     if isinstance(self.orig, dict):
         self.getter, self.setter, self.deleter = dictget, dictset, dictdel
     else:
         self.getter, self.setter, self.deleter = getattr, setattr, delattr
     self.diff = change(self.orig, self.getter, self.setter, self.deleter, **self.attrs)
     return self
Exemple #2
0
def alter(obj, **changes):
    """
    Alternative API entry: a two step altering procedure. Same  as
    `state`, but returns a function that will restore the changes at a
    later point.
    """
    diff = change(obj, **changes)

    def restoration():
        restore(obj, diff)

    return restoration
Exemple #3
0
def alter(obj, **changes):
    """
    Alternative API entry: a two step altering procedure. Same  as
    `state`, but returns a function that will restore the changes at a
    later point.
    """
    getter, setter, deleter = changers(obj)

    diff = change(obj, getter, setter, deleter, **changes)

    def restoration():
        restore(obj, diff, getter, setter, deleter)

    return restoration
Exemple #4
0
 def __enter__(self):
     self.diff = change(self.orig, **self.attrs)
     return self
Exemple #5
0
 def __enter__(self):
     self.getter, self.setter, self.deleter = changers(self.orig)
     self.diff = change(self.orig, self.getter,
                        self.setter, self.deleter, **self.attrs)
     return self