Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

inputhook: further cleanups for stdin_ready()

 - split stdin_ready() in 3 platform specific functions and choose
   the appropriate one at import time
 - add docstrings for each of these
  • Loading branch information...
commit bbdb0ddc0e6493d870339acc432461b310f06d82 1 parent fa66348
@cboos authored
Showing with 21 additions and 12 deletions.
  1. +21 −12 IPython/lib/inputhook.py
View
33 IPython/lib/inputhook.py
@@ -37,18 +37,27 @@
# Utilities
#-----------------------------------------------------------------------------
-def stdin_ready():
- if os.name == 'posix':
- import select
- infds, outfds, erfds = select.select([sys.stdin],[],[],0)
- if infds:
- return True
- else:
- return False
- elif os.name == 'nt':
- import msvcrt
- return msvcrt.kbhit()
- return True # assume there's something so that we won't wait forever
+def _stdin_ready_posix():
+ """Return True if there's something to read on stdin (posix version)."""
+ infds, outfds, erfds = select.select([sys.stdin],[],[],0)
+ return bool(infds)
+
+def _stdin_ready_nt():
+ """Return True if there's something to read on stdin (nt version)."""
+ return msvcrt.kbhit()
+
+def _stdin_ready_other():
+ """Return True, assuming there's something to read on stdin."""
+ return True #
+
+if os.name == 'posix':
+ import select
+ stdin_ready = _stdin_ready_posix
+elif os.name == 'nt':
+ import msvcrt
+ stdin_ready = _stdin_ready_nt
+else:
+ stdin_ready = _stdin_ready_other
#-----------------------------------------------------------------------------
Please sign in to comment.
Something went wrong with that request. Please try again.