>>> try:
... while c.input() == None:
... if i > 4:
-... print >> _sys.stderr, 'testing error output'
-... raise TestException, 'testing error exception'
-... c.output('sleeping %d\\n' % i)
+... size = _sys.stderr.write('testing error output\\n')
+... raise TestException('testing error exception')
+... c.output('sleeping {}\\n'.format(i))
... _test_sleep()
... i += 1
-... raise Exception, '_test_error_catching() failed!'
-... except TestException, e:
-... print 'caught exception:', e
+... raise Exception('_test_error_catching() failed!')
+... except TestException as e:
+... print('caught exception: {}'.format(e))
... finally:
... c.cleanup()
sleeping 0
import curses.ascii as _curses_ascii
from time import sleep as _sleep
import sys as _sys
-import StringIO as _StringIO
+try: # Python 3
+ from io import StringIO as _StringIO
+except ImportError: # Python 2
+ from StringIO import StringIO as _StringIO
__version__ = '0.2'
self.last = None # last byte number read
self.lasta = None # last as an ASCII character
if test_mode == True:
- print prompt
+ print(prompt)
self.i = 0
return None
# redirect stderr to a file, because exiting curses mode clears
# any error messages that had been printed to the screen
- _sys.stderr = _StringIO.StringIO()
+ _sys.stderr = _StringIO()
# initialize raw curses mode
self._active = True
self.stdscr = _curses.initscr()
contents = _sys.stderr.getvalue()
_sys.stderr = _sys.__stderr__
if len(contents) > 0:
- print >> _sys.stderr, contents
+ _sys.stderr.write(contents)
self._active = False
def input(self):
def _output(self, string):
if self.test_mode == True:
- print string,
+ _sys.stdout.write(string)
return None
#y,x = self.stdscr.getyx()
self.stdscr.addstr(string)
i_max = 20
try:
while c.input() == None:
- c.output('%d/%d (sleeping)\n' % (i, i_max))
+ c.output('{}/{} (sleeping)\n'.format(i, i_max))
_test_sleep()
if i >= i_max:
- raise Exception, "you didn't press a key!"
+ raise Exception("you didn't press a key!")
i += 1
finally:
c.cleanup()
url = 'http://blog.tremily.us/post/{}/'.format(package_name),
download_url = 'http://git.tremily.us/?p={}.git/a=snapshot;h=v{};sf=tgz'.format(
package_name, __version__),
-
license = 'GNU GPL v3+',
platforms = ['all'],
description = __doc__,
'Operating System :: OS Independent',
'License :: OSI Approved :: GNU General Public License (GPL)',
'Programming Language :: Python',
+ 'Programming Language :: Python :: 2',
+ 'Programming Language :: Python :: 2.7',
+ 'Programming Language :: Python :: 3',
+ 'Programming Language :: Python :: 3.2',
+ 'Programming Language :: Python :: 3.3',
'Topic :: Software Development :: Libraries :: Python Modules',
],
py_modules = ['curses_check_for_keypress'],