# HG changeset patch # User Sebastian Ramacher # Date 1327774845 -3600 # Node ID 2ba3ea8f38cf63078d3846d9a421374637131bbc # Parent 1f8c00a6dd68be94af669548066b2cde592b2930 Check if twisted is available and report and error if that's not the case. diff -r 1f8c00a6dd68be94af669548066b2cde592b2930 -r 2ba3ea8f38cf63078d3846d9a421374637131bbc bpython/urwid.py --- a/bpython/urwid.py Sat Jan 28 19:16:53 2012 +0100 +++ b/bpython/urwid.py Sat Jan 28 19:20:45 2012 +0100 @@ -1012,10 +1012,14 @@ ])) if options.help_reactors: - from twisted.application import reactors - # Stolen from twisted.application.app (twistd). - for r in reactors.getReactorTypes(): - print ' %-4s\t%s' % (r.shortName, r.description) + try: + from twisted.application import reactors + # Stolen from twisted.application.app (twistd). + for r in reactors.getReactorTypes(): + print ' %-4s\t%s' % (r.shortName, r.description) + except ImportError: + sys.stderr.write('No reactors are available. Please install ' + 'twisted for reactor support.') return palette = [ @@ -1030,7 +1034,12 @@ options.reactor = 'select' if options.reactor: - from twisted.application import reactors + try: + from twisted.application import reactors + except ImportError: + sys.stderr.write('No reactors are available. Please install ' + 'twisted for reactor support.') + return try: # XXX why does this not just return the reactor it installed? reactor = reactors.installReactor(options.reactor) @@ -1053,8 +1062,14 @@ locals_ = main_mod.__dict__ if options.plugin: - from twisted import plugin - from twisted.application import service + try: + from twisted import plugin + from twisted.application import service + except ImportError: + sys.stderr.write('No twisted plugins are available. Please install ' + 'twisted for twisted plugin support.') + return + for plug in plugin.getPlugins(service.IServiceMaker): if plug.tapname == options.plugin: break