summaryrefslogtreecommitdiff
path: root/pexpect/FSM.py
diff options
context:
space:
mode:
authorNoah Spurrier <noah@squaretrade.com>2012-10-25 16:03:06 -0700
committerNoah Spurrier <noah@squaretrade.com>2012-10-25 16:03:06 -0700
commit1ebbd81cb88cf6d23e77168df0e10b81362d1822 (patch)
treed8f2fcabbb28c56ee35bf80fc8ee48840450dd48 /pexpect/FSM.py
parentb5dacf63d8adf090db918e3016ac1450c0f80d33 (diff)
downloadpexpect-1ebbd81cb88cf6d23e77168df0e10b81362d1822.tar.gz
Added backward compatability back to Python 2.2.
I removed some of the changes I was working on for Python3 (mostly exception systax). The reason for doing this is that it's impossible to maintain a single source file that supports both Python2 and Python3, so Python3 is never going to happen in this code anyway.** This is one of the most annoying things about Python3. Maybe I'll create a build script that strips out the Python3 crap so I can at least maintain one set of source files that can be retargeted to Python2 or Python3 as a pre-install step. ** This may not be strictly true, but short of adding conditional tests and exceptions to handle run-time errors I can't think of a clean way to do this.
Diffstat (limited to 'pexpect/FSM.py')
-rw-r--r--pexpect/FSM.py21
1 files changed, 9 insertions, 12 deletions
diff --git a/pexpect/FSM.py b/pexpect/FSM.py
index a1ebaff..ad22880 100644
--- a/pexpect/FSM.py
+++ b/pexpect/FSM.py
@@ -264,7 +264,11 @@ class FSM:
# 2003
##############################################################################
-import sys, os, traceback, optparse, time, string
+import sys
+import os
+import traceback
+import time
+import string
#
# These define the actions.
@@ -308,7 +312,7 @@ def main():
defined. Note that states are strings (such as 'INIT'). This is not
necessary, but it makes the example easier to read. '''
- f = FSM ('INIT', []) # "memory" will be used as a stack.
+ f = FSM ('INIT', [])
f.set_default_transition (Error, 'INIT')
f.add_transition_any ('INIT', None, 'INIT')
f.add_transition ('=', 'INIT', DoEqual, 'INIT')
@@ -326,21 +330,14 @@ def main():
inputstr = raw_input ('> ')
f.process_list(inputstr)
+
if __name__ == '__main__':
try:
- start_time = time.time()
- parser = optparse.OptionParser(formatter=optparse.TitledHelpFormatter(), usage=globals()['__doc__'], version='$Id: FSM.py 533 2012-10-20 02:19:33Z noah $')
- parser.add_option ('-v', '--verbose', action='store_true', default=False, help='verbose output')
- (options, args) = parser.parse_args()
- if options.verbose: print time.asctime()
main()
- if options.verbose: print time.asctime()
- if options.verbose: print 'TOTAL TIME IN MINUTES:',
- if options.verbose: print (time.time() - start_time) / 60.0
sys.exit(0)
- except KeyboardInterrupt, e: # Ctrl-C
+ except KeyboardInterrupt, e: # Ctrl-C
raise e
- except SystemExit, e: # sys.exit()
+ except SystemExit, e: # sys.exit()
raise e
except Exception, e:
print 'ERROR, UNEXPECTED EXCEPTION'