#!/bin/env python
# -*- PYTHON -*-

#-----------------------------------------------------------------------------#
#		       Copyright (c) John F. Croix, 1997
#
#			      All Rights Reserved
#
# Permission to use, copy, modify, and distribute this software and its
# documentation for any non-commercial or internal-use-only purpose and without
# fee is hereby granted, provided that the above copyright notice appears in
# all copies and that both the copyright notice and this permission notice
# appear in supporting documentation, and all changes or alterations to the
# software and documentation are clearly documented.  Resale of any part of
# this software or documentation is prohibited without a license.  Licenses may
# be obtained by contacting the author, John F. Croix, at John.Croix@amd.com or
# journeyman@mail.utexas.edu.
#
# THE AUTHOR, JOHN F. CROIX, DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
# SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, INDIRECT OR
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
# DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
# TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OF PERFORMANCE
# OF THIS SOFTWARE.
#-----------------------------------------------------------------------------#

#-----------------------------------------------------------------------------#
# Test the ability of the module to handle the Pipe "FULL_BUFFER" condition #
#-----------------------------------------------------------------------------#


import pipe
import sys


class GlobalTimeout(pipe.TIMEOUT):
    def __init__(Self):
	pipe.TIMEOUT.__init__(Self)

    def Apply(Self, PipeProcess, BeforeMatch, MatchingText):
	pipe.TIMEOUT.Apply( Self, PipeProcess, BeforeMatch, MatchingText )
	print "Error --> Process has timed out!  Exiting."
	sys.exit( 1 )


#
# Start DC Shell.  Wait for it to initialize.
#


User = pipe.Pipe()
User.MatchAfter( GlobalTimeout() )
User.SetTimeout( 10 )
print 'Please type in "quit" in the next 10 seconds to avoid a timeout.'
User.Open( sys.stdin )

QuitPattern = pipe.RegexNocasePattern( "quit" )
User.Match( QuitPattern )
if QuitPattern.Matched():
    print "\n\n\nThank you.  Shutting down."

