#   PsychePostProcessor.py
#       base class for all python postprocessor objects

class PsychePostProcessor:
    """
        all this class does is allow derived classes to set a result,
        or share the stored result.
    """
    _result     =   ''
    
    def set_result(self, result):
        self._result    =   result    

    def append_to_result(self, result):
        self._result    =   self._result + result

    def prepend_to_result(self, result):
        self._result    =   result + self._result

    def get_result(self):
        return self._result

class PsycheInteractivePP(PsychePostProcessor):
    """
        for an interactive object, setup_pipes must be called to specify
        the input and output pipes.  read_input will grab the next availible
        input, and send_output sends whatever was stored by set_result.
    """
    def setup_pipes( self, input, output ):
        self.__input    =   input
        self.__output   =   output

    def read_input( self ):
        return self.__input.getline()

    def send_output( self ):
        self.__output( self._result )
        
################################################################################
if __name__ == '__main__':
    X   =   'this is a sample string.'
    print '>> X = %s'%X
    print ">> p = PsychePostProcessor()"
    p   =   PsychePostProcessor()
    
    print ">> p.set_result(X)"
    p.set_result(X)
    
    print ">> p.get_result(X)"
    print p.get_result()
    
    print ">> p.prepend_to_result('prepend')"
    p.prepend_to_result('prepend ')
    
    print ">> p.get_result(X)"
    print p.get_result()
    
    print ">> p.append_to_result('append')"
    p.append_to_result(' append')
    
    print ">> p.get_result(X)"
    print p.get_result()