summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRobey Pointer <robey@lag.net>2004-09-25 21:32:53 +0000
committerRobey Pointer <robey@lag.net>2004-09-25 21:32:53 +0000
commit3e644a94f17fbf0a683bf298f865cd62694add19 (patch)
tree3b67d3361de77ca3c4a5bccbf6c06b65b516a0f5
parent12287b3e0e95664a383902b69a0881775b550feb (diff)
[project @ Arch-1:robey@lag.net--2003-public%secsh--dev--1.0--patch-88]
add Message.rewind() add rewind() method to Message, which just resets the pointer so you can start reading from the beginning again. this is useful for some tests.
-rw-r--r--paramiko/message.py9
-rw-r--r--tests/test_message.py4
2 files changed, 12 insertions, 1 deletions
diff --git a/paramiko/message.py b/paramiko/message.py
index f46ab3d0..3ebd4f00 100644
--- a/paramiko/message.py
+++ b/paramiko/message.py
@@ -60,7 +60,14 @@ class Message (object):
@rtype: string
"""
return 'paramiko.Message(' + repr(self.packet) + ')'
-
+
+ def rewind(self):
+ """
+ Rewind the message to the beginning as if no items had been parsed
+ out of it yet.
+ """
+ self.idx = 0
+
def get_remainder(self):
"""
Return the bytes of this Message that haven't already been parsed and
diff --git a/tests/test_message.py b/tests/test_message.py
index 9e4f2a42..218ab529 100644
--- a/tests/test_message.py
+++ b/tests/test_message.py
@@ -95,4 +95,8 @@ class MessageTest (unittest.TestCase):
self.assertEquals(msg.get_mpint(), 0x1122334455L)
self.assertEquals(msg.get_so_far(), self.__d[:13])
self.assertEquals(msg.get_remainder(), self.__d[13:])
+ msg.rewind()
+ self.assertEquals(msg.get_int(), 5)
+ self.assertEquals(msg.get_so_far(), self.__d[:4])
+ self.assertEquals(msg.get_remainder(), self.__d[4:])