__init__.py 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. '''Pexpect is a Python module for spawning child applications and controlling
  2. them automatically. Pexpect can be used for automating interactive applications
  3. such as ssh, ftp, passwd, telnet, etc. It can be used to a automate setup
  4. scripts for duplicating software package installations on different servers. It
  5. can be used for automated software testing. Pexpect is in the spirit of Don
  6. Libes' Expect, but Pexpect is pure Python. Other Expect-like modules for Python
  7. require TCL and Expect or require C extensions to be compiled. Pexpect does not
  8. use C, Expect, or TCL extensions. It should work on any platform that supports
  9. the standard Python pty module. The Pexpect interface focuses on ease of use so
  10. that simple tasks are easy.
  11. There are two main interfaces to the Pexpect system; these are the function,
  12. run() and the class, spawn. The spawn class is more powerful. The run()
  13. function is simpler than spawn, and is good for quickly calling program. When
  14. you call the run() function it executes a given program and then returns the
  15. output. This is a handy replacement for os.system().
  16. For example::
  17. pexpect.run('ls -la')
  18. The spawn class is the more powerful interface to the Pexpect system. You can
  19. use this to spawn a child program then interact with it by sending input and
  20. expecting responses (waiting for patterns in the child's output).
  21. For example::
  22. child = pexpect.spawn('scp foo user@example.com:.')
  23. child.expect('Password:')
  24. child.sendline(mypassword)
  25. This works even for commands that ask for passwords or other input outside of
  26. the normal stdio streams. For example, ssh reads input directly from the TTY
  27. device which bypasses stdin.
  28. Credits: Noah Spurrier, Richard Holden, Marco Molteni, Kimberley Burchett,
  29. Robert Stone, Hartmut Goebel, Chad Schroeder, Erick Tryzelaar, Dave Kirby, Ids
  30. vander Molen, George Todd, Noel Taylor, Nicolas D. Cesar, Alexander Gattin,
  31. Jacques-Etienne Baudoux, Geoffrey Marshall, Francisco Lourenco, Glen Mabey,
  32. Karthik Gurusamy, Fernando Perez, Corey Minyard, Jon Cohen, Guillaume
  33. Chazarain, Andrew Ryan, Nick Craig-Wood, Andrew Stone, Jorgen Grahn, John
  34. Spiegel, Jan Grant, and Shane Kerr. Let me know if I forgot anyone.
  35. Pexpect is free, open source, and all that good stuff.
  36. http://pexpect.sourceforge.net/
  37. PEXPECT LICENSE
  38. This license is approved by the OSI and FSF as GPL-compatible.
  39. http://opensource.org/licenses/isc-license.txt
  40. Copyright (c) 2012, Noah Spurrier <noah@noah.org>
  41. PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY
  42. PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE
  43. COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES.
  44. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  45. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  46. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  47. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  48. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  49. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  50. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  51. '''
  52. import sys
  53. PY3 = (sys.version_info[0] >= 3)
  54. from .exceptions import ExceptionPexpect, EOF, TIMEOUT
  55. from .utils import split_command_line, which, is_executable_file
  56. from .expect import Expecter, searcher_re, searcher_string
  57. if sys.platform != 'win32':
  58. # On Unix, these are available at the top level for backwards compatibility
  59. from .pty_spawn import spawn, spawnu
  60. from .run import run, runu
  61. __version__ = '4.2.1'
  62. __revision__ = ''
  63. __all__ = ['ExceptionPexpect', 'EOF', 'TIMEOUT', 'spawn', 'spawnu', 'run', 'runu',
  64. 'which', 'split_command_line', '__version__', '__revision__']
  65. # vim: set shiftround expandtab tabstop=4 shiftwidth=4 ft=python autoindent :