~ubuntu-branches/debian/squeeze/pexpect/squeeze

« back to all changes in this revision

Viewing changes to doc/pxssh.html

  • Committer: Bazaar Package Importer
  • Author(s): Ganesan Rajagopal
  • Date: 2008-07-27 18:21:35 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080727182135-6bvn1enxhq51jckc
Tags: 2.3-1
* New upstream release.
* Fix lintian warnings:
      - Move debhelper to Build-Depends from Build-Depends-Indep.
      - Remove DH_COMPAT in debian/rules.
        - Added debian/pycompat.
        - Added #! line for examples/ssh_session.py.
* Updated standards version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
7
7
<tr bgcolor="#7799ee">
8
8
<td valign=bottom>&nbsp;<br>
9
 
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong>pxssh</strong></big></big> (version 2.1)</font></td
 
9
<font color="#ffffff" face="helvetica, arial">&nbsp;<br><big><big><strong>pxssh</strong></big></big> (version 2.3)</font></td
10
10
><td align=right valign=bottom
11
 
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/noah/documents/export/engineering/source/python/pexpect/trunk/pexpect/pxssh.py">/home/noah/documents/export/engineering/source/python/pexpect/trunk/pexpect/pxssh.py</a></font></td></tr></table>
12
 
    <p></p>
 
11
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/home/noah/pexpect/trunk/pexpect/pxssh.py">/home/noah/pexpect/trunk/pexpect/pxssh.py</a></font></td></tr></table>
 
12
    <p><tt>This&nbsp;class&nbsp;extends&nbsp;pexpect.<a href="pexpect.html#spawn">spawn</a>&nbsp;to&nbsp;specialize&nbsp;setting&nbsp;up&nbsp;SSH&nbsp;connections.<br>
 
13
This&nbsp;adds&nbsp;methods&nbsp;for&nbsp;login,&nbsp;logout,&nbsp;and&nbsp;expecting&nbsp;the&nbsp;shell&nbsp;prompt.<br>
 
14
&nbsp;<br>
 
15
$Id:&nbsp;<a href="#pxssh">pxssh</a>.py&nbsp;487&nbsp;2007-08-29&nbsp;22:33:29Z&nbsp;noah&nbsp;$</tt></p>
13
16
<p>
14
17
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
 
18
<tr bgcolor="#aa55cc">
 
19
<td colspan=3 valign=bottom>&nbsp;<br>
 
20
<font color="#fffff" face="helvetica, arial"><big><strong>Modules</strong></big></font></td></tr>
 
21
    
 
22
<tr><td bgcolor="#aa55cc"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
 
23
<td width="100%"><table width="100%" summary="list"><tr><td width="25%" valign=top><a href="pexpect.html">pexpect</a><br>
 
24
</td><td width="25%" valign=top><a href="time.html">time</a><br>
 
25
</td><td width="25%" valign=top></td><td width="25%" valign=top></td></tr></table></td></tr></table><p>
 
26
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
15
27
<tr bgcolor="#ee77aa">
16
28
<td colspan=3 valign=bottom>&nbsp;<br>
17
29
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
18
30
    
19
31
<tr><td bgcolor="#ee77aa"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
20
32
<td width="100%"><dl>
 
33
<dt><font face="helvetica, arial"><a href="pexpect.html#ExceptionPexpect">pexpect.ExceptionPexpect</a>(<a href="exceptions.html#Exception">exceptions.Exception</a>)
 
34
</font></dt><dd>
 
35
<dl>
 
36
<dt><font face="helvetica, arial"><a href="pxssh.html#ExceptionPxssh">ExceptionPxssh</a>
 
37
</font></dt></dl>
 
38
</dd>
21
39
<dt><font face="helvetica, arial"><a href="pexpect.html#spawn">pexpect.spawn</a>(<a href="__builtin__.html#object">__builtin__.object</a>)
22
40
</font></dt><dd>
23
41
<dl>
29
47
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
30
48
<tr bgcolor="#ffc8d8">
31
49
<td colspan=3 valign=bottom>&nbsp;<br>
 
50
<font color="#000000" face="helvetica, arial"><a name="ExceptionPxssh">class <strong>ExceptionPxssh</strong></a>(<a href="pexpect.html#ExceptionPexpect">pexpect.ExceptionPexpect</a>)</font></td></tr>
 
51
    
 
52
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
 
53
<td colspan=2><tt>Raised&nbsp;for&nbsp;<a href="#pxssh">pxssh</a>&nbsp;exceptions.<br>&nbsp;</tt></td></tr>
 
54
<tr><td>&nbsp;</td>
 
55
<td width="100%"><dl><dt>Method resolution order:</dt>
 
56
<dd><a href="pxssh.html#ExceptionPxssh">ExceptionPxssh</a></dd>
 
57
<dd><a href="pexpect.html#ExceptionPexpect">pexpect.ExceptionPexpect</a></dd>
 
58
<dd><a href="exceptions.html#Exception">exceptions.Exception</a></dd>
 
59
<dd><a href="exceptions.html#BaseException">exceptions.BaseException</a></dd>
 
60
<dd><a href="__builtin__.html#object">__builtin__.object</a></dd>
 
61
</dl>
 
62
<hr>
 
63
Methods inherited from <a href="pexpect.html#ExceptionPexpect">pexpect.ExceptionPexpect</a>:<br>
 
64
<dl><dt><a name="ExceptionPxssh-__init__"><strong>__init__</strong></a>(self, value)</dt></dl>
 
65
 
 
66
<dl><dt><a name="ExceptionPxssh-__str__"><strong>__str__</strong></a>(self)</dt></dl>
 
67
 
 
68
<dl><dt><a name="ExceptionPxssh-get_trace"><strong>get_trace</strong></a>(self)</dt><dd><tt>This&nbsp;returns&nbsp;an&nbsp;abbreviated&nbsp;stack&nbsp;trace&nbsp;with&nbsp;lines&nbsp;that&nbsp;only&nbsp;concern<br>
 
69
the&nbsp;caller.&nbsp;In&nbsp;other&nbsp;words,&nbsp;the&nbsp;stack&nbsp;trace&nbsp;inside&nbsp;the&nbsp;Pexpect&nbsp;module<br>
 
70
is&nbsp;not&nbsp;included.</tt></dd></dl>
 
71
 
 
72
<hr>
 
73
Data descriptors inherited from <a href="pexpect.html#ExceptionPexpect">pexpect.ExceptionPexpect</a>:<br>
 
74
<dl><dt><strong>__weakref__</strong></dt>
 
75
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
 
76
</dl>
 
77
<hr>
 
78
Data and other attributes inherited from <a href="exceptions.html#Exception">exceptions.Exception</a>:<br>
 
79
<dl><dt><strong>__new__</strong> = &lt;built-in method __new__ of type object at 0x81400e0&gt;<dd><tt>T.<a href="#ExceptionPxssh-__new__">__new__</a>(S,&nbsp;...)&nbsp;-&gt;&nbsp;a&nbsp;new&nbsp;object&nbsp;with&nbsp;type&nbsp;S,&nbsp;a&nbsp;subtype&nbsp;of&nbsp;T</tt></dl>
 
80
 
 
81
<hr>
 
82
Methods inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br>
 
83
<dl><dt><a name="ExceptionPxssh-__delattr__"><strong>__delattr__</strong></a>(...)</dt><dd><tt>x.<a href="#ExceptionPxssh-__delattr__">__delattr__</a>('name')&nbsp;&lt;==&gt;&nbsp;del&nbsp;x.name</tt></dd></dl>
 
84
 
 
85
<dl><dt><a name="ExceptionPxssh-__getattribute__"><strong>__getattribute__</strong></a>(...)</dt><dd><tt>x.<a href="#ExceptionPxssh-__getattribute__">__getattribute__</a>('name')&nbsp;&lt;==&gt;&nbsp;x.name</tt></dd></dl>
 
86
 
 
87
<dl><dt><a name="ExceptionPxssh-__getitem__"><strong>__getitem__</strong></a>(...)</dt><dd><tt>x.<a href="#ExceptionPxssh-__getitem__">__getitem__</a>(y)&nbsp;&lt;==&gt;&nbsp;x[y]</tt></dd></dl>
 
88
 
 
89
<dl><dt><a name="ExceptionPxssh-__getslice__"><strong>__getslice__</strong></a>(...)</dt><dd><tt>x.<a href="#ExceptionPxssh-__getslice__">__getslice__</a>(i,&nbsp;j)&nbsp;&lt;==&gt;&nbsp;x[i:j]<br>
 
90
&nbsp;<br>
 
91
Use&nbsp;of&nbsp;negative&nbsp;indices&nbsp;is&nbsp;not&nbsp;supported.</tt></dd></dl>
 
92
 
 
93
<dl><dt><a name="ExceptionPxssh-__reduce__"><strong>__reduce__</strong></a>(...)</dt></dl>
 
94
 
 
95
<dl><dt><a name="ExceptionPxssh-__repr__"><strong>__repr__</strong></a>(...)</dt><dd><tt>x.<a href="#ExceptionPxssh-__repr__">__repr__</a>()&nbsp;&lt;==&gt;&nbsp;repr(x)</tt></dd></dl>
 
96
 
 
97
<dl><dt><a name="ExceptionPxssh-__setattr__"><strong>__setattr__</strong></a>(...)</dt><dd><tt>x.<a href="#ExceptionPxssh-__setattr__">__setattr__</a>('name',&nbsp;value)&nbsp;&lt;==&gt;&nbsp;x.name&nbsp;=&nbsp;value</tt></dd></dl>
 
98
 
 
99
<dl><dt><a name="ExceptionPxssh-__setstate__"><strong>__setstate__</strong></a>(...)</dt></dl>
 
100
 
 
101
<hr>
 
102
Data descriptors inherited from <a href="exceptions.html#BaseException">exceptions.BaseException</a>:<br>
 
103
<dl><dt><strong>__dict__</strong></dt>
 
104
</dl>
 
105
<dl><dt><strong>args</strong></dt>
 
106
</dl>
 
107
<dl><dt><strong>message</strong></dt>
 
108
<dd><tt>exception&nbsp;message</tt></dd>
 
109
</dl>
 
110
</td></tr></table> <p>
 
111
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
 
112
<tr bgcolor="#ffc8d8">
 
113
<td colspan=3 valign=bottom>&nbsp;<br>
32
114
<font color="#000000" face="helvetica, arial"><a name="pxssh">class <strong>pxssh</strong></a>(<a href="pexpect.html#spawn">pexpect.spawn</a>)</font></td></tr>
33
115
    
34
116
<tr bgcolor="#ffc8d8"><td rowspan=2><tt>&nbsp;&nbsp;&nbsp;</tt></td>
35
 
<td colspan=2><tt>This&nbsp;class&nbsp;extends&nbsp;pexpect.<a href="pexpect.html#spawn">spawn</a>&nbsp;to&nbsp;specialize&nbsp;setting&nbsp;up&nbsp;SSH&nbsp;connections.<br>
36
 
This&nbsp;adds&nbsp;methods&nbsp;for&nbsp;login,&nbsp;logout,&nbsp;and&nbsp;expecting&nbsp;the&nbsp;prompt.<br>
37
 
It&nbsp;does&nbsp;various&nbsp;hacky&nbsp;things&nbsp;to&nbsp;handle&nbsp;any&nbsp;situation&nbsp;in&nbsp;the&nbsp;SSH&nbsp;login&nbsp;process.<br>
38
 
For&nbsp;example,&nbsp;if&nbsp;the&nbsp;session&nbsp;is&nbsp;your&nbsp;first&nbsp;login,&nbsp;then&nbsp;it&nbsp;automatically<br>
39
 
accepts&nbsp;the&nbsp;certificate;&nbsp;or&nbsp;if&nbsp;you&nbsp;have&nbsp;public&nbsp;key&nbsp;authentication&nbsp;setup<br>
40
 
and&nbsp;you&nbsp;don't&nbsp;need&nbsp;a&nbsp;password&nbsp;then&nbsp;this&nbsp;is&nbsp;OK&nbsp;too.<br>
41
 
&nbsp;<br>
42
 
Example&nbsp;usage&nbsp;that&nbsp;runs&nbsp;'ls&nbsp;-l'&nbsp;on&nbsp;server&nbsp;and&nbsp;prints&nbsp;the&nbsp;result:<br>
 
117
<td colspan=2><tt>This&nbsp;class&nbsp;extends&nbsp;pexpect.<a href="pexpect.html#spawn">spawn</a>&nbsp;to&nbsp;specialize&nbsp;setting&nbsp;up&nbsp;SSH<br>
 
118
connections.&nbsp;This&nbsp;adds&nbsp;methods&nbsp;for&nbsp;login,&nbsp;logout,&nbsp;and&nbsp;expecting&nbsp;the&nbsp;shell<br>
 
119
prompt.&nbsp;It&nbsp;does&nbsp;various&nbsp;tricky&nbsp;things&nbsp;to&nbsp;handle&nbsp;many&nbsp;situations&nbsp;in&nbsp;the&nbsp;SSH<br>
 
120
login&nbsp;process.&nbsp;For&nbsp;example,&nbsp;if&nbsp;the&nbsp;session&nbsp;is&nbsp;your&nbsp;first&nbsp;login,&nbsp;then&nbsp;<a href="#pxssh">pxssh</a><br>
 
121
automatically&nbsp;accepts&nbsp;the&nbsp;remote&nbsp;certificate;&nbsp;or&nbsp;if&nbsp;you&nbsp;have&nbsp;public&nbsp;key<br>
 
122
authentication&nbsp;setup&nbsp;then&nbsp;<a href="#pxssh">pxssh</a>&nbsp;won't&nbsp;wait&nbsp;for&nbsp;the&nbsp;password&nbsp;prompt.<br>
 
123
&nbsp;<br>
 
124
<a href="#pxssh">pxssh</a>&nbsp;uses&nbsp;the&nbsp;shell&nbsp;prompt&nbsp;to&nbsp;synchronize&nbsp;output&nbsp;from&nbsp;the&nbsp;remote&nbsp;host.&nbsp;In<br>
 
125
order&nbsp;to&nbsp;make&nbsp;this&nbsp;more&nbsp;robust&nbsp;it&nbsp;sets&nbsp;the&nbsp;shell&nbsp;prompt&nbsp;to&nbsp;something&nbsp;more<br>
 
126
unique&nbsp;than&nbsp;just&nbsp;$&nbsp;or&nbsp;#.&nbsp;This&nbsp;should&nbsp;work&nbsp;on&nbsp;most&nbsp;Borne/Bash&nbsp;or&nbsp;Csh&nbsp;style<br>
 
127
shells.<br>
 
128
&nbsp;<br>
 
129
Example&nbsp;that&nbsp;runs&nbsp;a&nbsp;few&nbsp;commands&nbsp;on&nbsp;a&nbsp;remote&nbsp;server&nbsp;and&nbsp;prints&nbsp;the&nbsp;result::<br>
 
130
&nbsp;&nbsp;&nbsp;&nbsp;<br>
43
131
&nbsp;&nbsp;&nbsp;&nbsp;import&nbsp;<a href="#pxssh">pxssh</a><br>
44
 
&nbsp;&nbsp;&nbsp;&nbsp;s&nbsp;=&nbsp;<a href="#pxssh">pxssh</a>.<a href="#pxssh">pxssh</a>()<br>
45
 
&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;not&nbsp;s.login&nbsp;('localhost',&nbsp;'myusername',&nbsp;'mypassword'):<br>
46
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;"SSH&nbsp;session&nbsp;failed&nbsp;on&nbsp;login."<br>
47
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;str(s)<br>
48
 
&nbsp;&nbsp;&nbsp;&nbsp;else:<br>
49
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;"SSH&nbsp;session&nbsp;login&nbsp;successful"<br>
 
132
&nbsp;&nbsp;&nbsp;&nbsp;import&nbsp;getpass<br>
 
133
&nbsp;&nbsp;&nbsp;&nbsp;try:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>
 
134
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s&nbsp;=&nbsp;<a href="#pxssh">pxssh</a>.<a href="#pxssh">pxssh</a>()<br>
 
135
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hostname&nbsp;=&nbsp;raw_input('hostname:&nbsp;')<br>
 
136
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;username&nbsp;=&nbsp;raw_input('username:&nbsp;')<br>
 
137
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;password&nbsp;=&nbsp;getpass.getpass('password:&nbsp;')<br>
 
138
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.login&nbsp;(hostname,&nbsp;username,&nbsp;password)<br>
 
