From a039d3d47deb77f0a544922d2c5f2be2104bf4ee Mon Sep 17 00:00:00 2001
From: Per Cederqvist <ceder@lysator.liu.se>
Date: Thu, 23 Oct 2003 23:22:04 +0000
Subject: [PATCH] Demo program for the Tcp class.

---
 demo/komtime.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)
 create mode 100644 demo/komtime.py

diff --git a/demo/komtime.py b/demo/komtime.py
new file mode 100644
index 0000000..235d22a
--- /dev/null
+++ b/demo/komtime.py
@@ -0,0 +1,48 @@
+# Connect to the LysKOM server at kom.lysator.liu.se, query it for the
+# current time, and print the result in ISO 8601 format.
+
+import pcl_expect.tcp
+import pcl_expect
+
+kom = pcl_expect.tcp.Tcp(("kom.lysator.liu.se", 4894))
+
+kom.send("A20Hpcl-expect time demo\n")
+
+x = pcl_expect.Controller()
+while x.loop():
+    if x.re(kom, "LysKOM\n"):
+        break
+
+kom.send("0 35\n")
+x = pcl_expect.Controller()
+while x.loop():
+    if x.re(kom, ("=0 "
+                  "(?P<sec>[0-9]*) "
+                  "(?P<min>[0-9]*) "
+                  "(?P<hour>[0-9]*) "
+                  "(?P<day>[0-9]*) "
+                  "(?P<month>[0-9]*) "
+                  "(?P<year>[0-9]*) "
+                  "(?P<wday>[0-9]*) "
+                  "(?P<yday>[0-9]*) "
+                  "(?P<isdst>[0-9]*)"
+                  "\n")):
+        year, month, day, hour, min, sec = [int(x) for x in kom.match.group(
+            "year", "month", "day", "hour", "min", "sec")]
+        print "%4d-%02d-%02d %02d:%02d:%02d (according to the server)" % (
+            1900+year, 1+month, day, hour, min, sec)
+        break
+
+kom.send("1 55 0\n")
+x = pcl_expect.Controller()
+while x.loop():
+    if x.re(kom, "=1\n"):
+        pass
+    elif x.re(kom, ":2 .*\n"):
+        pass
+    elif x.eof(kom):
+        if kom.consumed != "":
+            print "Unexpected output:", kom.consumed
+        break
+
+kom.close()
-- 
GitLab