From 3e644a94f17fbf0a683bf298f865cd62694add19 Mon Sep 17 00:00:00 2001 From: Robey Pointer Date: Sat, 25 Sep 2004 21:32:53 +0000 Subject: [PATCH] [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. --- paramiko/message.py | 9 ++++++++- tests/test_message.py | 4 ++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/paramiko/message.py b/paramiko/message.py index f46ab3d..3ebd4f0 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 9e4f2a4..218ab52 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:])