139
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.sendline&nbsp;('uptime')&nbsp;&nbsp;#&nbsp;run&nbsp;a&nbsp;command<br>
 
140
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.<a href="#pxssh-prompt">prompt</a>()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;match&nbsp;the&nbsp;prompt<br>
 
141
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;s.before&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;print&nbsp;everything&nbsp;before&nbsp;the&nbsp;prompt.<br>
50
142
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.sendline&nbsp;('ls&nbsp;-l')<br>
51
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.<a href="#pxssh-prompt">prompt</a>()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;match&nbsp;the&nbsp;prompt<br>
52
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;s.before&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;print&nbsp;everything&nbsp;before&nbsp;the&nbsp;prompt.<br>
53
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.<a href="#pxssh-logout">logout</a>()<br>&nbsp;</tt></td></tr>
 
143
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.<a href="#pxssh-prompt">prompt</a>()<br>
 
144
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;s.before<br>
 
145
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.sendline&nbsp;('df')<br>
 
146
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.<a href="#pxssh-prompt">prompt</a>()<br>
 
147
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;s.before<br>
 
148
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.<a href="#pxssh-logout">logout</a>()<br>
 
149
&nbsp;&nbsp;&nbsp;&nbsp;except&nbsp;<a href="#pxssh">pxssh</a>.<a href="#ExceptionPxssh">ExceptionPxssh</a>,&nbsp;e:<br>
 
150
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;"<a href="#pxssh">pxssh</a>&nbsp;failed&nbsp;on&nbsp;login."<br>
 
151
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;str(e)<br>
 
152
&nbsp;<br>
 
153
Note&nbsp;that&nbsp;if&nbsp;you&nbsp;have&nbsp;ssh-agent&nbsp;running&nbsp;while&nbsp;doing&nbsp;development&nbsp;with&nbsp;<a href="#pxssh">pxssh</a><br>
 
154
then&nbsp;this&nbsp;can&nbsp;lead&nbsp;to&nbsp;a&nbsp;lot&nbsp;of&nbsp;confusion.&nbsp;Many&nbsp;X&nbsp;display&nbsp;managers&nbsp;(xdm,<br>
 
155
gdm,&nbsp;kdm,&nbsp;etc.)&nbsp;will&nbsp;automatically&nbsp;start&nbsp;a&nbsp;GUI&nbsp;agent.&nbsp;You&nbsp;may&nbsp;see&nbsp;a&nbsp;GUI<br>
 
156
dialog&nbsp;box&nbsp;popup&nbsp;asking&nbsp;for&nbsp;a&nbsp;password&nbsp;during&nbsp;development.&nbsp;You&nbsp;should&nbsp;turn<br>
 
157
off&nbsp;any&nbsp;key&nbsp;agents&nbsp;during&nbsp;testing.&nbsp;The&nbsp;'force_password'&nbsp;attribute&nbsp;will&nbsp;turn<br>
 
158
off&nbsp;public&nbsp;key&nbsp;authentication.&nbsp;This&nbsp;will&nbsp;only&nbsp;work&nbsp;if&nbsp;the&nbsp;remote&nbsp;SSH&nbsp;server<br>
 
159
is&nbsp;configured&nbsp;to&nbsp;allow&nbsp;password&nbsp;logins.&nbsp;Example&nbsp;of&nbsp;using&nbsp;'force_password'<br>
 
160
attribute::<br>
 
161
&nbsp;<br>
 
162
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s&nbsp;=&nbsp;<a href="#pxssh">pxssh</a>.<a href="#pxssh">pxssh</a>()<br>
 
163
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.force_password&nbsp;=&nbsp;True<br>
 
164
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hostname&nbsp;=&nbsp;raw_input('hostname:&nbsp;')<br>
 
165
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;username&nbsp;=&nbsp;raw_input('username:&nbsp;')<br>
 
166
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;password&nbsp;=&nbsp;getpass.getpass('password:&nbsp;')<br>
 
167
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s.login&nbsp;(hostname,&nbsp;username,&nbsp;password)<br>&nbsp;</tt></td></tr>
54
168
<tr><td>&nbsp;</td>
55
169
<td width="100%"><dl><dt>Method resolution order:</dt>
56
170
<dd><a href="pxssh.html#pxssh">pxssh</a></dd>
59
173
</dl>
60
174
<hr>
61
175
Methods defined here:<br>
62
 
<dl><dt><a name="pxssh-__init__"><strong>__init__</strong></a>(self)</dt></dl>
63
 
 
64
 
<dl><dt><a name="pxssh-login"><strong>login</strong></a>(self, server, username, password<font color="#909090">=''</font>, terminal_type<font color="#909090">='ansi'</font>, original_prompts<font color="#909090">='][#$]|~[#$]|bash.*?[#$]|[#$] '</font>, login_timeout<font color="#909090">=10</font>)</dt><dd><tt>This&nbsp;logs&nbsp;the&nbsp;user&nbsp;into&nbsp;the&nbsp;given&nbsp;server.&nbsp;By&nbsp;default&nbsp;the&nbsp;prompt&nbsp;is<br>
65
 
rather&nbsp;optimistic&nbsp;and&nbsp;should&nbsp;be&nbsp;considered&nbsp;more&nbsp;of&nbsp;an&nbsp;example.&nbsp;It's<br>
66
 
better&nbsp;to&nbsp;try&nbsp;to&nbsp;match&nbsp;the&nbsp;prompt&nbsp;as&nbsp;exactly&nbsp;as&nbsp;possible&nbsp;to&nbsp;prevent<br>
67
 
any&nbsp;false&nbsp;matches&nbsp;by&nbsp;server&nbsp;strings&nbsp;such&nbsp;as&nbsp;a&nbsp;"Message&nbsp;Of&nbsp;The&nbsp;Day"&nbsp;or<br>
68
 
something.&nbsp;The&nbsp;closer&nbsp;you&nbsp;can&nbsp;make&nbsp;the&nbsp;original_prompt&nbsp;match&nbsp;your&nbsp;real&nbsp;prompt<br>
69
 
then&nbsp;the&nbsp;better.&nbsp;A&nbsp;timeout&nbsp;will&nbsp;not&nbsp;necessarily&nbsp;cause&nbsp;the&nbsp;login&nbsp;to&nbsp;fail.<br>
70
 
In&nbsp;the&nbsp;case&nbsp;of&nbsp;a&nbsp;timeout&nbsp;we&nbsp;assume&nbsp;that&nbsp;the&nbsp;prompt&nbsp;was&nbsp;so&nbsp;weird&nbsp;that<br>
71
 
we&nbsp;could&nbsp;not&nbsp;match&nbsp;it.&nbsp;We&nbsp;still&nbsp;try&nbsp;to&nbsp;reset&nbsp;the&nbsp;prompt&nbsp;to&nbsp;something<br>
72
 
more&nbsp;unique.&nbsp;If&nbsp;that&nbsp;still&nbsp;fails&nbsp;then&nbsp;we&nbsp;return&nbsp;False.</tt></dd></dl>
73
 
 
74
 
<dl><dt><a name="pxssh-logout"><strong>logout</strong></a>(self)</dt><dd><tt>This&nbsp;sends&nbsp;exit.&nbsp;If&nbsp;there&nbsp;are&nbsp;stopped&nbsp;jobs&nbsp;then&nbsp;this&nbsp;sends&nbsp;exit&nbsp;twice.</tt></dd></dl>
75
 
 
76
 
<dl><dt><a name="pxssh-prompt"><strong>prompt</strong></a>(self, timeout<font color="#909090">=20</font>)</dt><dd><tt>This&nbsp;expects&nbsp;the&nbsp;prompt.&nbsp;This&nbsp;returns&nbsp;True&nbsp;if&nbsp;the&nbsp;prompt&nbsp;was&nbsp;matched.<br>
77
 
This&nbsp;returns&nbsp;False&nbsp;if&nbsp;there&nbsp;was&nbsp;a&nbsp;timeout.</tt></dd></dl>
78
 
 
79
 
<dl><dt><a name="pxssh-set_unique_prompt"><strong>set_unique_prompt</strong></a>(self, optional_prompt<font color="#909090">=None</font>)</dt><dd><tt>This&nbsp;attempts&nbsp;to&nbsp;reset&nbsp;the&nbsp;shell&nbsp;prompt&nbsp;to&nbsp;something&nbsp;more&nbsp;unique.<br>
80
 
This&nbsp;makes&nbsp;it&nbsp;easier&nbsp;to&nbsp;match&nbsp;unambiguously.</tt></dd></dl>
 
176
<dl><dt><a name="pxssh-__init__"><strong>__init__</strong></a>(self, timeout<font color="#909090">=30</font>, maxread<font color="#909090">=2000</font>, searchwindowsize<font color="#909090">=None</font>, logfile<font color="#909090">=None</font>, cwd<font color="#909090">=None</font>, env<font color="#909090">=None</font>)</dt></dl>
 
177
 
 
178
<dl><dt><a name="pxssh-levenshtein_distance"><strong>levenshtein_distance</strong></a>(self, a, b)</dt><dd><tt>This&nbsp;calculates&nbsp;the&nbsp;Levenshtein&nbsp;distance&nbsp;between&nbsp;a&nbsp;and&nbsp;b.</tt></dd></dl>
 
179
 
 
180
<dl><dt><a name="pxssh-login"><strong>login</strong></a>(self, server, username, password<font color="#909090">=''</font>, terminal_type<font color="#909090">='ansi'</font>, original_prompt<font color="#909090">='[#$]'</font>, login_timeout<font color="#909090">=10</font>, port<font color="#909090">=None</font>, auto_prompt_reset<font color="#909090">=True</font>)</dt><dd><tt>This&nbsp;logs&nbsp;the&nbsp;user&nbsp;into&nbsp;the&nbsp;given&nbsp;server.&nbsp;It&nbsp;uses&nbsp;the<br>
 
181
'original_prompt'&nbsp;to&nbsp;try&nbsp;to&nbsp;find&nbsp;the&nbsp;prompt&nbsp;right&nbsp;after&nbsp;login.&nbsp;When&nbsp;it<br>
 
182
finds&nbsp;the&nbsp;prompt&nbsp;it&nbsp;immediately&nbsp;tries&nbsp;to&nbsp;reset&nbsp;the&nbsp;prompt&nbsp;to&nbsp;something<br>
 
183
more&nbsp;easily&nbsp;matched.&nbsp;The&nbsp;default&nbsp;'original_prompt'&nbsp;is&nbsp;very&nbsp;optimistic<br>
 
184
and&nbsp;is&nbsp;easily&nbsp;fooled.&nbsp;It's&nbsp;more&nbsp;reliable&nbsp;to&nbsp;try&nbsp;to&nbsp;match&nbsp;the&nbsp;original<br>
 
185
prompt&nbsp;as&nbsp;exactly&nbsp;as&nbsp;possible&nbsp;to&nbsp;prevent&nbsp;false&nbsp;matches&nbsp;by&nbsp;server<br>
 
186
strings&nbsp;such&nbsp;as&nbsp;the&nbsp;"Message&nbsp;Of&nbsp;The&nbsp;Day".&nbsp;On&nbsp;many&nbsp;systems&nbsp;you&nbsp;can<br>
 
187
disable&nbsp;the&nbsp;MOTD&nbsp;on&nbsp;the&nbsp;remote&nbsp;server&nbsp;by&nbsp;creating&nbsp;a&nbsp;zero-length&nbsp;file<br>
 
188
called&nbsp;"~/.hushlogin"&nbsp;on&nbsp;the&nbsp;remote&nbsp;server.&nbsp;If&nbsp;a&nbsp;prompt&nbsp;cannot&nbsp;be&nbsp;found<br>
 
189
then&nbsp;this&nbsp;will&nbsp;not&nbsp;necessarily&nbsp;cause&nbsp;the&nbsp;login&nbsp;to&nbsp;fail.&nbsp;In&nbsp;the&nbsp;case&nbsp;of<br>
 
190
a&nbsp;timeout&nbsp;when&nbsp;looking&nbsp;for&nbsp;the&nbsp;prompt&nbsp;we&nbsp;assume&nbsp;that&nbsp;the&nbsp;original<br>
 
191
prompt&nbsp;was&nbsp;so&nbsp;weird&nbsp;that&nbsp;we&nbsp;could&nbsp;not&nbsp;match&nbsp;it,&nbsp;so&nbsp;we&nbsp;use&nbsp;a&nbsp;few&nbsp;tricks<br>
 
192
to&nbsp;guess&nbsp;when&nbsp;we&nbsp;have&nbsp;reached&nbsp;the&nbsp;prompt.&nbsp;Then&nbsp;we&nbsp;hope&nbsp;for&nbsp;the&nbsp;best&nbsp;and<br>
 
193
blindly&nbsp;try&nbsp;to&nbsp;reset&nbsp;the&nbsp;prompt&nbsp;to&nbsp;something&nbsp;more&nbsp;unique.&nbsp;If&nbsp;that&nbsp;fails<br>
 
194
then&nbsp;<a href="#pxssh-login">login</a>()&nbsp;raises&nbsp;an&nbsp;<a href="#ExceptionPxssh">ExceptionPxssh</a>&nbsp;exception.<br>
 
195
&nbsp;<br>
 
196
In&nbsp;some&nbsp;situations&nbsp;it&nbsp;is&nbsp;not&nbsp;possible&nbsp;or&nbsp;desirable&nbsp;to&nbsp;reset&nbsp;the<br>
 
197
original&nbsp;prompt.&nbsp;In&nbsp;this&nbsp;case,&nbsp;set&nbsp;'auto_prompt_reset'&nbsp;to&nbsp;False&nbsp;to<br>
 
198
inhibit&nbsp;setting&nbsp;the&nbsp;prompt&nbsp;to&nbsp;the&nbsp;UNIQUE_PROMPT.&nbsp;Remember&nbsp;that&nbsp;<a href="#pxssh">pxssh</a><br>
 
199
uses&nbsp;a&nbsp;unique&nbsp;prompt&nbsp;in&nbsp;the&nbsp;<a href="#pxssh-prompt">prompt</a>()&nbsp;method.&nbsp;If&nbsp;the&nbsp;original&nbsp;prompt&nbsp;is<br>
 
200
not&nbsp;reset&nbsp;then&nbsp;this&nbsp;will&nbsp;disable&nbsp;the&nbsp;<a href="#pxssh-prompt">prompt</a>()&nbsp;method&nbsp;unless&nbsp;you<br>
 
201
manually&nbsp;set&nbsp;the&nbsp;PROMPT&nbsp;attribute.</tt></dd></dl>
 
202
 
 
203
<dl><dt><a name="pxssh-logout"><strong>logout</strong></a>(self)</dt><dd><tt>This&nbsp;sends&nbsp;exit&nbsp;to&nbsp;the&nbsp;remote&nbsp;shell.&nbsp;If&nbsp;there&nbsp;are&nbsp;stopped&nbsp;jobs&nbsp;then<br>
 
204
this&nbsp;automatically&nbsp;sends&nbsp;exit&nbsp;twice.</tt></dd></dl>
 
205
 
 
206
<dl><dt><a name="pxssh-prompt"><strong>prompt</strong></a>(self, timeout<font color="#909090">=20</font>)</dt><dd><tt>This&nbsp;matches&nbsp;the&nbsp;shell&nbsp;prompt.&nbsp;This&nbsp;is&nbsp;little&nbsp;more&nbsp;than&nbsp;a&nbsp;short-cut<br>
 
207
to&nbsp;the&nbsp;<a href="#pxssh-expect">expect</a>()&nbsp;method.&nbsp;This&nbsp;returns&nbsp;True&nbsp;if&nbsp;the&nbsp;shell&nbsp;prompt&nbsp;was<br>
 
208
matched.&nbsp;This&nbsp;returns&nbsp;False&nbsp;if&nbsp;there&nbsp;was&nbsp;a&nbsp;timeout.&nbsp;Note&nbsp;that&nbsp;if&nbsp;you<br>
 
209
called&nbsp;<a href="#pxssh-login">login</a>()&nbsp;with&nbsp;auto_prompt_reset&nbsp;set&nbsp;to&nbsp;False&nbsp;then&nbsp;you&nbsp;should&nbsp;have<br>
 
210
manually&nbsp;set&nbsp;the&nbsp;PROMPT&nbsp;attribute&nbsp;to&nbsp;a&nbsp;regex&nbsp;pattern&nbsp;for&nbsp;matching&nbsp;the<br>
 
