# -*- coding: Latin-1 -*-

class Clay(object):
    def __init__(self, operations=None):
        if operations is None:
            operations = []
        self.operations = operations
    
    def __getattribute__(self, name):
        if name in ('fire', 'operations', '__call__'):
            return object.__getattribute__(self, name)
        else:
            self.operations.append(Clay([lambda o: getattr(o, name)]))
            return self.operations[-1]

    def __call__(self, *args, **kw):
        self.operations.append(Clay([lambda o: o(*args, **kw)]))
        return self.operations[-1]
    
    def __add__(self, other):
        self.operations.append(Clay([lambda o: o + other]))
        return self.operations[-1]
    
    def __radd__(self, other):
        print 'hi'
    
    def fire(self, obj):
        for c in self.operations:
            if isinstance(c, Clay):
                c.fire(obj)
            else:
                obj = c(obj)
        return obj

if __name__ == '__main__':
    c = Clay()
    c.append(5)
    c + [10]
    c.extend([3])
    d = c + ['hello']

    L = []
    L = c.fire(L)
    print L, d.fire(L)

    i = Clay()
    i = i + 5
    i = 10 / i
    print i.fire(2)

