Re: Issue 2: TextFSM should leave file pointer at top of template file. (issue4560043)

16 views
Skip to first unread message

ha...@google.com

unread,
Jun 3, 2011, 12:48:49 AM6/3/11
to jd...@google.com, bbu...@google.com, textf...@googlegroups.com, re...@codereview.appspotmail.com
Reviewers: jdoak_google.com, bbuxton,


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()


bbu...@google.com

unread,
Jun 3, 2011, 4:00:16 AM6/3/11
to ha...@google.com, jd...@google.com, textf...@googlegroups.com, re...@codereview.appspotmail.com
Reply all
Reply to author
Forward
0 new messages