211
prompt.</tt></dd></dl>
 
212
 
 
213
<dl><dt><a name="pxssh-set_unique_prompt"><strong>set_unique_prompt</strong></a>(self)</dt><dd><tt>This&nbsp;sets&nbsp;the&nbsp;remote&nbsp;prompt&nbsp;to&nbsp;something&nbsp;more&nbsp;unique&nbsp;than&nbsp;#&nbsp;or&nbsp;$.<br>
 
214
This&nbsp;makes&nbsp;it&nbsp;easier&nbsp;for&nbsp;the&nbsp;<a href="#pxssh-prompt">prompt</a>()&nbsp;method&nbsp;to&nbsp;match&nbsp;the&nbsp;shell&nbsp;prompt<br>
 
215
unambiguously.&nbsp;This&nbsp;method&nbsp;is&nbsp;called&nbsp;automatically&nbsp;by&nbsp;the&nbsp;<a href="#pxssh-login">login</a>()<br>
 
216
method,&nbsp;but&nbsp;you&nbsp;may&nbsp;want&nbsp;to&nbsp;call&nbsp;it&nbsp;manually&nbsp;if&nbsp;you&nbsp;somehow&nbsp;reset&nbsp;the<br>
 
217
shell&nbsp;prompt.&nbsp;For&nbsp;example,&nbsp;if&nbsp;you&nbsp;'su'&nbsp;to&nbsp;a&nbsp;different&nbsp;user&nbsp;then&nbsp;you<br>
 
218
will&nbsp;need&nbsp;to&nbsp;manually&nbsp;reset&nbsp;the&nbsp;prompt.&nbsp;This&nbsp;sends&nbsp;shell&nbsp;commands&nbsp;to<br>
 
219
the&nbsp;remote&nbsp;host&nbsp;to&nbsp;set&nbsp;the&nbsp;prompt,&nbsp;so&nbsp;this&nbsp;assumes&nbsp;the&nbsp;remote&nbsp;host&nbsp;is<br>
 
220
ready&nbsp;to&nbsp;receive&nbsp;commands.<br>
 
221
&nbsp;<br>
 
222
Alternatively,&nbsp;you&nbsp;may&nbsp;use&nbsp;your&nbsp;own&nbsp;prompt&nbsp;pattern.&nbsp;Just&nbsp;set&nbsp;the&nbsp;PROMPT<br>
 
223
attribute&nbsp;to&nbsp;a&nbsp;regular&nbsp;expression&nbsp;that&nbsp;matches&nbsp;it.&nbsp;In&nbsp;this&nbsp;case&nbsp;you<br>
 
224
should&nbsp;call&nbsp;<a href="#pxssh-login">login</a>()&nbsp;with&nbsp;auto_prompt_reset=False;&nbsp;then&nbsp;set&nbsp;the&nbsp;PROMPT<br>
 
225
attribute.&nbsp;After&nbsp;that&nbsp;the&nbsp;<a href="#pxssh-prompt">prompt</a>()&nbsp;method&nbsp;will&nbsp;try&nbsp;to&nbsp;match&nbsp;your&nbsp;prompt<br>
 
226
pattern.</tt></dd></dl>
 
227
 
 
228
<dl><dt><a name="pxssh-synch_original_prompt"><strong>synch_original_prompt</strong></a>(self)</dt><dd><tt>This&nbsp;attempts&nbsp;to&nbsp;find&nbsp;the&nbsp;prompt.&nbsp;Basically,&nbsp;press&nbsp;enter&nbsp;and&nbsp;record<br>
 
229
the&nbsp;response;&nbsp;press&nbsp;enter&nbsp;again&nbsp;and&nbsp;record&nbsp;the&nbsp;response;&nbsp;if&nbsp;the&nbsp;two<br>
 
230
responses&nbsp;are&nbsp;similar&nbsp;then&nbsp;assume&nbsp;we&nbsp;are&nbsp;at&nbsp;the&nbsp;original&nbsp;prompt.</tt></dd></dl>
81
231
 
82
232
<hr>
83
233
Methods inherited from <a href="pexpect.html#spawn">pexpect.spawn</a>:<br>
84
 
<dl><dt><a name="pxssh-__del__"><strong>__del__</strong></a>(self)</dt><dd><tt>This&nbsp;makes&nbsp;sure&nbsp;that&nbsp;no&nbsp;system&nbsp;resources&nbsp;are&nbsp;left&nbsp;open.<br>
85
 
Python&nbsp;only&nbsp;garbage&nbsp;collects&nbsp;Python&nbsp;objects.&nbsp;OS&nbsp;file&nbsp;descriptors<br>
86
 
are&nbsp;not&nbsp;Python&nbsp;objects,&nbsp;so&nbsp;they&nbsp;must&nbsp;be&nbsp;handled&nbsp;explicitly.<br>
87
 
If&nbsp;the&nbsp;child&nbsp;file&nbsp;descriptor&nbsp;was&nbsp;opened&nbsp;outside&nbsp;of&nbsp;this&nbsp;class<br>
88
 
(passed&nbsp;to&nbsp;the&nbsp;constructor)&nbsp;then&nbsp;this&nbsp;does&nbsp;not&nbsp;close&nbsp;it.</tt></dd></dl>
 
234
<dl><dt><a name="pxssh-__del__"><strong>__del__</strong></a>(self)</dt><dd><tt>This&nbsp;makes&nbsp;sure&nbsp;that&nbsp;no&nbsp;system&nbsp;resources&nbsp;are&nbsp;left&nbsp;open.&nbsp;Python&nbsp;only<br>
 
235
garbage&nbsp;collects&nbsp;Python&nbsp;objects.&nbsp;OS&nbsp;file&nbsp;descriptors&nbsp;are&nbsp;not&nbsp;Python<br>
 
236
objects,&nbsp;so&nbsp;they&nbsp;must&nbsp;be&nbsp;handled&nbsp;explicitly.&nbsp;If&nbsp;the&nbsp;child&nbsp;file<br>
 
237
descriptor&nbsp;was&nbsp;opened&nbsp;outside&nbsp;of&nbsp;this&nbsp;class&nbsp;(passed&nbsp;to&nbsp;the&nbsp;constructor)<br>
 
238
then&nbsp;this&nbsp;does&nbsp;not&nbsp;close&nbsp;it.</tt></dd></dl>
89
239
 
90
240
<dl><dt><a name="pxssh-__iter__"><strong>__iter__</strong></a>(self)</dt><dd><tt>This&nbsp;is&nbsp;to&nbsp;support&nbsp;iterators&nbsp;over&nbsp;a&nbsp;file-like&nbsp;object.</tt></dd></dl>
91
241
 
92
 
<dl><dt><a name="pxssh-__str__"><strong>__str__</strong></a>(self)</dt><dd><tt>This&nbsp;returns&nbsp;the&nbsp;current&nbsp;state&nbsp;of&nbsp;the&nbsp;pexpect&nbsp;object&nbsp;as&nbsp;a&nbsp;string.</tt></dd></dl>
 
242
<dl><dt><a name="pxssh-__str__"><strong>__str__</strong></a>(self)</dt><dd><tt>This&nbsp;returns&nbsp;a&nbsp;human-readable&nbsp;string&nbsp;that&nbsp;represents&nbsp;the&nbsp;state&nbsp;of<br>
 
243
the&nbsp;object.</tt></dd></dl>
93
244
 
94
 
<dl><dt><a name="pxssh-close"><strong>close</strong></a>(self, force<font color="#909090">=True</font>)</dt><dd><tt>This&nbsp;closes&nbsp;the&nbsp;connection&nbsp;with&nbsp;the&nbsp;child&nbsp;application.<br>
95
 
Note&nbsp;that&nbsp;calling&nbsp;<a href="#pxssh-close">close</a>()&nbsp;more&nbsp;than&nbsp;once&nbsp;is&nbsp;valid.<br>
96
 
This&nbsp;emulates&nbsp;standard&nbsp;Python&nbsp;behavior&nbsp;with&nbsp;files.<br>
97
 
Set&nbsp;force&nbsp;to&nbsp;True&nbsp;if&nbsp;you&nbsp;want&nbsp;to&nbsp;make&nbsp;sure&nbsp;that&nbsp;the&nbsp;child&nbsp;is&nbsp;terminated<br>
98
 
(SIGKILL&nbsp;is&nbsp;sent&nbsp;if&nbsp;the&nbsp;child&nbsp;ignores&nbsp;SIGHUP&nbsp;and&nbsp;SIGINT).</tt></dd></dl>
 
245
<dl><dt><a name="pxssh-close"><strong>close</strong></a>(self, force<font color="#909090">=True</font>)</dt><dd><tt>This&nbsp;closes&nbsp;the&nbsp;connection&nbsp;with&nbsp;the&nbsp;child&nbsp;application.&nbsp;Note&nbsp;that<br>
 
246
calling&nbsp;<a href="#pxssh-close">close</a>()&nbsp;more&nbsp;than&nbsp;once&nbsp;is&nbsp;valid.&nbsp;This&nbsp;emulates&nbsp;standard&nbsp;Python<br>
 
247
behavior&nbsp;with&nbsp;files.&nbsp;Set&nbsp;force&nbsp;to&nbsp;True&nbsp;if&nbsp;you&nbsp;want&nbsp;to&nbsp;make&nbsp;sure&nbsp;that<br>
 
248
the&nbsp;child&nbsp;is&nbsp;terminated&nbsp;(SIGKILL&nbsp;is&nbsp;sent&nbsp;if&nbsp;the&nbsp;child&nbsp;ignores&nbsp;SIGHUP<br>
 
249
and&nbsp;SIGINT).</tt></dd></dl>
99
250
 
100
251
<dl><dt><a name="pxssh-compile_pattern_list"><strong>compile_pattern_list</strong></a>(self, patterns)</dt><dd><tt>This&nbsp;compiles&nbsp;a&nbsp;pattern-string&nbsp;or&nbsp;a&nbsp;list&nbsp;of&nbsp;pattern-strings.<br>
101
 
Patterns&nbsp;must&nbsp;be&nbsp;a&nbsp;StringType,&nbsp;EOF,&nbsp;TIMEOUT,&nbsp;SRE_Pattern,&nbsp;or&nbsp;<br>
102
 
a&nbsp;list&nbsp;of&nbsp;those.&nbsp;Patterns&nbsp;may&nbsp;also&nbsp;be&nbsp;None&nbsp;which&nbsp;results&nbsp;in<br>
103
 
an&nbsp;empty&nbsp;list.<br>
104
 
&nbsp;<br>
105
 
This&nbsp;is&nbsp;used&nbsp;by&nbsp;<a href="#pxssh-expect">expect</a>()&nbsp;when&nbsp;calling&nbsp;<a href="#pxssh-expect_list">expect_list</a>().<br>
106
 
Thus&nbsp;<a href="#pxssh-expect">expect</a>()&nbsp;is&nbsp;nothing&nbsp;more&nbsp;than::<br>
 
252
Patterns&nbsp;must&nbsp;be&nbsp;a&nbsp;StringType,&nbsp;EOF,&nbsp;TIMEOUT,&nbsp;SRE_Pattern,&nbsp;or&nbsp;a&nbsp;list&nbsp;of<br>
 
253
those.&nbsp;Patterns&nbsp;may&nbsp;also&nbsp;be&nbsp;None&nbsp;which&nbsp;results&nbsp;in&nbsp;an&nbsp;empty&nbsp;list&nbsp;(you<br>
 
254
might&nbsp;do&nbsp;this&nbsp;if&nbsp;waiting&nbsp;for&nbsp;an&nbsp;EOF&nbsp;or&nbsp;TIMEOUT&nbsp;condition&nbsp;without<br>
 
255
expecting&nbsp;any&nbsp;pattern).<br>
 
256
&nbsp;<br>
 
257
This&nbsp;is&nbsp;used&nbsp;by&nbsp;<a href="#pxssh-expect">expect</a>()&nbsp;when&nbsp;calling&nbsp;<a href="#pxssh-expect_list">expect_list</a>().&nbsp;Thus&nbsp;<a href="#pxssh-expect">expect</a>()&nbsp;is<br>
 
258
nothing&nbsp;more&nbsp;than::<br>
 
259
&nbsp;<br>
107
260
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cpl&nbsp;=&nbsp;<a href="#pxssh-compile_pattern_list">compile_pattern_list</a>(pl)<br>
108
 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<a href="#pxssh-expect_list">expect_list</a>(clp,&nbsp;timeout)<br>
 
261
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return&nbsp;<a href="#pxssh-expect_list">expect_list</a>(cpl,&nbsp;timeout)<br>
109
262
&nbsp;<br>
110
263
If&nbsp;you&nbsp;are&nbsp;using&nbsp;<a href="#pxssh-expect">expect</a>()&nbsp;within&nbsp;a&nbsp;loop&nbsp;it&nbsp;may&nbsp;be&nbsp;more<br>
111
264
efficient&nbsp;to&nbsp;compile&nbsp;the&nbsp;patterns&nbsp;first&nbsp;and&nbsp;then&nbsp;call&nbsp;<a href="#pxssh-expect_list">expect_list</a>().<br>
112
 
This&nbsp;avoid&nbsp;calls&nbsp;in&nbsp;a&nbsp;loop&nbsp;to&nbsp;<a href="#pxssh-compile_pattern_list">compile_pattern_list</a>():<br>
 
265
This&nbsp;avoid&nbsp;calls&nbsp;in&nbsp;a&nbsp;loop&nbsp;to&nbsp;<a href="#pxssh-compile_pattern_list">compile_pattern_list</a>()::<br>
 
266
&nbsp;<br>
113
267
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;cpl&nbsp;=&nbsp;<a href="#pxssh-compile_pattern_list">compile_pattern_list</a>(my_pattern)<br>
114
268
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while&nbsp;some_condition:<br>
115
269
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...<br>
118
272
 
119
273
<dl><dt><a name="pxssh-eof"><strong>eof</strong></a>(self)</dt><dd><tt>This&nbsp;returns&nbsp;True&nbsp;if&nbsp;the&nbsp;EOF&nbsp;exception&nbsp;was&nbsp;ever&nbsp;raised.</tt></dd></dl>
120
274
 
121
 
<dl><dt><a name="pxssh-expect"><strong>expect</strong></a>(self, pattern, timeout<font color="#909090">=-1</font>, searchwindowsize<font color="#909090">=None</font>)</dt><dd><tt>This&nbsp;seeks&nbsp;through&nbsp;the&nbsp;stream&nbsp;until&nbsp;a&nbsp;pattern&nbsp;is&nbsp;matched.<br>
122
 
The&nbsp;pattern&nbsp;is&nbsp;overloaded&nbsp;and&nbsp;may&nbsp;take&nbsp;several&nbsp;types&nbsp;including&nbsp;a&nbsp;list.<br>
123
 
The&nbsp;pattern&nbsp;can&nbsp;be&nbsp;a&nbsp;StringType,&nbsp;EOF,&nbsp;a&nbsp;compiled&nbsp;re,&nbsp;or&nbsp;a&nbsp;list&nbsp;of<br>
124
 
those&nbsp;types.&nbsp;Strings&nbsp;will&nbsp;be&nbsp;compiled&nbsp;to&nbsp;re&nbsp;types.&nbsp;This&nbsp;returns&nbsp;the<br>
125
 
index&nbsp;into&nbsp;the&nbsp;pattern&nbsp;list.&nbsp;If&nbsp;the&nbsp;pattern&nbsp;was&nbsp;not&nbsp;a&nbsp;list&nbsp;this<br>
126
 
returns&nbsp;index&nbsp;0&nbsp;on&nbsp;a&nbsp;successful&nbsp;match.&nbsp;This&nbsp;may&nbsp;raise&nbsp;exceptions&nbsp;for<br>
127
 
EOF&nbsp;or&nbsp;TIMEOUT.&nbsp;To&nbsp;avoid&nbsp;the&nbsp;EOF&nbsp;or&nbsp;TIMEOUT&nbsp;exceptions&nbsp;add<br>
128
 
EOF&nbsp;or&nbsp;TIMEOUT&nbsp;to&nbsp;the&nbsp;pattern&nbsp;list.<br>
129
 
&nbsp;<br>
130
 
After&nbsp;a&nbsp;match&nbsp;is&nbsp;found&nbsp;the&nbsp;instance&nbsp;attributes<br>
131
 
'before',&nbsp;'after'&nbsp;and&nbsp;'match'&nbsp;will&nbsp;be&nbsp;set.<br>
132
 
