Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pexpect/__init__.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-04-20 06:09 +0000

1'''Pexpect is a Python module for spawning child applications and controlling 

2them automatically. Pexpect can be used for automating interactive applications 

3such as ssh, ftp, passwd, telnet, etc. It can be used to automate setup 

4scripts for duplicating software package installations on different servers. It 

5can be used for automated software testing. Pexpect is in the spirit of Don 

6Libes' Expect, but Pexpect is pure Python. Other Expect-like modules for Python 

7require TCL and Expect or require C extensions to be compiled. Pexpect does not 

8use C, Expect, or TCL extensions. It should work on any platform that supports 

9the standard Python pty module. The Pexpect interface focuses on ease of use so 

10that simple tasks are easy. 

11 

12There are two main interfaces to the Pexpect system; these are the function, 

13run() and the class, spawn. The spawn class is more powerful. The run() 

14function is simpler than spawn, and is good for quickly calling program. When 

15you call the run() function it executes a given program and then returns the 

16output. This is a handy replacement for os.system(). 

17 

18For example:: 

19 

20 pexpect.run('ls -la') 

21 

22The spawn class is the more powerful interface to the Pexpect system. You can 

23use this to spawn a child program then interact with it by sending input and 

24expecting responses (waiting for patterns in the child's output). 

25 

26For example:: 

27 

28 child = pexpect.spawn('scp foo user@example.com:.') 

29 child.expect('Password:') 

30 child.sendline(mypassword) 

31 

32Context manager can be used for the spawn() function:: 

33 

34 with pexpect.spawn('scp foo user@example.com:.') as child: 

35 child.expect('Password:') 

36 child.sendline(mypassword) 

37 

38This works even for commands that ask for passwords or other input outside of 

39the normal stdio streams. For example, ssh reads input directly from the TTY 

40device which bypasses stdin. 

41 

42Credits: Noah Spurrier, Richard Holden, Marco Molteni, Kimberley Burchett, 

43Robert Stone, Hartmut Goebel, Chad Schroeder, Erick Tryzelaar, Dave Kirby, Ids 

44vander Molen, George Todd, Noel Taylor, Nicolas D. Cesar, Alexander Gattin, 

45Jacques-Etienne Baudoux, Geoffrey Marshall, Francisco Lourenco, Glen Mabey, 

46Karthik Gurusamy, Fernando Perez, Corey Minyard, Jon Cohen, Guillaume 

47Chazarain, Andrew Ryan, Nick Craig-Wood, Andrew Stone, Jorgen Grahn, John 

48Spiegel, Jan Grant, and Shane Kerr. Let me know if I forgot anyone. 

49 

50Pexpect is free, open source, and all that good stuff. 

51http://pexpect.sourceforge.net/ 

52 

53PEXPECT LICENSE 

54 

55 This license is approved by the OSI and FSF as GPL-compatible. 

56 http://opensource.org/licenses/isc-license.txt 

57 

58 Copyright (c) 2012, Noah Spurrier <noah@noah.org> 

59 PERMISSION TO USE, COPY, MODIFY, AND/OR DISTRIBUTE THIS SOFTWARE FOR ANY 

60 PURPOSE WITH OR WITHOUT FEE IS HEREBY GRANTED, PROVIDED THAT THE ABOVE 

61 COPYRIGHT NOTICE AND THIS PERMISSION NOTICE APPEAR IN ALL COPIES. 

62 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 

63 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 

64 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 

65 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 

66 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 

67 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 

68 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 

69 

70''' 

71 

72import sys 

73PY3 = (sys.version_info[0] >= 3) 

74 

75from .exceptions import ExceptionPexpect, EOF, TIMEOUT 

76from .utils import split_command_line, which, is_executable_file 

77from .expect import Expecter, searcher_re, searcher_string 

78 

79if sys.platform != 'win32': 

80 # On Unix, these are available at the top level for backwards compatibility 

81 from .pty_spawn import spawn, spawnu 

82 from .run import run, runu 

83 

84__version__ = '4.9.0' 

85__revision__ = '' 

86__all__ = ['ExceptionPexpect', 'EOF', 'TIMEOUT', 'spawn', 'spawnu', 'run', 'runu', 

87 'which', 'split_command_line', '__version__', '__revision__'] 

88 

89 

90 

91# vim: set shiftround expandtab tabstop=4 shiftwidth=4 ft=python autoindent :