From a2bda099219267b1c2b91a99c084084f531254f3 Mon Sep 17 00:00:00 2001 From: noah Date: Tue, 2 Mar 2004 09:33:36 +0000 Subject: This is evil! git-svn-id: http://pexpect.svn.sourceforge.net/svnroot/pexpect/trunk@216 656d521f-e311-0410-88e0-e7920216d269 --- pexpect/examples/bd_client_web.py | 75 ++++++++++++++++++++++++++++----------- pexpect/examples/bd_serv.py | 14 ++++++-- 2 files changed, 67 insertions(+), 22 deletions(-) diff --git a/pexpect/examples/bd_client_web.py b/pexpect/examples/bd_client_web.py index 80edf11..5b5e9c6 100755 --- a/pexpect/examples/bd_client_web.py +++ b/pexpect/examples/bd_client_web.py @@ -12,39 +12,74 @@ import socket ROOTPATH="/tmp" -def page (url, result = ''): +def page (result = ''): """Return the main form""" return """ Og. - + + + +
 %s
 
-
-
- - -
- - - - """ % (result, url) +
+
+ + +
+ + + """ % (result) def bd_client (command, host='localhost', port = 1666): + HOST = 'localhost' # The remote host + PORT = 1666 # The same port as used by the server + s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + s.connect((HOST, PORT)) + s.send(command) + data = s.recv(1024) + s.close() + return data + + #fout = file ('/tmp/log2','w') + #fout.write (command) + #fout.write ('\n') s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((host, port)) s.send(command) data = s.recv(1024) + #fout.write (data) + #fout.write ('\n') s.close() + #fout.close() return data -def link (matchobject): - """Used in re.sub calls to replace a matched object with an HTML link.""" - path = matchobject.group(0) - l = "%s" % \ - (ROOTPATH+"/"+path, ROOTPATH+"/"+path, path) - return l +#def link (matchobject): +# """Used in re.sub calls to replace a matched object with an HTML link.""" +# path = matchobject.group(0) +# l = "%s" % \ +# (ROOTPATH+"/"+path, ROOTPATH+"/"+path, path) +# return l def escape_shell_meta_chars(s): """Escape shell meta characters. This is done for security.""" @@ -61,7 +96,7 @@ def escape_shell_meta_chars(s): s = string.replace(s, ">", "\\>",) return s -sys.path.insert (0,"/var/www/cgi-bin") +sys.path.insert (0,"/usr/local/apache/cgi-bin") sys.stderr = sys.stdout print "Content-type: text/html" @@ -72,9 +107,9 @@ try: if form.has_key("command"): command = form["command"].value result = bd_client (command) - print page('bd_client_web.py', result) + print page(result) else: - print page('bd_client_web.py') + print page() except: print "\n\n
"
diff --git a/pexpect/examples/bd_serv.py b/pexpect/examples/bd_serv.py
index 64477e7..260a5d6 100755
--- a/pexpect/examples/bd_serv.py
+++ b/pexpect/examples/bd_serv.py
@@ -1,8 +1,11 @@
 #!/usr/bin/env python
 import socket, pexpect
+import time
 
 p = pexpect.spawn ('bash')
-p.expect ('# ')
+time.sleep (0.1)
+p.expect ('\$')
+time.sleep (0.1)
 
 HOST = ''                 # Symbolic name meaning the local host
 PORT = 1666               # Arbitrary non-privileged port
@@ -15,11 +18,18 @@ while 1:
     conn, addr = s.accept()
     print 'Connected by', addr
     data = conn.recv(1024)
+    print 'RECEIVED:'
+    print data
 #    if not data:
 #        break
+    time.sleep (0.1)
     p.sendline (data)
-    p.expect ('# ')
+    time.sleep (0.1)
+    p.expect ('\$')
+    time.sleep (0.1)
     response = p.before + p.after
+    print 'RESPONSE:'
+    print response
     conn.send(response)
     
 conn.close()
-- 
cgit v1.2.1