You&nbsp;can&nbsp;see&nbsp;all&nbsp;the&nbsp;data&nbsp;read&nbsp;before&nbsp;the&nbsp;match&nbsp;in&nbsp;'before'.<br>
133
 
You&nbsp;can&nbsp;see&nbsp;the&nbsp;data&nbsp;that&nbsp;was&nbsp;matched&nbsp;in&nbsp;'after'.<br>
134
 
The&nbsp;re.MatchObject&nbsp;used&nbsp;in&nbsp;the&nbsp;re&nbsp;match&nbsp;will&nbsp;be&nbsp;in&nbsp;'match'.<br>
135
 
If&nbsp;an&nbsp;error&nbsp;occured&nbsp;then&nbsp;'before'&nbsp;will&nbsp;be&nbsp;set&nbsp;to&nbsp;all&nbsp;the<br>
136
 
data&nbsp;read&nbsp;so&nbsp;far&nbsp;and&nbsp;'after'&nbsp;and&nbsp;'match'&nbsp;will&nbsp;be&nbsp;None.<br>
 
275
<dl><dt><a name="pxssh-expect"><strong>expect</strong></a>(self, pattern, timeout<font color="#909090">=-1</font>, searchwindowsize<font color="#909090">=None</font>)</dt><dd><tt>This&nbsp;seeks&nbsp;through&nbsp;the&nbsp;stream&nbsp;until&nbsp;a&nbsp;pattern&nbsp;is&nbsp;matched.&nbsp;The<br>
 
276
pattern&nbsp;is&nbsp;overloaded&nbsp;and&nbsp;may&nbsp;take&nbsp;several&nbsp;types.&nbsp;The&nbsp;pattern&nbsp;can&nbsp;be&nbsp;a<br>
 
277
StringType,&nbsp;EOF,&nbsp;a&nbsp;compiled&nbsp;re,&nbsp;or&nbsp;a&nbsp;list&nbsp;of&nbsp;any&nbsp;of&nbsp;those&nbsp;types.<br>
 
278
Strings&nbsp;will&nbsp;be&nbsp;compiled&nbsp;to&nbsp;re&nbsp;types.&nbsp;This&nbsp;returns&nbsp;the&nbsp;index&nbsp;into&nbsp;the<br>
 
279
pattern&nbsp;list.&nbsp;If&nbsp;the&nbsp;pattern&nbsp;was&nbsp;not&nbsp;a&nbsp;list&nbsp;this&nbsp;returns&nbsp;index&nbsp;0&nbsp;on&nbsp;a<br>
 
280
successful&nbsp;match.&nbsp;This&nbsp;may&nbsp;raise&nbsp;exceptions&nbsp;for&nbsp;EOF&nbsp;or&nbsp;TIMEOUT.&nbsp;To<br>
 
281
avoid&nbsp;the&nbsp;EOF&nbsp;or&nbsp;TIMEOUT&nbsp;exceptions&nbsp;add&nbsp;EOF&nbsp;or&nbsp;TIMEOUT&nbsp;to&nbsp;the&nbsp;pattern<br>
 
282
list.&nbsp;That&nbsp;will&nbsp;cause&nbsp;expect&nbsp;to&nbsp;match&nbsp;an&nbsp;EOF&nbsp;or&nbsp;TIMEOUT&nbsp;condition<br>
 
283
instead&nbsp;of&nbsp;raising&nbsp;an&nbsp;exception.<br>
 
284
&nbsp;<br>
 
285
If&nbsp;you&nbsp;pass&nbsp;a&nbsp;list&nbsp;of&nbsp;patterns&nbsp;and&nbsp;more&nbsp;than&nbsp;one&nbsp;matches,&nbsp;the&nbsp;first&nbsp;match<br>
 
286
in&nbsp;the&nbsp;stream&nbsp;is&nbsp;chosen.&nbsp;If&nbsp;more&nbsp;than&nbsp;one&nbsp;pattern&nbsp;matches&nbsp;at&nbsp;that&nbsp;point,<br>
 
287
the&nbsp;leftmost&nbsp;in&nbsp;the&nbsp;pattern&nbsp;list&nbsp;is&nbsp;chosen.&nbsp;For&nbsp;example::<br>
 
288
&nbsp;<br>
 
289
&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;the&nbsp;input&nbsp;is&nbsp;'foobar'<br>
 
290
&nbsp;&nbsp;&nbsp;&nbsp;index&nbsp;=&nbsp;p.expect&nbsp;(['bar',&nbsp;'foo',&nbsp;'foobar'])<br>
 
291
&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;returns&nbsp;1&nbsp;('foo')&nbsp;even&nbsp;though&nbsp;'foobar'&nbsp;is&nbsp;a&nbsp;"better"&nbsp;match<br>
 
292
&nbsp;<br>
 
293
Please&nbsp;note,&nbsp;however,&nbsp;that&nbsp;buffering&nbsp;can&nbsp;affect&nbsp;this&nbsp;behavior,&nbsp;since<br>
 
294
input&nbsp;arrives&nbsp;in&nbsp;unpredictable&nbsp;chunks.&nbsp;For&nbsp;example::<br>
 
295
&nbsp;<br>
 
296
&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;the&nbsp;input&nbsp;is&nbsp;'foobar'<br>
 
297
&nbsp;&nbsp;&nbsp;&nbsp;index&nbsp;=&nbsp;p.expect&nbsp;(['foobar',&nbsp;'foo'])<br>
 
298
&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;returns&nbsp;0&nbsp;('foobar')&nbsp;if&nbsp;all&nbsp;input&nbsp;is&nbsp;available&nbsp;at&nbsp;once,<br>
 
299
&nbsp;&nbsp;&nbsp;&nbsp;#&nbsp;but&nbsp;returs&nbsp;1&nbsp;('foo')&nbsp;if&nbsp;parts&nbsp;of&nbsp;the&nbsp;final&nbsp;'bar'&nbsp;arrive&nbsp;late<br>
 
300
&nbsp;<br>
 
301
After&nbsp;a&nbsp;match&nbsp;is&nbsp;found&nbsp;the&nbsp;instance&nbsp;attributes&nbsp;'before',&nbsp;'after'&nbsp;and<br>
 
302
'match'&nbsp;will&nbsp;be&nbsp;set.&nbsp;You&nbsp;can&nbsp;see&nbsp;all&nbsp;the&nbsp;data&nbsp;read&nbsp;before&nbsp;the&nbsp;match&nbsp;in<br>
 
303
'before'.&nbsp;You&nbsp;can&nbsp;see&nbsp;the&nbsp;data&nbsp;that&nbsp;was&nbsp;matched&nbsp;in&nbsp;'after'.&nbsp;The<br>
 
304
re.MatchObject&nbsp;used&nbsp;in&nbsp;the&nbsp;re&nbsp;match&nbsp;will&nbsp;be&nbsp;in&nbsp;'match'.&nbsp;If&nbsp;an&nbsp;error<br>
 
305
occurred&nbsp;then&nbsp;'before'&nbsp;will&nbsp;be&nbsp;set&nbsp;to&nbsp;all&nbsp;the&nbsp;data&nbsp;read&nbsp;so&nbsp;far&nbsp;and<br>
 
306
'after'&nbsp;and&nbsp;'match'&nbsp;will&nbsp;be&nbsp;None.<br>
137
307
&nbsp;<br>
138
308
If&nbsp;timeout&nbsp;is&nbsp;-1&nbsp;then&nbsp;timeout&nbsp;will&nbsp;be&nbsp;set&nbsp;to&nbsp;the&nbsp;self.<strong>timeout</strong>&nbsp;value.<br>
139
309
&nbsp;<br>
140
 
Note:&nbsp;A&nbsp;list&nbsp;entry&nbsp;may&nbsp;be&nbsp;EOF&nbsp;or&nbsp;TIMEOUT&nbsp;instead&nbsp;of&nbsp;a&nbsp;string.<br>
141
 
This&nbsp;will&nbsp;catch&nbsp;these&nbsp;exceptions&nbsp;and&nbsp;return&nbsp;the&nbsp;index<br>
142
 
of&nbsp;the&nbsp;list&nbsp;entry&nbsp;instead&nbsp;of&nbsp;raising&nbsp;the&nbsp;exception.<br>
143
 
The&nbsp;attribute&nbsp;'after'&nbsp;will&nbsp;be&nbsp;set&nbsp;to&nbsp;the&nbsp;exception&nbsp;type.<br>
144
 
The&nbsp;attribute&nbsp;'match'&nbsp;will&nbsp;be&nbsp;None.<br>
145
 
This&nbsp;allows&nbsp;you&nbsp;to&nbsp;write&nbsp;code&nbsp;like&nbsp;this:<br>
 
310
A&nbsp;list&nbsp;entry&nbsp;may&nbsp;be&nbsp;EOF&nbsp;or&nbsp;TIMEOUT&nbsp;instead&nbsp;of&nbsp;a&nbsp;string.&nbsp;This&nbsp;will<br>
 
311
catch&nbsp;these&nbsp;exceptions&nbsp;and&nbsp;return&nbsp;the&nbsp;index&nbsp;of&nbsp;the&nbsp;list&nbsp;entry&nbsp;instead<br>
 
312
of&nbsp;raising&nbsp;the&nbsp;exception.&nbsp;The&nbsp;attribute&nbsp;'after'&nbsp;will&nbsp;be&nbsp;set&nbsp;to&nbsp;the<br>
 
313
exception&nbsp;type.&nbsp;The&nbsp;attribute&nbsp;'match'&nbsp;will&nbsp;be&nbsp;None.&nbsp;This&nbsp;allows&nbsp;you&nbsp;to<br>
 
314
write&nbsp;code&nbsp;like&nbsp;this::<br>
 
315
&nbsp;<br>
146
316
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;index&nbsp;=&nbsp;p.expect&nbsp;(['good',&nbsp;'bad',&nbsp;pexpect.EOF,&nbsp;pexpect.TIMEOUT])<br>
147
317
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;index&nbsp;==&nbsp;0:<br>
148
318
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do_something()<br>
152
322
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do_some_other_thing()<br>
153
323
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elif&nbsp;index&nbsp;==&nbsp;3:<br>
154
324
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do_something_completely_different()<br>
155
 
instead&nbsp;of&nbsp;code&nbsp;like&nbsp;this:<br>
 
325
&nbsp;<br>
 
326
instead&nbsp;of&nbsp;code&nbsp;like&nbsp;this::<br>
 
327
&nbsp;<br>
156
328
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try:<br>
157
329
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;index&nbsp;=&nbsp;p.expect&nbsp;(['good',&nbsp;'bad'])<br>
158
330
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;index&nbsp;==&nbsp;0:<br>
163
335
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do_some_other_thing()<br>
164
336
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;except&nbsp;TIMEOUT:<br>
165
337
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;do_something_completely_different()<br>
166
 
These&nbsp;two&nbsp;forms&nbsp;are&nbsp;equivalent.&nbsp;It&nbsp;all&nbsp;depends&nbsp;on&nbsp;what&nbsp;you&nbsp;want.<br>
167
 
You&nbsp;can&nbsp;also&nbsp;just&nbsp;expect&nbsp;the&nbsp;EOF&nbsp;if&nbsp;you&nbsp;are&nbsp;waiting&nbsp;for&nbsp;all&nbsp;output<br>
168
 
of&nbsp;a&nbsp;child&nbsp;to&nbsp;finish.&nbsp;For&nbsp;example:<br>
 
338
&nbsp;<br>
 
339
These&nbsp;two&nbsp;forms&nbsp;are&nbsp;equivalent.&nbsp;It&nbsp;all&nbsp;depends&nbsp;on&nbsp;what&nbsp;you&nbsp;want.&nbsp;You<br>
 
340
can&nbsp;also&nbsp;just&nbsp;expect&nbsp;the&nbsp;EOF&nbsp;if&nbsp;you&nbsp;are&nbsp;waiting&nbsp;for&nbsp;all&nbsp;output&nbsp;of&nbsp;a<br>
 
341
child&nbsp;to&nbsp;finish.&nbsp;For&nbsp;example::<br>
 
342
&nbsp;<br>
169
343
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p&nbsp;=&nbsp;pexpect.<a href="pexpect.html#spawn">spawn</a>('/bin/ls')<br>
170
344
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;p.expect&nbsp;(pexpect.EOF)<br>
171
345
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;p.before<br>
172
346
&nbsp;<br>
173
347
If&nbsp;you&nbsp;are&nbsp;trying&nbsp;to&nbsp;optimize&nbsp;for&nbsp;speed&nbsp;then&nbsp;see&nbsp;<a href="#pxssh-expect_list">expect_list</a>().</tt></dd></dl>
174
348
 
175
 
<dl><dt><a name="pxssh-expect_exact"><strong>expect_exact</strong></a>(self, pattern_list, timeout<font color="#909090">=-1</font>)</dt><dd><tt>This&nbsp;method&nbsp;is&nbsp;no&nbsp;longer&nbsp;supported&nbsp;or&nbsp;allowed.<br>
176
 
It&nbsp;was&nbsp;too&nbsp;hard&nbsp;to&nbsp;maintain&nbsp;and&nbsp;keep&nbsp;it&nbsp;up&nbsp;to&nbsp;date&nbsp;with&nbsp;expect_list.<br>
177
 
Few&nbsp;people&nbsp;used&nbsp;this&nbsp;method.&nbsp;Most&nbsp;people&nbsp;favored&nbsp;reliability&nbsp;over&nbsp;speed.<br>
178
 
The&nbsp;implementation&nbsp;is&nbsp;left&nbsp;in&nbsp;comments&nbsp;in&nbsp;case&nbsp;anyone&nbsp;needs&nbsp;to&nbsp;hack&nbsp;this<br>
179
 
feature&nbsp;back&nbsp;into&nbsp;their&nbsp;copy.<br>
180
 
If&nbsp;someone&nbsp;wants&nbsp;to&nbsp;diff&nbsp;this&nbsp;with&nbsp;expect_list&nbsp;and&nbsp;make&nbsp;them&nbsp;work<br>
181
 
nearly&nbsp;the&nbsp;same&nbsp;then&nbsp;I&nbsp;will&nbsp;consider&nbsp;adding&nbsp;this&nbsp;make&nbsp;in.</tt></dd></dl>
182
 
 
183
 
<dl><dt><a name="pxssh-expect_list"><strong>expect_list</strong></a>(self, pattern_list, timeout<font color="#909090">=-1</font>, searchwindowsize<font color="#909090">=-1</font>)</dt><dd><tt>This&nbsp;takes&nbsp;a&nbsp;list&nbsp;of&nbsp;compiled&nbsp;regular&nbsp;expressions&nbsp;and&nbsp;returns&nbsp;<br>
184
 
the&nbsp;index&nbsp;into&nbsp;the&nbsp;pattern_list&nbsp;that&nbsp;matched&nbsp;the&nbsp;child&nbsp;output.<br>
185
 
The&nbsp;list&nbsp;may&nbsp;also&nbsp;contain&nbsp;EOF&nbsp;or&nbsp;TIMEOUT&nbsp;(which&nbsp;are&nbsp;not<br>
186
 
compiled&nbsp;regular&nbsp;expressions).&nbsp;This&nbsp;method&nbsp;is&nbsp;similar&nbsp;to<br>
187
 
the&nbsp;<a href="#pxssh-expect">expect</a>()&nbsp;method&nbsp;except&nbsp;that&nbsp;<a href="#pxssh-expect_list">expect_list</a>()&nbsp;does&nbsp;not<br>
188
 
recompile&nbsp;the&nbsp;pattern&nbsp;list&nbsp;on&nbsp;every&nbsp;call.<br>
189
 
This&nbsp;may&nbsp;help&nbsp;if&nbsp;you&nbsp;are&nbsp;trying&nbsp;to&nbsp;optimize&nbsp;for&nbsp;speed,&nbsp;otherwise<br>
190
 
just&nbsp;use&nbsp;the&nbsp;<a href="#pxssh-expect">expect</a>()&nbsp;method.&nbsp;&nbsp;This&nbsp;is&nbsp;called&nbsp;by&nbsp;<a href="#pxssh-expect">expect</a>().<br>
191
 
If&nbsp;timeout==-1&nbsp;then&nbsp;the&nbsp;self.<strong>timeout</strong>&nbsp;value&nbsp;is&nbsp;used.<br>
192
 
