http://codereview.appspot.com/4560043/diff/1/textfsm.py
File textfsm.py (right):
http://codereview.appspot.com/4560043/diff/1/textfsm.py#newcode529
textfsm.py:529: except TextFSMTemplateError, error:
On 2011/05/26 05:09:16, bbuxton wrote:
> finally? I think it's reasonable to change to or assume python > 2.4.
> Failing that, line 531 just needs to be "raise" (this will re-raise
the outer
> exception).
Done.
Please review this at http://codereview.appspot.com/4560043/
Affected files:
M textfsm.py
M textfsm_test.py
Index: textfsm_test.py
===================================================================
--- textfsm_test.py (revision 6)
+++ textfsm_test.py (working copy)
@@ -690,6 +690,18 @@
result = t.ParseText(data)
self.failUnlessEqual(str(result), "[['f'], ['fo'], ['foo']]")
+ def testReEnteringState(sefl):
+ """Issue 2. TextFSM should leave file pointer at top of template
file."""
+ tplt = 'Value boo (.*)\n\nStart\n ^$boo -> Next Stop\n\nStop\n
^abc\n'
+ output_text = 'one\ntwo'
+ tmpl_file = cStringIO.StringIO(tplt)
+
+ t = textfsm.TextFSM(tmpl_file)
+ t.ParseText(output_text)
+ t = textfsm.TextFSM(tmpl_file)
+ t.ParseText(output_text)
+
+
if __name__ == '__main__':
unittest.main()
Index: textfsm.py
===================================================================
--- textfsm.py (revision 6)
+++ textfsm.py (working copy)
@@ -522,7 +522,11 @@
self._cur_state_name = None
# Read and parse FSM definition.
- self._Parse(template)
+ # Restore the file pointer once done.
+ try:
+ self._Parse(template)
+ finally:
+ template.seek(0)
# Initialise starting data.
self.Reset()