Browse Source

#2 fix python telnet script

Guillermo Espinoza 6 năm trước cách đây
mục cha
commit
a78ae8a4a4
1 tập tin đã thay đổi với 18 bổ sung12 xóa
  1. 18 12
      ObjectTelnet.py

+ 18 - 12
ObjectTelnet.py

@@ -1,3 +1,4 @@
+import types
 import errno
 import sys
 import telnetlib
@@ -192,18 +193,23 @@ class ObjectTelnet(ObjectConnection):
         """
         iteration = 0
         position = -1
+        if isinstance(expected, types.StringType):
+            expected = [expected]
         while iteration < 6:
-            (i, obj, all_data) = self.tn.expect(expected, 10)
-            nc = 1
-            for ch in expected:
-                if ch in all_data:
-                    position = nc
-                    break
-                nc += 1
-            if position == -1:
-                iteration += 1
-            else:
+            try:
+                (i, obj, all_data) = self.tn.expect(expected, 10)
+                nc = 1
+                for ch in expected:
+                    if ch in all_data:
+                        position = nc
+                        break
+                    nc += 1
+                if position == -1:
+                    iteration += 1
+                else:
+                    iteration = 6
+                    print(str(all_data))
+                    self.all_data = self.all_data + str(all_data)
+            except EOFError as error:
                 iteration = 6
-                print(str(all_data))
-                self.all_data = self.all_data + str(all_data)
         return position