If&nbsp;searchwindowsize==-1&nbsp;then&nbsp;the&nbsp;self.<strong>searchwindowsize</strong>&nbsp;value&nbsp;is&nbsp;used.</tt></dd></dl>
 
349
<dl><dt><a name="pxssh-expect_exact"><strong>expect_exact</strong></a>(self, pattern_list, timeout<font color="#909090">=-1</font>, searchwindowsize<font color="#909090">=-1</font>)</dt><dd><tt>This&nbsp;is&nbsp;similar&nbsp;to&nbsp;<a href="#pxssh-expect">expect</a>(),&nbsp;but&nbsp;uses&nbsp;plain&nbsp;string&nbsp;matching&nbsp;instead<br>
 
350
of&nbsp;compiled&nbsp;regular&nbsp;expressions&nbsp;in&nbsp;'pattern_list'.&nbsp;The&nbsp;'pattern_list'<br>
 
351
may&nbsp;be&nbsp;a&nbsp;string;&nbsp;a&nbsp;list&nbsp;or&nbsp;other&nbsp;sequence&nbsp;of&nbsp;strings;&nbsp;or&nbsp;TIMEOUT&nbsp;and<br>
 
352
EOF.<br>
 
353
&nbsp;<br>
 
354
This&nbsp;call&nbsp;might&nbsp;be&nbsp;faster&nbsp;than&nbsp;<a href="#pxssh-expect">expect</a>()&nbsp;for&nbsp;two&nbsp;reasons:&nbsp;string<br>
 
355
searching&nbsp;is&nbsp;faster&nbsp;than&nbsp;RE&nbsp;matching&nbsp;and&nbsp;it&nbsp;is&nbsp;possible&nbsp;to&nbsp;limit&nbsp;the<br>
 
356
search&nbsp;to&nbsp;just&nbsp;the&nbsp;end&nbsp;of&nbsp;the&nbsp;input&nbsp;buffer.<br>
 
357
&nbsp;<br>
 
358
This&nbsp;method&nbsp;is&nbsp;also&nbsp;useful&nbsp;when&nbsp;you&nbsp;don't&nbsp;want&nbsp;to&nbsp;have&nbsp;to&nbsp;worry&nbsp;about<br>
 
359
escaping&nbsp;regular&nbsp;expression&nbsp;characters&nbsp;that&nbsp;you&nbsp;want&nbsp;to&nbsp;match.</tt></dd></dl>
 
360
 
 
361
<dl><dt><a name="pxssh-expect_list"><strong>expect_list</strong></a>(self, pattern_list, timeout<font color="#909090">=-1</font>, searchwindowsize<font color="#909090">=-1</font>)</dt><dd><tt>This&nbsp;takes&nbsp;a&nbsp;list&nbsp;of&nbsp;compiled&nbsp;regular&nbsp;expressions&nbsp;and&nbsp;returns&nbsp;the<br>
 
362
index&nbsp;into&nbsp;the&nbsp;pattern_list&nbsp;that&nbsp;matched&nbsp;the&nbsp;child&nbsp;output.&nbsp;The&nbsp;list&nbsp;may<br>
 
363
also&nbsp;contain&nbsp;EOF&nbsp;or&nbsp;TIMEOUT&nbsp;(which&nbsp;are&nbsp;not&nbsp;compiled&nbsp;regular<br>
 
364
expressions).&nbsp;This&nbsp;method&nbsp;is&nbsp;similar&nbsp;to&nbsp;the&nbsp;<a href="#pxssh-expect">expect</a>()&nbsp;method&nbsp;except&nbsp;that<br>
 
365
<a href="#pxssh-expect_list">expect_list</a>()&nbsp;does&nbsp;not&nbsp;recompile&nbsp;the&nbsp;pattern&nbsp;list&nbsp;on&nbsp;every&nbsp;call.&nbsp;This<br>
 
366
may&nbsp;help&nbsp;if&nbsp;you&nbsp;are&nbsp;trying&nbsp;to&nbsp;optimize&nbsp;for&nbsp;speed,&nbsp;otherwise&nbsp;just&nbsp;use<br>
 
367
the&nbsp;<a href="#pxssh-expect">expect</a>()&nbsp;method.&nbsp;&nbsp;This&nbsp;is&nbsp;called&nbsp;by&nbsp;<a href="#pxssh-expect">expect</a>().&nbsp;If&nbsp;timeout==-1&nbsp;then<br>
 
368
the&nbsp;self.<strong>timeout</strong>&nbsp;value&nbsp;is&nbsp;used.&nbsp;If&nbsp;searchwindowsize==-1&nbsp;then&nbsp;the<br>
 
369
self.<strong>searchwindowsize</strong>&nbsp;value&nbsp;is&nbsp;used.</tt></dd></dl>
 
370
 
 
371
<dl><dt><a name="pxssh-expect_loop"><strong>expect_loop</strong></a>(self, searcher, timeout<font color="#909090">=-1</font>, searchwindowsize<font color="#909090">=-1</font>)</dt><dd><tt>This&nbsp;is&nbsp;the&nbsp;common&nbsp;loop&nbsp;used&nbsp;inside&nbsp;expect.&nbsp;The&nbsp;'searcher'&nbsp;should&nbsp;be<br>
 
372
an&nbsp;instance&nbsp;of&nbsp;searcher_re&nbsp;or&nbsp;searcher_string,&nbsp;which&nbsp;describes&nbsp;how&nbsp;and&nbsp;what<br>
 
373
to&nbsp;search&nbsp;for&nbsp;in&nbsp;the&nbsp;input.<br>
 
374
&nbsp;<br>
 
375
See&nbsp;<a href="#pxssh-expect">expect</a>()&nbsp;for&nbsp;other&nbsp;arguments,&nbsp;return&nbsp;value&nbsp;and&nbsp;exceptions.</tt></dd></dl>
193
376
 
194
377
<dl><dt><a name="pxssh-fileno"><strong>fileno</strong></a>(self)</dt><dd><tt>This&nbsp;returns&nbsp;the&nbsp;file&nbsp;descriptor&nbsp;of&nbsp;the&nbsp;pty&nbsp;for&nbsp;the&nbsp;child.</tt></dd></dl>
195
378
 
196
 
<dl><dt><a name="pxssh-flush"><strong>flush</strong></a>(self)</dt><dd><tt>This&nbsp;does&nbsp;nothing.&nbsp;It&nbsp;is&nbsp;here&nbsp;to&nbsp;support&nbsp;the&nbsp;interface&nbsp;for&nbsp;a&nbsp;File-like&nbsp;object.</tt></dd></dl>
197
 
 
198
 
<dl><dt><a name="pxssh-getwinsize"><strong>getwinsize</strong></a>(self)</dt><dd><tt>This&nbsp;returns&nbsp;the&nbsp;terminal&nbsp;window&nbsp;size&nbsp;of&nbsp;the&nbsp;child&nbsp;tty.<br>
199
 
The&nbsp;return&nbsp;value&nbsp;is&nbsp;a&nbsp;tuple&nbsp;of&nbsp;(rows,&nbsp;cols).</tt></dd></dl>
200
 
 
201
 
<dl><dt><a name="pxssh-interact"><strong>interact</strong></a>(self, escape_character<font color="#909090">='<font color="#c040c0">\x1d</font>'</font>, input_filter<font color="#909090">=None</font>, output_filter<font color="#909090">=None</font>)</dt><dd><tt>This&nbsp;gives&nbsp;control&nbsp;of&nbsp;the&nbsp;child&nbsp;process&nbsp;to&nbsp;the&nbsp;interactive&nbsp;user<br>
202
 
(the&nbsp;human&nbsp;at&nbsp;the&nbsp;keyboard).<br>
203
 
Keystrokes&nbsp;are&nbsp;sent&nbsp;to&nbsp;the&nbsp;child&nbsp;process,&nbsp;and&nbsp;the&nbsp;stdout&nbsp;and&nbsp;stderr<br>
204
 
output&nbsp;of&nbsp;the&nbsp;child&nbsp;process&nbsp;is&nbsp;printed.<br>
205
 
This&nbsp;simply&nbsp;echos&nbsp;the&nbsp;child&nbsp;stdout&nbsp;and&nbsp;child&nbsp;stderr&nbsp;to&nbsp;the&nbsp;real<br>
206
 
stdout&nbsp;and&nbsp;it&nbsp;echos&nbsp;the&nbsp;real&nbsp;stdin&nbsp;to&nbsp;the&nbsp;child&nbsp;stdin.<br>
207
 
When&nbsp;the&nbsp;user&nbsp;types&nbsp;the&nbsp;escape_character&nbsp;this&nbsp;method&nbsp;will&nbsp;stop.<br>
208
 
The&nbsp;default&nbsp;for&nbsp;escape_character&nbsp;is&nbsp;^].&nbsp;This&nbsp;should&nbsp;not&nbsp;be&nbsp;confused<br>
209
 
with&nbsp;ASCII&nbsp;27&nbsp;--&nbsp;the&nbsp;ESC&nbsp;character.&nbsp;ASCII&nbsp;29&nbsp;was&nbsp;chosen<br>
210
 
for&nbsp;historical&nbsp;merit&nbsp;because&nbsp;this&nbsp;is&nbsp;the&nbsp;character&nbsp;used<br>
211
 
by&nbsp;'telnet'&nbsp;as&nbsp;the&nbsp;escape&nbsp;character.&nbsp;The&nbsp;escape_character&nbsp;will<br>
212
 
not&nbsp;be&nbsp;sent&nbsp;to&nbsp;the&nbsp;child&nbsp;process.<br>
213
 
&nbsp;<br>
214
 
You&nbsp;may&nbsp;pass&nbsp;in&nbsp;optional&nbsp;input&nbsp;and&nbsp;output&nbsp;filter&nbsp;functions.<br>
215
 
These&nbsp;functions&nbsp;should&nbsp;take&nbsp;a&nbsp;string&nbsp;and&nbsp;return&nbsp;a&nbsp;string.<br>
216
 
The&nbsp;output_filter&nbsp;will&nbsp;be&nbsp;passed&nbsp;all&nbsp;the&nbsp;output&nbsp;from&nbsp;the&nbsp;child&nbsp;process.<br>
217
 
The&nbsp;input_filter&nbsp;will&nbsp;be&nbsp;passed&nbsp;all&nbsp;the&nbsp;keyboard&nbsp;input&nbsp;from&nbsp;the&nbsp;user.<br>
218
 
The&nbsp;input_filter&nbsp;is&nbsp;run&nbsp;BEFORE&nbsp;the&nbsp;check&nbsp;for&nbsp;the&nbsp;escape_character.<br>
219
 
&nbsp;<br>
220
 
Note&nbsp;that&nbsp;if&nbsp;you&nbsp;change&nbsp;the&nbsp;window&nbsp;size&nbsp;of&nbsp;the&nbsp;parent<br>
221
 
the&nbsp;SIGWINCH&nbsp;signal&nbsp;will&nbsp;not&nbsp;be&nbsp;passed&nbsp;through&nbsp;to&nbsp;the&nbsp;child.<br>
222
 
If&nbsp;you&nbsp;want&nbsp;the&nbsp;child&nbsp;window&nbsp;size&nbsp;to&nbsp;change&nbsp;when&nbsp;the&nbsp;parent's<br>
223
 
window&nbsp;size&nbsp;changes&nbsp;then&nbsp;do&nbsp;something&nbsp;like&nbsp;the&nbsp;following&nbsp;example:<br>
 
379
<dl><dt><a name="pxssh-flush"><strong>flush</strong></a>(self)</dt><dd><tt>This&nbsp;does&nbsp;nothing.&nbsp;It&nbsp;is&nbsp;here&nbsp;to&nbsp;support&nbsp;the&nbsp;interface&nbsp;for&nbsp;a<br>
 
380
File-like&nbsp;object.</tt></dd></dl>
 
381
 
 
382
<dl><dt><a name="pxssh-getecho"><strong>getecho</strong></a>(self)</dt><dd><tt>This&nbsp;returns&nbsp;the&nbsp;terminal&nbsp;echo&nbsp;mode.&nbsp;This&nbsp;returns&nbsp;True&nbsp;if&nbsp;echo&nbsp;is<br>
 
383
on&nbsp;or&nbsp;False&nbsp;if&nbsp;echo&nbsp;is&nbsp;off.&nbsp;Child&nbsp;applications&nbsp;that&nbsp;are&nbsp;expecting&nbsp;you<br>
 
384
to&nbsp;enter&nbsp;a&nbsp;password&nbsp;often&nbsp;set&nbsp;ECHO&nbsp;False.&nbsp;See&nbsp;<a href="#pxssh-waitnoecho">waitnoecho</a>().</tt></dd></dl>
 
385
 
 
386
<dl><dt><a name="pxssh-getwinsize"><strong>getwinsize</strong></a>(self)</dt><dd><tt>This&nbsp;returns&nbsp;the&nbsp;terminal&nbsp;window&nbsp;size&nbsp;of&nbsp;the&nbsp;child&nbsp;tty.&nbsp;The&nbsp;return<br>
 
387
value&nbsp;is&nbsp;a&nbsp;tuple&nbsp;of&nbsp;(rows,&nbsp;cols).</tt></dd></dl>
 
388
 
 
389
<dl><dt><a name="pxssh-interact"><strong>interact</strong></a>(self, escape_character<font color="#909090">='<font color="#c040c0">\x1d</font>'</font>, input_filter<font color="#909090">=None</font>, output_filter<font color="#909090">=None</font>)</dt><dd><tt>This&nbsp;gives&nbsp;control&nbsp;of&nbsp;the&nbsp;child&nbsp;process&nbsp;to&nbsp;the&nbsp;interactive&nbsp;user&nbsp;(the<br>
 
390
human&nbsp;at&nbsp;the&nbsp;keyboard).&nbsp;Keystrokes&nbsp;are&nbsp;sent&nbsp;to&nbsp;the&nbsp;child&nbsp;process,&nbsp;and<br>
 
391
the&nbsp;stdout&nbsp;and&nbsp;stderr&nbsp;output&nbsp;of&nbsp;the&nbsp;child&nbsp;process&nbsp;is&nbsp;printed.&nbsp;This<br>
 
392
simply&nbsp;echos&nbsp;the&nbsp;child&nbsp;stdout&nbsp;and&nbsp;child&nbsp;stderr&nbsp;to&nbsp;the&nbsp;real&nbsp;stdout&nbsp;and<br>
 
393
it&nbsp;echos&nbsp;the&nbsp;real&nbsp;stdin&nbsp;to&nbsp;the&nbsp;child&nbsp;stdin.&nbsp;When&nbsp;the&nbsp;user&nbsp;types&nbsp;the<br>
 
394
escape_character&nbsp;this&nbsp;method&nbsp;will&nbsp;stop.&nbsp;The&nbsp;default&nbsp;for<br>
 
395
escape_character&nbsp;is&nbsp;^].&nbsp;This&nbsp;should&nbsp;not&nbsp;be&nbsp;confused&nbsp;with&nbsp;ASCII&nbsp;27&nbsp;--<br>
 
396
the&nbsp;ESC&nbsp;character.&nbsp;ASCII&nbsp;29&nbsp;was&nbsp;chosen&nbsp;for&nbsp;historical&nbsp;merit&nbsp;because<br>
 
397
this&nbsp;is&nbsp;the&nbsp;character&nbsp;used&nbsp;by&nbsp;'telnet'&nbsp;as&nbsp;the&nbsp;escape&nbsp;character.&nbsp;The<br>
 
398
escape_character&nbsp;will&nbsp;not&nbsp;be&nbsp;sent&nbsp;to&nbsp;the&nbsp;child&nbsp;process.<br>
 
399
&nbsp;<br>
 
400
You&nbsp;may&nbsp;pass&nbsp;in&nbsp;optional&nbsp;input&nbsp;and&nbsp;output&nbsp;filter&nbsp;functions.&nbsp;These<br>
 
401
functions&nbsp;should&nbsp;take&nbsp;a&nbsp;string&nbsp;and&nbsp;return&nbsp;a&nbsp;string.&nbsp;The&nbsp;output_filter<br>
 
402
will&nbsp;be&nbsp;passed&nbsp;all&nbsp;the&nbsp;output&nbsp;from&nbsp;the&nbsp;child&nbsp;process.&nbsp;The&nbsp;input_filter<br>
 
403
will&nbsp;be&nbsp;passed&nbsp;all&nbsp;the&nbsp;keyboard&nbsp;input&nbsp;from&nbsp;the&nbsp;user.&nbsp;The&nbsp;input_filter<br>
 
404
is&nbsp;run&nbsp;BEFORE&nbsp;the&nbsp;check&nbsp;for&nbsp;the&nbsp;escape_character.<br>
 
405
&nbsp;<br>
 
406
Note&nbsp;that&nbsp;if&nbsp;you&nbsp;change&nbsp;the&nbsp;window&nbsp;size&nbsp;of&nbsp;the&nbsp;parent&nbsp;the&nbsp;SIGWINCH<br>
 
407
signal&nbsp;will&nbsp;not&nbsp;be&nbsp;passed&nbsp;through&nbsp;to&nbsp;the&nbsp;child.&nbsp;If&nbsp;you&nbsp;want&nbsp;the&nbsp;child<br>
 
408
window&nbsp;size&nbsp;to&nbsp;change&nbsp;when&nbsp;the&nbsp;parent's&nbsp;window&nbsp;size&nbsp;changes&nbsp;then&nbsp;do<br>
 
409
something&nbsp;like&nbsp;the&nbsp;following&nbsp;example::<br>
 
410
&nbsp;<br>
224
411
&nbsp;&nbsp;&nbsp;&nbsp;import&nbsp;pexpect,&nbsp;struct,&nbsp;fcntl,&nbsp;termios,&nbsp;signal,&nbsp;sys<br>
225
412
&nbsp;&nbsp;&nbsp;&nbsp;def&nbsp;sigwinch_passthrough&nbsp;(sig,&nbsp;data):<br>
226
413
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;s&nbsp;=&nbsp;struct.pack("HHHH",&nbsp;0,&nbsp;0,&nbsp;0,&nbsp;0)<br>
231
418
&nbsp;&nbsp;&nbsp;&nbsp;signal.signal(signal.SIGWINCH,&nbsp;sigwinch_passthrough)<br>
232
419
&nbsp;&nbsp;&nbsp;&nbsp;p.<a href="#pxssh-interact">interact</a>()</tt></dd></dl>
233
420
 
234
 
<dl><dt><a name="pxssh-isalive"><strong>isalive</strong></a>(self)</dt><dd><tt>This&nbsp;tests&nbsp;if&nbsp;the&nbsp;child&nbsp;process&nbsp;is&nbsp;running&nbsp;or&nbsp;not.<br>
235
 
This&nbsp;is&nbsp;non-blocking.&nbsp;If&nbsp;the&nbsp;child&nbsp;was&nbsp;terminated&nbsp;then&nbsp;this<br>
236
 
will&nbsp;read&nbsp;the&nbsp;exitstatus&nbsp;or&nbsp;signalstatus&nbsp;of&nbsp;the&nbsp;child.<br>
237
 
This&nbsp;returns&nbsp;True&nbsp;if&nbsp;the&nbsp;child&nbsp;process&nbsp;appears&nbsp;to&nbsp;be&nbsp;running&nbsp;or&nbsp;False&nbsp;if&nbsp;not.<br>
238
 
It&nbsp;can&nbsp;take&nbsp;literally&nbsp;SECONDS&nbsp;for&nbsp;Solaris&nbsp;to&nbsp;return&nbsp;the&nbsp;right&nbsp;status.</tt></dd></dl>
239
 
 
240
 
<dl><dt><a name="pxssh-isatty"><strong>isatty</strong></a>(self)</dt><dd><tt>This&nbsp;returns&nbsp;True&nbsp;if&nbsp;the&nbsp;file&nbsp;descriptor&nbsp;is&nbsp;open&nbsp;and&nbsp;connected&nbsp;to&nbsp;a&nbsp;tty(-like)&nbsp;device,&nbsp;else&nbsp;False.</tt></dd></dl>
241
 
 
242
 
<dl><dt><a name="pxssh-kill"><strong>kill</strong></a>(self, sig)</dt><dd><tt>This&nbsp;sends&nbsp;the&nbsp;given&nbsp;signal&nbsp;to&nbsp;the&nbsp;child&nbsp;application.<br>
243
 
In&nbsp;keeping&nbsp;with&nbsp;UNIX&nbsp;tradition&nbsp;it&nbsp;has&nbsp;a&nbsp;misleading&nbsp;name.<br>
244
 
It&nbsp;does&nbsp;not&nbsp;necessarily&nbsp;kill&nbsp;the&nbsp;child&nbsp;unless<br>
245
 
you&nbsp;send&nbsp;the&nbsp;right&nbsp;signal.</tt></dd></dl>
 
421
<dl><dt><a name="pxssh-isalive"><strong>isalive</strong></a>(self)</dt><dd><tt>This&nbsp;tests&nbsp;if&nbsp;the&nbsp;child&nbsp;process&nbsp;is&nbsp;running&nbsp;or&nbsp;not.&nbsp;This&nbsp;is<br>
 
422
non-blocking.&nbsp;If&nbsp;the&nbsp;child&nbsp;was&nbsp;terminated&nbsp;then&nbsp;this&nbsp;will&nbsp;read&nbsp;the<br>
 
423
exitstatus&nbsp;or&nbsp;signalstatus&nbsp;of&nbsp;the&nbsp;child.&nbsp;This&nbsp;returns&nbsp;True&nbsp;if&nbsp;the&nbsp;child<br>
 
424
process&nbsp;appears&nbsp;to&nbsp;be&nbsp;running&nbsp;or&nbsp;False&nbsp;if&nbsp;not.&nbsp;It&nbsp;can&nbsp;take&nbsp;literally<br>
 
425
SECONDS&nbsp;for&nbsp;Solaris&nbsp;to&nbsp;return&nbsp;the&nbsp;right&nbsp;status.</tt></dd></dl>
 
426
 
 
427
<dl><dt><a name="pxssh-isatty"><strong>isatty</strong></a>(self)</dt><dd><tt>This&nbsp;returns&nbsp;True&nbsp;if&nbsp;the&nbsp;file&nbsp;descriptor&nbsp;is&nbsp;open&nbsp;and&nbsp;connected&nbsp;to&nbsp;a<br>
 
428
tty(-like)&nbsp;device,&nbsp;else&nbsp;False.</tt></dd></dl>
 
429
 
 
430
<dl><dt><a name="pxssh-kill"><strong>kill</strong></a>(self, sig)</dt><dd><tt>This&nbsp;sends&nbsp;the&nbsp;given&nbsp;signal&nbsp;to&nbsp;the&nbsp;child&nbsp;application.&nbsp;In&nbsp;keeping<br>
 
431
with&nbsp;UNIX&nbsp;tradition&nbsp;it&nbsp;has&nbsp;a&nbsp;misleading&nbsp;name.&nbsp;It&nbsp;does&nbsp;not&nbsp;necessarily<br>
 
432
kill&nbsp;the&nbsp;child&nbsp;unless&nbsp;you&nbsp;send&nbsp;the&nbsp;right&nbsp;signal.</tt></dd></dl>
246
433
 
247
434
<dl><dt><a name="pxssh-next"><strong>next</strong></a>(self)</dt><dd><tt>This&nbsp;is&nbsp;to&nbsp;support&nbsp;iterators&nbsp;over&nbsp;a&nbsp;file-like&nbsp;object.</tt></dd></dl>
248
435
 
249
 
<dl><dt><a name="pxssh-read"><strong>read</strong></a>(self, size<font color="#909090">=-1</font>)</dt><dd><tt>This&nbsp;reads&nbsp;at&nbsp;most&nbsp;"size"&nbsp;bytes&nbsp;from&nbsp;the&nbsp;file&nbsp;<br>
250
 
(less&nbsp;if&nbsp;the&nbsp;read&nbsp;hits&nbsp;EOF&nbsp;before&nbsp;obtaining&nbsp;size&nbsp;bytes).&nbsp;<br>
251
 
If&nbsp;the&nbsp;size&nbsp;argument&nbsp;is&nbsp;negative&nbsp;or&nbsp;omitted,&nbsp;<br>
252
 
read&nbsp;all&nbsp;data&nbsp;until&nbsp;EOF&nbsp;is&nbsp;reached.&nbsp;<br>
253
 
The&nbsp;bytes&nbsp;are&nbsp;returned&nbsp;as&nbsp;a&nbsp;string&nbsp;object.&nbsp;<br>
254
 
An&nbsp;empty&nbsp;string&nbsp;is&nbsp;returned&nbsp;when&nbsp;EOF&nbsp;is&nbsp;encountered&nbsp;immediately.</tt></dd></dl>
 
436
<dl><dt><a name="pxssh-read"><strong>read</strong></a>(self, size<font color="#909090">=-1</font>)</dt><dd><tt>This&nbsp;reads&nbsp;at&nbsp;most&nbsp;"size"&nbsp;bytes&nbsp;from&nbsp;the&nbsp;file&nbsp;(less&nbsp;if&nbsp;the&nbsp;read&nbsp;hits<br>
 
437
EOF&nbsp;before&nbsp;obtaining&nbsp;size&nbsp;bytes).&nbsp;If&nbsp;the&nbsp;size&nbsp;argument&nbsp;is&nbsp;negative&nbsp;or<br>
 
438
omitted,&nbsp;read&nbsp;all&nbsp;data&nbsp;until&nbsp;EOF&nbsp;is&nbsp;reached.&nbsp;The&nbsp;bytes&nbsp;are&nbsp;returned&nbsp;as<br>
 
439
a&nbsp;string&nbsp;object.&nbsp;An&nbsp;empty&nbsp;string&nbsp;is&nbsp;returned&nbsp;when&nbsp;EOF&nbsp;is&nbsp;encountered<br>
 
440
immediately.</tt></dd></dl>
255
441
 
256
 
<dl><dt><a name="pxssh-read_nonblocking"><strong>read_nonblocking</strong></a>(self, size<font color="#909090">=1</font>, timeout<font color="#909090">=-1</font>)</dt><dd><tt>This&nbsp;reads&nbsp;at&nbsp;most&nbsp;size&nbsp;characters&nbsp;from&nbsp;the&nbsp;child&nbsp;application.<br>
257
 
It&nbsp;includes&nbsp;a&nbsp;timeout.&nbsp;If&nbsp;the&nbsp;read&nbsp;does&nbsp;not&nbsp;complete&nbsp;within&nbsp;the<br>
258
 
timeout&nbsp;period&nbsp;then&nbsp;a&nbsp;TIMEOUT&nbsp;exception&nbsp;is&nbsp;raised.<br>
259
 
If&nbsp;the&nbsp;end&nbsp;of&nbsp;file&nbsp;is&nbsp;read&nbsp;then&nbsp;an&nbsp;EOF&nbsp;exception&nbsp;will&nbsp;be&nbsp;raised.<br>
260
 
If&nbsp;a&nbsp;log&nbsp;file&nbsp;was&nbsp;set&nbsp;using&nbsp;<a href="#pxssh-setlog">setlog</a>()&nbsp;then&nbsp;all&nbsp;data&nbsp;will<br>
261
 
also&nbsp;be&nbsp;written&nbsp;to&nbsp;the&nbsp;log&nbsp;file.<br>
262
 
&nbsp;<br>
263
 
If&nbsp;timeout==None&nbsp;then&nbsp;the&nbsp;read&nbsp;may&nbsp;block&nbsp;indefinitely.<br>
264
 
If&nbsp;timeout==-1&nbsp;then&nbsp;the&nbsp;self.<strong>timeout</strong>&nbsp;value&nbsp;is&nbsp;used.<br>
265
 
If&nbsp;timeout==0&nbsp;then&nbsp;the&nbsp;child&nbsp;is&nbsp;polled&nbsp;and&nbsp;<br>
266
 
&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;there&nbsp;was&nbsp;no&nbsp;data&nbsp;immediately&nbsp;ready&nbsp;then&nbsp;this&nbsp;will&nbsp;raise&nbsp;a&nbsp;TIMEOUT&nbsp;exception.<br>
267
 
&nbsp;<br>
268
 
The&nbsp;"timeout"&nbsp;refers&nbsp;only&nbsp;to&nbsp;the&nbsp;amount&nbsp;of&nbsp;time&nbsp;to&nbsp;read&nbsp;at&nbsp;least&nbsp;one&nbsp;character.<br>
269
 
This&nbsp;is&nbsp;not&nbsp;effected&nbsp;by&nbsp;the&nbsp;'size'&nbsp;parameter,&nbsp;so&nbsp;if&nbsp;you&nbsp;call<br>
 
442
<dl><dt><a name="pxssh-read_nonblocking"><strong>read_nonblocking</strong></a>(self, size<font color="#909090">=1</font>, timeout<font color="#909090">=-1</font>)</dt><dd><tt>This&nbsp;reads&nbsp;at&nbsp;most&nbsp;size&nbsp;characters&nbsp;from&nbsp;the&nbsp;child&nbsp;application.&nbsp;It<br>
 
443
includes&nbsp;a&nbsp;timeout.&nbsp;If&nbsp;the&nbsp;read&nbsp;does&nbsp;not&nbsp;complete&nbsp;within&nbsp;the&nbsp;timeout<br>
 
444
period&nbsp;then&nbsp;a&nbsp;TIMEOUT&nbsp;exception&nbsp;is&nbsp;raised.&nbsp;If&nbsp;the&nbsp;end&nbsp;of&nbsp;file&nbsp;is&nbsp;read<br>
 
445
then&nbsp;an&nbsp;EOF&nbsp;exception&nbsp;will&nbsp;be&nbsp;raised.&nbsp;If&nbsp;a&nbsp;log&nbsp;file&nbsp;was&nbsp;set&nbsp;using<br>
 
446
<a href="#pxssh-setlog">setlog</a>()&nbsp;then&nbsp;all&nbsp;data&nbsp;will&nbsp;also&nbsp;be&nbsp;written&nbsp;to&nbsp;the&nbsp;log&nbsp;file.<br>
 
447
&nbsp;<br>
 
448
If&nbsp;timeout&nbsp;is&nbsp;None&nbsp;then&nbsp;the&nbsp;read&nbsp;may&nbsp;block&nbsp;indefinitely.&nbsp;If&nbsp;timeout&nbsp;is&nbsp;-1<br>
 
449
then&nbsp;the&nbsp;self.<strong>timeout</strong>&nbsp;value&nbsp;is&nbsp;used.&nbsp;If&nbsp;timeout&nbsp;is&nbsp;0&nbsp;then&nbsp;the&nbsp;child&nbsp;is<br>
 
450
polled&nbsp;and&nbsp;if&nbsp;there&nbsp;was&nbsp;no&nbsp;data&nbsp;immediately&nbsp;ready&nbsp;then&nbsp;this&nbsp;will&nbsp;raise<br>
 
451
a&nbsp;TIMEOUT&nbsp;exception.<br>
 
452
&nbsp;<br>
 
453
The&nbsp;timeout&nbsp;refers&nbsp;only&nbsp;to&nbsp;the&nbsp;amount&nbsp;of&nbsp;time&nbsp;to&nbsp;read&nbsp;at&nbsp;least&nbsp;one<br>
 
454
character.&nbsp;This&nbsp;is&nbsp;not&nbsp;effected&nbsp;by&nbsp;the&nbsp;'size'&nbsp;parameter,&nbsp;so&nbsp;if&nbsp;you&nbsp;call<br>
270
455
<a href="#pxssh-read_nonblocking">read_nonblocking</a>(size=100,&nbsp;timeout=30)&nbsp;and&nbsp;only&nbsp;one&nbsp;character&nbsp;is<br>
271
 
available&nbsp;right&nbsp;away&nbsp;then&nbsp;one&nbsp;character&nbsp;will&nbsp;be&nbsp;returned&nbsp;immediately.&nbsp;<br>
 
456
available&nbsp;right&nbsp;away&nbsp;then&nbsp;one&nbsp;character&nbsp;will&nbsp;be&nbsp;returned&nbsp;immediately.<br>
272
457
It&nbsp;will&nbsp;not&nbsp;wait&nbsp;for&nbsp;30&nbsp;seconds&nbsp;for&nbsp;another&nbsp;99&nbsp;characters&nbsp;to&nbsp;come&nbsp;in.<br>
273
458
&nbsp;<br>
274
 
This&nbsp;is&nbsp;a&nbsp;wrapper&nbsp;around&nbsp;os.<a href="#pxssh-read">read</a>().<br>
275
 
It&nbsp;uses&nbsp;select.select()&nbsp;to&nbsp;implement&nbsp;a&nbsp;timeout.</tt></dd></dl>
276
 
 
277
 
<dl><dt><a name="pxssh-readline"><strong>readline</strong></a>(self, size<font color="#909090">=-1</font>)</dt><dd><tt>This&nbsp;reads&nbsp;and&nbsp;returns&nbsp;one&nbsp;entire&nbsp;line.&nbsp;A&nbsp;trailing&nbsp;newline&nbsp;is&nbsp;kept&nbsp;in<br>
278
 
the&nbsp;string,&nbsp;but&nbsp;may&nbsp;be&nbsp;absent&nbsp;when&nbsp;a&nbsp;file&nbsp;ends&nbsp;with&nbsp;an&nbsp;incomplete&nbsp;line.&nbsp;<br>
279
 
Note:&nbsp;This&nbsp;<a href="#pxssh-readline">readline</a>()&nbsp;looks&nbsp;for&nbsp;a&nbsp;\r\n&nbsp;pair&nbsp;even&nbsp;on&nbsp;UNIX&nbsp;because<br>
280
 
this&nbsp;is&nbsp;what&nbsp;the&nbsp;pseudo&nbsp;tty&nbsp;device&nbsp;returns.&nbsp;So&nbsp;contrary&nbsp;to&nbsp;what&nbsp;you<br>
281
 
may&nbsp;expect&nbsp;you&nbsp;will&nbsp;receive&nbsp;the&nbsp;newline&nbsp;as&nbsp;\r\n.<br>
282
 
An&nbsp;empty&nbsp;string&nbsp;is&nbsp;returned&nbsp;when&nbsp;EOF&nbsp;is&nbsp;hit&nbsp;immediately.<br>
283
 
Currently,&nbsp;the&nbsp;size&nbsp;agument&nbsp;is&nbsp;mostly&nbsp;ignored,&nbsp;so&nbsp;this&nbsp;behavior&nbsp;is&nbsp;not<br>
284
 
standard&nbsp;for&nbsp;a&nbsp;file-like&nbsp;object.&nbsp;If&nbsp;size&nbsp;is&nbsp;0&nbsp;then&nbsp;an&nbsp;empty&nbsp;string<br>
285
 
is&nbsp;returned.</tt></dd></dl>
286
 
 
287
 
<dl><dt><a name="pxssh-readlines"><strong>readlines</strong></a>(self, sizehint<font color="#909090">=-1</font>)</dt><dd><tt>This&nbsp;reads&nbsp;until&nbsp;EOF&nbsp;using&nbsp;<a href="#pxssh-readline">readline</a>()&nbsp;and&nbsp;returns&nbsp;a&nbsp;list&nbsp;containing&nbsp;<br>
 
459
This&nbsp;is&nbsp;a&nbsp;wrapper&nbsp;around&nbsp;os.<a href="#pxssh-read">read</a>().&nbsp;It&nbsp;uses&nbsp;select.select()&nbsp;to<br>
 
460
implement&nbsp;the&nbsp;timeout.</tt></dd></dl>
 
461
 
 
462
<dl><dt><a name="pxssh-readline"><strong>readline</strong></a>(self, size<font color="#909090">=-1</font>)</dt><dd><tt>This&nbsp;reads&nbsp;and&nbsp;returns&nbsp;one&nbsp;entire&nbsp;line.&nbsp;A&nbsp;trailing&nbsp;newline&nbsp;is&nbsp;kept<br>
 
463
in&nbsp;the&nbsp;string,&nbsp;but&nbsp;may&nbsp;be&nbsp;absent&nbsp;when&nbsp;a&nbsp;file&nbsp;ends&nbsp;with&nbsp;an&nbsp;incomplete<br>
 
464
line.&nbsp;Note:&nbsp;This&nbsp;<a href="#pxssh-readline">readline</a>()&nbsp;looks&nbsp;for&nbsp;a&nbsp;\r\n&nbsp;pair&nbsp;even&nbsp;on&nbsp;UNIX<br>
 
465
because&nbsp;this&nbsp;is&nbsp;what&nbsp;the&nbsp;pseudo&nbsp;tty&nbsp;device&nbsp;returns.&nbsp;So&nbsp;contrary&nbsp;to&nbsp;what<br>
 
466
you&nbsp;may&nbsp;expect&nbsp;you&nbsp;will&nbsp;receive&nbsp;the&nbsp;newline&nbsp;as&nbsp;\r\n.&nbsp;An&nbsp;empty&nbsp;string<br>
 
467
is&nbsp;returned&nbsp;when&nbsp;EOF&nbsp;is&nbsp;hit&nbsp;immediately.&nbsp;Currently,&nbsp;the&nbsp;size&nbsp;argument&nbsp;is<br>
 
468
mostly&nbsp;ignored,&nbsp;so&nbsp;this&nbsp;behavior&nbsp;is&nbsp;not&nbsp;standard&nbsp;for&nbsp;a&nbsp;file-like<br>
 
469
object.&nbsp;If&nbsp;size&nbsp;is&nbsp;0&nbsp;then&nbsp;an&nbsp;empty&nbsp;string&nbsp;is&nbsp;returned.</tt></dd></dl>
 
470
 
 
471
<dl><dt><a name="pxssh-readlines"><strong>readlines</strong></a>(self, sizehint<font color="#909090">=-1</font>)</dt><dd><tt>This&nbsp;reads&nbsp;until&nbsp;EOF&nbsp;using&nbsp;<a href="#pxssh-readline">readline</a>()&nbsp;and&nbsp;returns&nbsp;a&nbsp;list&nbsp;containing<br>
288
472
the&nbsp;lines&nbsp;thus&nbsp;read.&nbsp;The&nbsp;optional&nbsp;"sizehint"&nbsp;argument&nbsp;is&nbsp;ignored.</tt></dd></dl>
289
473
 
290
 
<dl><dt><a name="pxssh-send"><strong>send</strong></a>(self, str)</dt><dd><tt>This&nbsp;sends&nbsp;a&nbsp;string&nbsp;to&nbsp;the&nbsp;child&nbsp;process.<br>
291
 
This&nbsp;returns&nbsp;the&nbsp;number&nbsp;of&nbsp;bytes&nbsp;written.<br>
292
 
If&nbsp;a&nbsp;log&nbsp;file&nbsp;was&nbsp;set&nbsp;then&nbsp;the&nbsp;data&nbsp;is&nbsp;also&nbsp;written&nbsp;to&nbsp;the&nbsp;log.</tt></dd></dl>
293
 
 
294
 
<dl><dt><a name="pxssh-sendeof"><strong>sendeof</strong></a>(self)</dt><dd><tt>This&nbsp;sends&nbsp;an&nbsp;EOF&nbsp;to&nbsp;the&nbsp;child.<br>
295
 
This&nbsp;sends&nbsp;a&nbsp;character&nbsp;which&nbsp;causes&nbsp;the&nbsp;pending&nbsp;parent&nbsp;output<br>
296
 
buffer&nbsp;to&nbsp;be&nbsp;sent&nbsp;to&nbsp;the&nbsp;waiting&nbsp;child&nbsp;program&nbsp;without<br>
297
 
waiting&nbsp;for&nbsp;end-of-line.&nbsp;If&nbsp;it&nbsp;is&nbsp;the&nbsp;first&nbsp;character&nbsp;of&nbsp;the<br>
298
 
line,&nbsp;the&nbsp;<a href="#pxssh-read">read</a>()&nbsp;in&nbsp;the&nbsp;user&nbsp;program&nbsp;returns&nbsp;0,&nbsp;which<br>
299
 
signifies&nbsp;end-of-file.&nbsp;This&nbsp;means&nbsp;to&nbsp;work&nbsp;as&nbsp;expected&nbsp;<br>
300
 
a&nbsp;<a href="#pxssh-sendeof">sendeof</a>()&nbsp;has&nbsp;to&nbsp;be&nbsp;called&nbsp;at&nbsp;the&nbsp;begining&nbsp;of&nbsp;a&nbsp;line.&nbsp;<br>
301
 
This&nbsp;method&nbsp;does&nbsp;not&nbsp;send&nbsp;a&nbsp;newline.&nbsp;It&nbsp;is&nbsp;the&nbsp;responsibility<br>
302
 
of&nbsp;the&nbsp;caller&nbsp;to&nbsp;ensure&nbsp;the&nbsp;eof&nbsp;is&nbsp;sent&nbsp;at&nbsp;the&nbsp;beginning&nbsp;of&nbsp;a&nbsp;line.</tt></dd></dl>
303
 
 
304
 
<dl><dt><a name="pxssh-sendline"><strong>sendline</strong></a>(self, str<font color="#909090">=''</font>)</dt><dd><tt>This&nbsp;is&nbsp;like&nbsp;<a href="#pxssh-send">send</a>(),&nbsp;but&nbsp;it&nbsp;adds&nbsp;a&nbsp;line&nbsp;feed&nbsp;(os.linesep).<br>
305
 
This&nbsp;returns&nbsp;the&nbsp;number&nbsp;of&nbsp;bytes&nbsp;written.</tt></dd></dl>
306
 
 
307
 
<dl><dt><a name="pxssh-setecho"><strong>setecho</strong></a>(self, state)</dt><dd><tt>This&nbsp;sets&nbsp;the&nbsp;terminal&nbsp;echo&nbsp;mode&nbsp;on&nbsp;or&nbsp;off.<br>
308
 
Note&nbsp;that&nbsp;anything&nbsp;the&nbsp;child&nbsp;sent&nbsp;before&nbsp;the&nbsp;echo&nbsp;will&nbsp;be&nbsp;lost,&nbsp;so<br>
309
 
you&nbsp;should&nbsp;be&nbsp;sure&nbsp;that&nbsp;your&nbsp;input&nbsp;buffer&nbsp;is&nbsp;empty&nbsp;before&nbsp;you&nbsp;setecho.<br>
310
 
For&nbsp;example,&nbsp;the&nbsp;following&nbsp;will&nbsp;work&nbsp;as&nbsp;expected.<br>
 
474
<dl><dt><a name="pxssh-send"><strong>send</strong></a>(self, s)</dt><dd><tt>This&nbsp;sends&nbsp;a&nbsp;string&nbsp;to&nbsp;the&nbsp;child&nbsp;process.&nbsp;This&nbsp;returns&nbsp;the&nbsp;number&nbsp;of<br>
 
475
bytes&nbsp;written.&nbsp;If&nbsp;a&nbsp;log&nbsp;file&nbsp;was&nbsp;set&nbsp;then&nbsp;the&nbsp;data&nbsp;is&nbsp;also&nbsp;written&nbsp;to<br>
 
476
the&nbsp;log.</tt></dd></dl>
 
477
 
 
478
<dl><dt><a name="pxssh-sendcontrol"><strong>sendcontrol</strong></a>(self, char)</dt><dd><tt>This&nbsp;sends&nbsp;a&nbsp;control&nbsp;character&nbsp;to&nbsp;the&nbsp;child&nbsp;such&nbsp;as&nbsp;Ctrl-C&nbsp;or<br>
 
479
Ctrl-D.&nbsp;For&nbsp;example,&nbsp;to&nbsp;send&nbsp;a&nbsp;Ctrl-G&nbsp;(ASCII&nbsp;7)::<br>
 
480
&nbsp;<br>
 
481
&nbsp;&nbsp;&nbsp;&nbsp;child.<a href="#pxssh-sendcontrol">sendcontrol</a>('g')<br>
 
482
&nbsp;<br>
 
483
See&nbsp;also,&nbsp;<a href="#pxssh-sendintr">sendintr</a>()&nbsp;and&nbsp;<a href="#pxssh-sendeof">sendeof</a>().</tt></dd></dl>
 
484
 
 
485
<dl><dt><a name="pxssh-sendeof"><strong>sendeof</strong></a>(self)</dt><dd><tt>This&nbsp;sends&nbsp;an&nbsp;EOF&nbsp;to&nbsp;the&nbsp;child.&nbsp;This&nbsp;sends&nbsp;a&nbsp;character&nbsp;which&nbsp;causes<br>
 
486
the&nbsp;pending&nbsp;parent&nbsp;output&nbsp;buffer&nbsp;to&nbsp;be&nbsp;sent&nbsp;to&nbsp;the&nbsp;waiting&nbsp;child<br>
 
487
program&nbsp;without&nbsp;waiting&nbsp;for&nbsp;end-of-line.&nbsp;If&nbsp;it&nbsp;is&nbsp;the&nbsp;first&nbsp;character<br>
 
488
of&nbsp;the&nbsp;line,&nbsp;the&nbsp;<a href="#pxssh-read">read</a>()&nbsp;in&nbsp;the&nbsp;user&nbsp;program&nbsp;returns&nbsp;0,&nbsp;which&nbsp;signifies<br>
 
489
end-of-file.&nbsp;This&nbsp;means&nbsp;to&nbsp;work&nbsp;as&nbsp;expected&nbsp;a&nbsp;<a href="#pxssh-sendeof">sendeof</a>()&nbsp;has&nbsp;to&nbsp;be<br>
 
490
called&nbsp;at&nbsp;the&nbsp;beginning&nbsp;of&nbsp;a&nbsp;line.&nbsp;This&nbsp;method&nbsp;does&nbsp;not&nbsp;send&nbsp;a&nbsp;newline.<br>
 
491
It&nbsp;is&nbsp;the&nbsp;responsibility&nbsp;of&nbsp;the&nbsp;caller&nbsp;to&nbsp;ensure&nbsp;the&nbsp;eof&nbsp;is&nbsp;sent&nbsp;at&nbsp;the<br>
 
492
beginning&nbsp;of&nbsp;a&nbsp;line.</tt></dd></dl>
 
493
 
 
494
<dl><dt><a name="pxssh-sendintr"><strong>sendintr</strong></a>(self)</dt><dd><tt>This&nbsp;sends&nbsp;a&nbsp;SIGINT&nbsp;to&nbsp;the&nbsp;child.&nbsp;It&nbsp;does&nbsp;not&nbsp;require<br>
 
495
the&nbsp;SIGINT&nbsp;to&nbsp;be&nbsp;the&nbsp;first&nbsp;character&nbsp;on&nbsp;a&nbsp;line.</tt></dd></dl>
 
496
 
 
497
<dl><dt><a name="pxssh-sendline"><strong>sendline</strong></a>(self, s<font color="#909090">=''</font>)</dt><dd><tt>This&nbsp;is&nbsp;like&nbsp;<a href="#pxssh-send">send</a>(),&nbsp;but&nbsp;it&nbsp;adds&nbsp;a&nbsp;line&nbsp;feed&nbsp;(os.linesep).&nbsp;This<br>
 
498
returns&nbsp;the&nbsp;number&nbsp;of&nbsp;bytes&nbsp;written.</tt></dd></dl>
 
499
 
 
500
<dl><dt><a name="pxssh-setecho"><strong>setecho</strong></a>(self, state)</dt><dd><tt>This&nbsp;sets&nbsp;the&nbsp;terminal&nbsp;echo&nbsp;mode&nbsp;on&nbsp;or&nbsp;off.&nbsp;Note&nbsp;that&nbsp;anything&nbsp;the<br>
 
501
child&nbsp;sent&nbsp;before&nbsp;the&nbsp;echo&nbsp;will&nbsp;be&nbsp;lost,&nbsp;so&nbsp;you&nbsp;should&nbsp;be&nbsp;sure&nbsp;that<br>
 
502
your&nbsp;input&nbsp;buffer&nbsp;is&nbsp;empty&nbsp;before&nbsp;you&nbsp;call&nbsp;<a href="#pxssh-setecho">setecho</a>().&nbsp;For&nbsp;example,&nbsp;the<br>
 
503
following&nbsp;will&nbsp;work&nbsp;as&nbsp;expected::<br>
 
504
&nbsp;<br>
311
505
&nbsp;&nbsp;&nbsp;&nbsp;p&nbsp;=&nbsp;pexpect.<a href="pexpect.html#spawn">spawn</a>('cat')<br>
312
506
&nbsp;&nbsp;&nbsp;&nbsp;p.sendline&nbsp;('1234')&nbsp;#&nbsp;We&nbsp;will&nbsp;see&nbsp;this&nbsp;twice&nbsp;(once&nbsp;from&nbsp;tty&nbsp;echo&nbsp;and&nbsp;again&nbsp;from&nbsp;cat).<br>
313
507
&nbsp;&nbsp;&nbsp;&nbsp;p.expect&nbsp;(['1234'])<br>
317
511
&nbsp;&nbsp;&nbsp;&nbsp;p.sendline&nbsp;('wxyz')&nbsp;#&nbsp;We&nbsp;will&nbsp;set&nbsp;this&nbsp;only&nbsp;once&nbsp;(echoed&nbsp;by&nbsp;cat)<br>
318
512
&nbsp;&nbsp;&nbsp;&nbsp;p.expect&nbsp;(['abcd'])<br>
319
513
&nbsp;&nbsp;&nbsp;&nbsp;p.expect&nbsp;(['wxyz'])<br>
 
514
&nbsp;<br>
320
515
The&nbsp;following&nbsp;WILL&nbsp;NOT&nbsp;WORK&nbsp;because&nbsp;the&nbsp;lines&nbsp;sent&nbsp;before&nbsp;the&nbsp;setecho<br>
321
 
will&nbsp;be&nbsp;lost:<br>
 
516
will&nbsp;be&nbsp;lost::<br>
 
517
&nbsp;<br>
322
518
&nbsp;&nbsp;&nbsp;&nbsp;p&nbsp;=&nbsp;pexpect.<a href="pexpect.html#spawn">spawn</a>('cat')<br>
323
519
&nbsp;&nbsp;&nbsp;&nbsp;p.sendline&nbsp;('1234')&nbsp;#&nbsp;We&nbsp;will&nbsp;see&nbsp;this&nbsp;twice&nbsp;(once&nbsp;from&nbsp;tty&nbsp;echo&nbsp;and&nbsp;again&nbsp;from&nbsp;cat).<br>
324
520
&nbsp;&nbsp;&nbsp;&nbsp;p.<a href="#pxssh-setecho">setecho</a>(False)&nbsp;#&nbsp;Turn&nbsp;off&nbsp;tty&nbsp;echo<br>
331
527
 
332
528
<dl><dt><a name="pxssh-setlog"><strong>setlog</strong></a>(self, fileobject)</dt><dd><tt>This&nbsp;method&nbsp;is&nbsp;no&nbsp;longer&nbsp;supported&nbsp;or&nbsp;allowed.</tt></dd></dl>
333
529
 
334
 
<dl><dt><a name="pxssh-setmaxread"><strong>setmaxread</strong></a>(self, maxread)</dt><dd><tt>This&nbsp;method&nbsp;is&nbsp;no&nbsp;longer&nbsp;supported&nbsp;or&nbsp;allowed.<br>
335
 
I&nbsp;don't&nbsp;like&nbsp;getters&nbsp;and&nbsp;setters&nbsp;without&nbsp;a&nbsp;good&nbsp;reason.</tt></dd></dl>
336
 
 
337
 
<dl><dt><a name="pxssh-setwinsize"><strong>setwinsize</strong></a>(self, r, c)</dt><dd><tt>This&nbsp;sets&nbsp;the&nbsp;terminal&nbsp;window&nbsp;size&nbsp;of&nbsp;the&nbsp;child&nbsp;tty.<br>
338
 
This&nbsp;will&nbsp;cause&nbsp;a&nbsp;SIGWINCH&nbsp;signal&nbsp;to&nbsp;be&nbsp;sent&nbsp;to&nbsp;the&nbsp;child.<br>
339
 
This&nbsp;does&nbsp;not&nbsp;change&nbsp;the&nbsp;physical&nbsp;window&nbsp;size.<br>
340
 
It&nbsp;changes&nbsp;the&nbsp;size&nbsp;reported&nbsp;to&nbsp;TTY-aware&nbsp;applications&nbsp;like<br>
341
 
vi&nbsp;or&nbsp;curses&nbsp;--&nbsp;applications&nbsp;that&nbsp;respond&nbsp;to&nbsp;the&nbsp;SIGWINCH&nbsp;signal.</tt></dd></dl>
342
 
 
343
 
<dl><dt><a name="pxssh-terminate"><strong>terminate</strong></a>(self, force<font color="#909090">=False</font>)</dt><dd><tt>This&nbsp;forces&nbsp;a&nbsp;child&nbsp;process&nbsp;to&nbsp;terminate.<br>
344
 
It&nbsp;starts&nbsp;nicely&nbsp;with&nbsp;SIGHUP&nbsp;and&nbsp;SIGINT.&nbsp;If&nbsp;"force"&nbsp;is&nbsp;True&nbsp;then<br>
345
 
moves&nbsp;onto&nbsp;SIGKILL.<br>
346
 
This&nbsp;returns&nbsp;True&nbsp;if&nbsp;the&nbsp;child&nbsp;was&nbsp;terminated.<br>
347
 
This&nbsp;returns&nbsp;False&nbsp;if&nbsp;the&nbsp;child&nbsp;could&nbsp;not&nbsp;be&nbsp;terminated.</tt></dd></dl>
348
 
 
349
 
<dl><dt><a name="pxssh-wait"><strong>wait</strong></a>(self)</dt><dd><tt>This&nbsp;waits&nbsp;until&nbsp;the&nbsp;child&nbsp;exits.&nbsp;This&nbsp;is&nbsp;a&nbsp;blocking&nbsp;call.<br>
350
 
This&nbsp;will&nbsp;not&nbsp;read&nbsp;any&nbsp;data&nbsp;from&nbsp;the&nbsp;child,&nbsp;so&nbsp;this&nbsp;will&nbsp;block&nbsp;forever<br>
351
 
if&nbsp;the&nbsp;child&nbsp;has&nbsp;unread&nbsp;output&nbsp;and&nbsp;has&nbsp;terminated.&nbsp;In&nbsp;other&nbsp;words,&nbsp;the&nbsp;child<br>
352
 
may&nbsp;have&nbsp;printed&nbsp;output&nbsp;then&nbsp;called&nbsp;exit();&nbsp;but,&nbsp;technically,&nbsp;the&nbsp;child&nbsp;is<br>
353
 
still&nbsp;alive&nbsp;until&nbsp;its&nbsp;output&nbsp;is&nbsp;read.</tt></dd></dl>
354
 
 
355
 
<dl><dt><a name="pxssh-write"><strong>write</strong></a>(self, str)</dt><dd><tt>This&nbsp;is&nbsp;similar&nbsp;to&nbsp;<a href="#pxssh-send">send</a>()&nbsp;except&nbsp;that&nbsp;there&nbsp;is&nbsp;no&nbsp;return&nbsp;value.</tt></dd></dl>
356
 
 
357
 
<dl><dt><a name="pxssh-writelines"><strong>writelines</strong></a>(self, sequence)</dt><dd><tt>This&nbsp;calls&nbsp;<a href="#pxssh-write">write</a>()&nbsp;for&nbsp;each&nbsp;element&nbsp;in&nbsp;the&nbsp;sequence.<br>
358
 
The&nbsp;sequence&nbsp;can&nbsp;be&nbsp;any&nbsp;iterable&nbsp;object&nbsp;producing&nbsp;strings,&nbsp;<br>
359
 
typically&nbsp;a&nbsp;list&nbsp;of&nbsp;strings.&nbsp;This&nbsp;does&nbsp;not&nbsp;add&nbsp;line&nbsp;separators<br>
360
 
There&nbsp;is&nbsp;no&nbsp;return&nbsp;value.</tt></dd></dl>
 
530
<dl><dt><a name="pxssh-setmaxread"><strong>setmaxread</strong></a>(self, maxread)</dt><dd><tt>This&nbsp;method&nbsp;is&nbsp;no&nbsp;longer&nbsp;supported&nbsp;or&nbsp;allowed.&nbsp;I&nbsp;don't&nbsp;like&nbsp;getters<br>
 
531
and&nbsp;setters&nbsp;without&nbsp;a&nbsp;good&nbsp;reason.</tt></dd></dl>
 
532
 
 
533
<dl><dt><a name="pxssh-setwinsize"><strong>setwinsize</strong></a>(self, r, c)</dt><dd><tt>This&nbsp;sets&nbsp;the&nbsp;terminal&nbsp;window&nbsp;size&nbsp;of&nbsp;the&nbsp;child&nbsp;tty.&nbsp;This&nbsp;will&nbsp;cause<br>
 
534
a&nbsp;SIGWINCH&nbsp;signal&nbsp;to&nbsp;be&nbsp;sent&nbsp;to&nbsp;the&nbsp;child.&nbsp;This&nbsp;does&nbsp;not&nbsp;change&nbsp;the<br>
 
535
physical&nbsp;window&nbsp;size.&nbsp;It&nbsp;changes&nbsp;the&nbsp;size&nbsp;reported&nbsp;to&nbsp;TTY-aware<br>
 
536
applications&nbsp;like&nbsp;vi&nbsp;or&nbsp;curses&nbsp;--&nbsp;applications&nbsp;that&nbsp;respond&nbsp;to&nbsp;the<br>
 
537
SIGWINCH&nbsp;signal.</tt></dd></dl>
 
538
 
 
539
<dl><dt><a name="pxssh-terminate"><strong>terminate</strong></a>(self, force<font color="#909090">=False</font>)</dt><dd><tt>This&nbsp;forces&nbsp;a&nbsp;child&nbsp;process&nbsp;to&nbsp;terminate.&nbsp;It&nbsp;starts&nbsp;nicely&nbsp;with<br>
 
540
SIGHUP&nbsp;and&nbsp;SIGINT.&nbsp;If&nbsp;"force"&nbsp;is&nbsp;True&nbsp;then&nbsp;moves&nbsp;onto&nbsp;SIGKILL.&nbsp;This<br>
 
541
returns&nbsp;True&nbsp;if&nbsp;the&nbsp;child&nbsp;was&nbsp;terminated.&nbsp;This&nbsp;returns&nbsp;False&nbsp;if&nbsp;the<br>
 
542
child&nbsp;could&nbsp;not&nbsp;be&nbsp;terminated.</tt></dd></dl>
 
543
 
 
544
<dl><dt><a name="pxssh-wait"><strong>wait</strong></a>(self)</dt><dd><tt>This&nbsp;waits&nbsp;until&nbsp;the&nbsp;child&nbsp;exits.&nbsp;This&nbsp;is&nbsp;a&nbsp;blocking&nbsp;call.&nbsp;This&nbsp;will<br>
 
545
not&nbsp;read&nbsp;any&nbsp;data&nbsp;from&nbsp;the&nbsp;child,&nbsp;so&nbsp;this&nbsp;will&nbsp;block&nbsp;forever&nbsp;if&nbsp;the<br>
 
546
child&nbsp;has&nbsp;unread&nbsp;output&nbsp;and&nbsp;has&nbsp;terminated.&nbsp;In&nbsp;other&nbsp;words,&nbsp;the&nbsp;child<br>
 
547
may&nbsp;have&nbsp;printed&nbsp;output&nbsp;then&nbsp;called&nbsp;exit();&nbsp;but,&nbsp;technically,&nbsp;the&nbsp;child<br>
 
548
is&nbsp;still&nbsp;alive&nbsp;until&nbsp;its&nbsp;output&nbsp;is&nbsp;read.</tt></dd></dl>
 
549
 
 
550
<dl><dt><a name="pxssh-waitnoecho"><strong>waitnoecho</strong></a>(self, timeout<font color="#909090">=-1</font>)</dt><dd><tt>This&nbsp;waits&nbsp;until&nbsp;the&nbsp;terminal&nbsp;ECHO&nbsp;flag&nbsp;is&nbsp;set&nbsp;False.&nbsp;This&nbsp;returns<br>
 
551
True&nbsp;if&nbsp;the&nbsp;echo&nbsp;mode&nbsp;is&nbsp;off.&nbsp;This&nbsp;returns&nbsp;False&nbsp;if&nbsp;the&nbsp;ECHO&nbsp;flag&nbsp;was<br>
 
552
not&nbsp;set&nbsp;False&nbsp;before&nbsp;the&nbsp;timeout.&nbsp;This&nbsp;can&nbsp;be&nbsp;used&nbsp;to&nbsp;detect&nbsp;when&nbsp;the<br>
 
553
child&nbsp;is&nbsp;waiting&nbsp;for&nbsp;a&nbsp;password.&nbsp;Usually&nbsp;a&nbsp;child&nbsp;application&nbsp;will&nbsp;turn<br>
 
554
off&nbsp;echo&nbsp;mode&nbsp;when&nbsp;it&nbsp;is&nbsp;waiting&nbsp;for&nbsp;the&nbsp;user&nbsp;to&nbsp;enter&nbsp;a&nbsp;password.&nbsp;For<br>
 
555
example,&nbsp;instead&nbsp;of&nbsp;expecting&nbsp;the&nbsp;"password:"&nbsp;prompt&nbsp;you&nbsp;can&nbsp;wait&nbsp;for<br>
 
556
the&nbsp;child&nbsp;to&nbsp;set&nbsp;ECHO&nbsp;off::<br>
 
557
&nbsp;<br>
 
558
&nbsp;&nbsp;&nbsp;&nbsp;p&nbsp;=&nbsp;pexpect.<a href="pexpect.html#spawn">spawn</a>&nbsp;('ssh&nbsp;user@example.com')<br>
 
559
&nbsp;&nbsp;&nbsp;&nbsp;p.<a href="#pxssh-waitnoecho">waitnoecho</a>()<br>
 
560
&nbsp;&nbsp;&nbsp;&nbsp;p.<a href="#pxssh-sendline">sendline</a>(mypassword)<br>
 
561
&nbsp;<br>
 
562
If&nbsp;timeout&nbsp;is&nbsp;None&nbsp;then&nbsp;this&nbsp;method&nbsp;to&nbsp;block&nbsp;forever&nbsp;until&nbsp;ECHO&nbsp;flag&nbsp;is<br>
 
563
False.</tt></dd></dl>
 
564
 
 
565
<dl><dt><a name="pxssh-write"><strong>write</strong></a>(self, s)</dt><dd><tt>This&nbsp;is&nbsp;similar&nbsp;to&nbsp;<a href="#pxssh-send">send</a>()&nbsp;except&nbsp;that&nbsp;there&nbsp;is&nbsp;no&nbsp;return&nbsp;value.</tt></dd></dl>
 
566
 
 
567
<dl><dt><a name="pxssh-writelines"><strong>writelines</strong></a>(self, sequence)</dt><dd><tt>This&nbsp;calls&nbsp;<a href="#pxssh-write">write</a>()&nbsp;for&nbsp;each&nbsp;element&nbsp;in&nbsp;the&nbsp;sequence.&nbsp;The&nbsp;sequence<br>
 
568
can&nbsp;be&nbsp;any&nbsp;iterable&nbsp;object&nbsp;producing&nbsp;strings,&nbsp;typically&nbsp;a&nbsp;list&nbsp;of<br>
 
569
strings.&nbsp;This&nbsp;does&nbsp;not&nbsp;add&nbsp;line&nbsp;separators&nbsp;There&nbsp;is&nbsp;no&nbsp;return&nbsp;value.</tt></dd></dl>
361
570
 
362
571
<hr>
363
 
Data and other attributes inherited from <a href="pexpect.html#spawn">pexpect.spawn</a>:<br>
364
 
<dl><dt><strong>__dict__</strong> = &lt;dictproxy object&gt;<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dl>
365
 
 
366
 
<dl><dt><strong>__weakref__</strong> = &lt;attribute '__weakref__' of 'spawn' objects&gt;<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dl>
367
 
 
 
572
Data descriptors inherited from <a href="pexpect.html#spawn">pexpect.spawn</a>:<br>
 
573
<dl><dt><strong>__dict__</strong></dt>
 
574
<dd><tt>dictionary&nbsp;for&nbsp;instance&nbsp;variables&nbsp;(if&nbsp;defined)</tt></dd>
 
575
</dl>
 
576
<dl><dt><strong>__weakref__</strong></dt>
 
577
<dd><tt>list&nbsp;of&nbsp;weak&nbsp;references&nbsp;to&nbsp;the&nbsp;object&nbsp;(if&nbsp;defined)</tt></dd>
 
578
</dl>
368
579
</td></tr></table></td></tr></table><p>
369
580
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
370
581
<tr bgcolor="#55aa55">
372
583
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
373
584
    
374
585
<tr><td bgcolor="#55aa55"><tt>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</tt></td><td>&nbsp;</td>
375
 
<td width="100%"><strong>__revision__</strong> = '$Revision: 395 $'<br>
376
 
<strong>__version__</strong> = '2.1'</td></tr></table>
 
586
<td width="100%"><strong>__all__</strong> = ['ExceptionPxssh', 'pxssh']<br>
 
587
<strong>__revision__</strong> = '$Revision: 399 $'<br>
 
588
<strong>__version__</strong> = '2.3'</td></tr></table>
377
589
</body></html>
 
 
b'\\ No newline at end of file'