robotframework-telnetlibrary 1.0.0__tar.gz → 1.0.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {robotframework_telnetlibrary-1.0.0/src/robotframework_telnetlibrary.egg-info → robotframework_telnetlibrary-1.0.2}/PKG-INFO +1 -1
- {robotframework_telnetlibrary-1.0.0 → robotframework_telnetlibrary-1.0.2}/pyproject.toml +1 -1
- {robotframework_telnetlibrary-1.0.0 → robotframework_telnetlibrary-1.0.2}/src/TelnetLibrary.py +514 -319
- {robotframework_telnetlibrary-1.0.0 → robotframework_telnetlibrary-1.0.2/src/robotframework_telnetlibrary.egg-info}/PKG-INFO +1 -1
- {robotframework_telnetlibrary-1.0.0 → robotframework_telnetlibrary-1.0.2}/LICENSE +0 -0
- {robotframework_telnetlibrary-1.0.0 → robotframework_telnetlibrary-1.0.2}/README.md +0 -0
- {robotframework_telnetlibrary-1.0.0 → robotframework_telnetlibrary-1.0.2}/setup.cfg +0 -0
- {robotframework_telnetlibrary-1.0.0 → robotframework_telnetlibrary-1.0.2}/src/robotframework_telnetlibrary.egg-info/SOURCES.txt +0 -0
- {robotframework_telnetlibrary-1.0.0 → robotframework_telnetlibrary-1.0.2}/src/robotframework_telnetlibrary.egg-info/dependency_links.txt +0 -0
- {robotframework_telnetlibrary-1.0.0 → robotframework_telnetlibrary-1.0.2}/src/robotframework_telnetlibrary.egg-info/requires.txt +0 -0
- {robotframework_telnetlibrary-1.0.0 → robotframework_telnetlibrary-1.0.2}/src/robotframework_telnetlibrary.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: robotframework-telnetlibrary
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.2
|
|
4
4
|
Summary: A Robot Framework library for communication via Telnet protocol
|
|
5
5
|
Maintainer-email: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/MarketSquare/robotframework-telnet-library
|
{robotframework_telnetlibrary-1.0.0 → robotframework_telnetlibrary-1.0.2}/src/TelnetLibrary.py
RENAMED
|
@@ -29,243 +29,257 @@ from robot.utils import (ConnectionCache, is_bytes, is_string, is_truthy,
|
|
|
29
29
|
|
|
30
30
|
|
|
31
31
|
class TelnetLibrary:
|
|
32
|
-
"""A library providing communication over Telnet connections.
|
|
32
|
+
r"""A library providing communication over Telnet connections.
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
connect to Telnet servers and execute commands on the opened connections
|
|
34
|
+
TelnetLibrary is Robot Framework's library that makes it possible to
|
|
35
|
+
connect to Telnet servers and execute commands on the opened connections
|
|
36
|
+
with or without terminal emulation.
|
|
36
37
|
|
|
37
|
-
|
|
38
|
+
This library used to be known as the Telnet standard library of Robot
|
|
39
|
+
Framework until it was extracted out of it as a standalone extension.
|
|
40
|
+
|
|
41
|
+
### Table of contents
|
|
38
42
|
|
|
39
43
|
%TOC%
|
|
40
44
|
|
|
41
|
-
|
|
45
|
+
# Dependencies
|
|
46
|
+
|
|
47
|
+
TelnetLibrary uses the [telnetlib] module internally. This module was part
|
|
48
|
+
of the Python standard library until Python 3.12, but with newer versions
|
|
49
|
+
the [telnetlib-313-and-up] package needs to be installed to provide it.
|
|
50
|
+
The [pyte] module is used for [terminal emulation].
|
|
42
51
|
|
|
43
|
-
|
|
44
|
-
Connection` keyword. Typically the next step is logging in with `Login`
|
|
45
|
-
keyword, and in the end the opened connection can be closed with `Close
|
|
46
|
-
Connection`.
|
|
52
|
+
# Connections
|
|
47
53
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
54
|
+
The first step of using TelnetLibrary is opening a connection with the [Open
|
|
55
|
+
Connection] keyword. Typically, the next step is logging in with the
|
|
56
|
+
[Login] keyword, and in the end the opened connection can be closed with
|
|
57
|
+
the [Close Connection] keyword.
|
|
52
58
|
|
|
53
|
-
|
|
59
|
+
It is possible to open multiple connections and switch the active one using
|
|
60
|
+
the [Switch Connection] keyword. The [Close All Connections] keyword can be
|
|
61
|
+
used to close all the connections, which is especially useful in suite
|
|
62
|
+
teardowns to guarantee that all connections are always closed.
|
|
63
|
+
|
|
64
|
+
# Writing and reading
|
|
54
65
|
|
|
55
66
|
After opening a connection and possibly logging in, commands can be
|
|
56
|
-
executed or text written to the connection for other reasons using
|
|
57
|
-
and
|
|
58
|
-
the former adds a
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
`Write Until Expected Output` is useful if you need to wait until writing
|
|
67
|
+
executed or text written to the connection for other reasons using the
|
|
68
|
+
[Write] and [Write Bare] keywords. The main difference between them is that
|
|
69
|
+
the former adds a newline after the text automatically.
|
|
70
|
+
|
|
71
|
+
After writing something to the connection, the resulting output can be read
|
|
72
|
+
using the [Read], [Read Until], [Read Until Regexp], and [Read Until Prompt]
|
|
73
|
+
keywords. Which one to use depends on the context, but the latest one is
|
|
74
|
+
often the most convenient.
|
|
75
|
+
|
|
76
|
+
As a convenience when running a command, it is possible to use
|
|
77
|
+
[Execute Command] that simply uses [Write] and [Read Until Prompt] internally.
|
|
78
|
+
[Write Until Expected Output] is useful if you need to wait until writing
|
|
69
79
|
something produces a desired output.
|
|
70
80
|
|
|
71
|
-
Written and read text is automatically encoded
|
|
72
|
-
|
|
81
|
+
Written and read text is automatically encoded and decoded using the
|
|
82
|
+
configured [encoding].
|
|
73
83
|
|
|
74
|
-
The ANSI escape codes, like cursor movement and color codes, are
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
84
|
+
The ANSI escape codes, like cursor movement and color codes, are normally
|
|
85
|
+
returned as part of the read operation. If an escape code occurs in the
|
|
86
|
+
middle of a search pattern, it may prevent finding the searched string.
|
|
87
|
+
[Terminal emulation] can be used to process these escape codes as they
|
|
88
|
+
would be if a real terminal would be in use.
|
|
79
89
|
|
|
80
|
-
|
|
90
|
+
# Configuration
|
|
81
91
|
|
|
82
92
|
Many aspects related the connections can be easily configured either
|
|
83
93
|
globally or per connection basis. Global configuration is done when
|
|
84
|
-
[
|
|
85
|
-
connection by
|
|
86
|
-
|
|
87
|
-
|
|
94
|
+
[importing] the library, and these values can be overridden per
|
|
95
|
+
connection by [Open Connection] or with setting specific keywords
|
|
96
|
+
[Set Timeout], [Set Newline], [Set Prompt], [Set Encoding],
|
|
97
|
+
[Set Default Log Level] and [Set Telnetlib Log Level].
|
|
88
98
|
|
|
89
|
-
Values of
|
|
90
|
-
|
|
99
|
+
Values of `environ_user`, `window_size`, `terminal_emulation`, and
|
|
100
|
+
`terminal_type` can not be changed after opening the connection.
|
|
91
101
|
|
|
92
|
-
|
|
102
|
+
## Timeout
|
|
93
103
|
|
|
94
104
|
Timeout defines how long is the maximum time to wait when reading
|
|
95
|
-
output. It is used internally by
|
|
96
|
-
|
|
105
|
+
output. It is used internally by [Read Until], [Read Until Regexp],
|
|
106
|
+
[Read Until Prompt], and [Login] keywords. The default value is 3 seconds.
|
|
97
107
|
|
|
98
|
-
|
|
108
|
+
## Connection timeout
|
|
99
109
|
|
|
100
110
|
Connection Timeout defines how long is the maximum time to wait when
|
|
101
|
-
opening the telnet connection. It is used internally by
|
|
111
|
+
opening the telnet connection. It is used internally by [Open Connection].
|
|
102
112
|
The default value is the system global default timeout.
|
|
103
113
|
|
|
104
|
-
|
|
114
|
+
## Newline
|
|
105
115
|
|
|
106
|
-
Newline defines which line separator
|
|
107
|
-
default value is
|
|
116
|
+
Newline defines which line separator [Write] keyword should use. The
|
|
117
|
+
default value is `CRLF` that is typically used by Telnet connections.
|
|
108
118
|
|
|
109
|
-
Newline can be given either in escaped format using
|
|
110
|
-
with special
|
|
119
|
+
Newline can be given either in escaped format using `\n` and `\r` or
|
|
120
|
+
with special `LF` and `CR` syntax.
|
|
111
121
|
|
|
112
122
|
Examples:
|
|
113
|
-
| `Set Newline` | \\n |
|
|
114
|
-
| `Set Newline` | CRLF |
|
|
115
123
|
|
|
116
|
-
|
|
124
|
+
```robotframework
|
|
125
|
+
*** Test Cases ***
|
|
126
|
+
Newline
|
|
127
|
+
Set Newline \n
|
|
128
|
+
Set Newline CRLF
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Prompt
|
|
117
132
|
|
|
118
133
|
Often the easiest way to read the output of a command is reading all
|
|
119
|
-
the output until the next prompt with
|
|
120
|
-
it easier, and faster, to verify did
|
|
134
|
+
the output until the next prompt with the [Read Until Prompt] keyword.
|
|
135
|
+
The prompt also makes it easier, and faster, to verify did [Login] succeed.
|
|
121
136
|
|
|
122
137
|
Prompt can be specified either as a normal string or a regular expression.
|
|
123
138
|
The latter is especially useful if the prompt changes as a result of
|
|
124
139
|
the executed commands. Prompt can be set to be a regular expression
|
|
125
|
-
by giving
|
|
126
|
-
arguments`).
|
|
140
|
+
by giving `prompt_is_regexp` argument a true value.
|
|
127
141
|
|
|
128
142
|
Examples:
|
|
129
|
-
| `Open Connection` | lolcathost | prompt=$ |
|
|
130
|
-
| `Set Prompt` | (> |# ) | prompt_is_regexp=true |
|
|
131
143
|
|
|
132
|
-
|
|
144
|
+
```robotframework
|
|
145
|
+
*** Test Cases ***
|
|
146
|
+
Prompt
|
|
147
|
+
Open Connection lolcathost prompt=$
|
|
148
|
+
Set Prompt (> |# ) prompt_is_regexp=True
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
## Encoding
|
|
133
152
|
|
|
134
153
|
To ease handling text containing non-ASCII characters, all written text is
|
|
135
154
|
encoded and read text decoded by default. The default encoding is UTF-8
|
|
136
155
|
that works also with ASCII. Encoding can be disabled by using a special
|
|
137
|
-
encoding value
|
|
156
|
+
encoding value `NONE`. This is mainly useful if you need to get the bytes
|
|
138
157
|
received from the connection as-is.
|
|
139
158
|
|
|
140
159
|
Notice that when writing to the connection, only Unicode strings are
|
|
141
160
|
encoded using the defined encoding. Byte strings are expected to be already
|
|
142
|
-
encoded correctly. Notice also that normal text in data is passed to
|
|
143
|
-
|
|
161
|
+
encoded correctly. Notice also that normal text in data is passed to the
|
|
162
|
+
library as Unicode strings, and you need to use variables to use bytes.
|
|
144
163
|
|
|
145
164
|
It is also possible to configure the error handler to use if encoding or
|
|
146
165
|
decoding characters fails. Accepted values are the same that encode/decode
|
|
147
166
|
functions in Python strings accept. In practice the following values are
|
|
148
167
|
the most useful:
|
|
149
168
|
|
|
150
|
-
-
|
|
151
|
-
-
|
|
152
|
-
-
|
|
169
|
+
- `ignore`: ignore characters that cannot be encoded (default)
|
|
170
|
+
- `strict`: fail if characters cannot be encoded
|
|
171
|
+
- `replace`: replace characters that cannot be encoded with a replacement
|
|
153
172
|
character
|
|
154
173
|
|
|
155
174
|
Examples:
|
|
156
|
-
| `Open Connection` | lolcathost | encoding=Latin1 | encoding_errors=strict |
|
|
157
|
-
| `Set Encoding` | ISO-8859-15 |
|
|
158
|
-
| `Set Encoding` | errors=ignore |
|
|
159
175
|
|
|
160
|
-
|
|
176
|
+
```robotframework
|
|
177
|
+
*** Test Cases ***
|
|
178
|
+
Open connection
|
|
179
|
+
Open Connection lolcathost encoding=Latin1 encoding_errors=strict
|
|
180
|
+
Set Encoding ISO-8859-15
|
|
181
|
+
Set Encoding errors=ignore
|
|
182
|
+
```
|
|
183
|
+
|
|
184
|
+
## Default log level
|
|
161
185
|
|
|
162
|
-
Default log level specifies the log level keywords use for
|
|
163
|
-
they are given an explicit log level. The default value is
|
|
164
|
-
changing it, for example, to
|
|
186
|
+
Default log level specifies the log level keywords use for [logging] unless
|
|
187
|
+
they are given an explicit log level. The default value is `INFO`, and
|
|
188
|
+
changing it, for example, to `DEBUG` can be a good idea if there is a lot
|
|
165
189
|
of unnecessary output that makes log files big.
|
|
166
190
|
|
|
167
|
-
|
|
191
|
+
## Terminal type
|
|
168
192
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
desired, the terminal type can be configured
|
|
172
|
-
|
|
193
|
+
TelnetLibrary does not negotiate any specific terminal type with the
|
|
194
|
+
server by default. If a specific terminal type, for example `vt100`, is
|
|
195
|
+
desired, the terminal type can be configured when [importing] the library
|
|
196
|
+
or with the [Open Connection] keyword.
|
|
173
197
|
|
|
174
|
-
|
|
198
|
+
## Window size
|
|
175
199
|
|
|
176
200
|
Window size for negotiation with the server can be configured when
|
|
177
|
-
|
|
201
|
+
[importing] the library and with the [Open Connection] keyword.
|
|
178
202
|
|
|
179
|
-
|
|
203
|
+
## `USER` environment variable
|
|
180
204
|
|
|
181
|
-
Telnet protocol allows the
|
|
205
|
+
Telnet protocol allows the `USER` environment variable to be sent when
|
|
182
206
|
connecting to the server. On some servers it may happen that there is no
|
|
183
207
|
login prompt, and on those cases this configuration option will allow still
|
|
184
|
-
to define the desired username. The
|
|
185
|
-
|
|
208
|
+
to define the desired username. The `environ_user` argument can be used when
|
|
209
|
+
[importing] the library and with the [Open Connection] keyword.
|
|
186
210
|
|
|
187
|
-
|
|
211
|
+
# Terminal emulation
|
|
188
212
|
|
|
189
|
-
TelnetLibrary supports terminal
|
|
190
|
-
emulation
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
``acdc\\x1b[3Dbba`` will result in output ``abba``.
|
|
213
|
+
TelnetLibrary supports terminal emulation by using the [pyte] module.
|
|
214
|
+
Terminal emulation will process the output in a virtual screen. This means
|
|
215
|
+
that ANSI escape codes, like cursor movements, and also control characters,
|
|
216
|
+
like carriage returns and backspaces, have the same effect on the result as
|
|
217
|
+
they would have on a normal terminal screen. For example the sequence
|
|
218
|
+
`acdc\x1b[3Dbba` will result in output `abba`.
|
|
196
219
|
|
|
197
|
-
Terminal emulation is taken into use by giving
|
|
198
|
-
argument a true value
|
|
199
|
-
|
|
220
|
+
Terminal emulation is taken into use by giving the `terminal_emulation`
|
|
221
|
+
argument a true value either when [importing] the library or with the
|
|
222
|
+
[Open Connection] keyword.
|
|
200
223
|
|
|
201
|
-
As
|
|
202
|
-
terminal type
|
|
224
|
+
As `pyte` approximates vt-style terminal, you may also want to set the
|
|
225
|
+
terminal type to `vt100`. We also recommend that you increase the window
|
|
203
226
|
size, as the terminal emulation will break all lines that are longer than
|
|
204
227
|
the window row length.
|
|
205
228
|
|
|
206
|
-
When terminal emulation is used, the
|
|
229
|
+
When terminal emulation is used, the newline and encoding can not be
|
|
207
230
|
changed anymore after opening the connection.
|
|
208
231
|
|
|
209
232
|
Examples:
|
|
210
|
-
| `Open Connection` | localhost | terminal_emulation=True | terminal_type=vt100 | window_size=400x100 |
|
|
211
233
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
234
|
+
```robotframework
|
|
235
|
+
*** Test Cases ***
|
|
236
|
+
Open connection
|
|
237
|
+
Open Connection lolcathost terminal_emulation=True terminal_type=vt100 window_size=400x100
|
|
238
|
+
```
|
|
215
239
|
|
|
216
|
-
|
|
240
|
+
# Logging
|
|
217
241
|
|
|
218
242
|
All keywords that read something log the output. These keywords take the
|
|
219
243
|
log level to use as an optional argument, and if no log level is specified
|
|
220
|
-
they use the
|
|
244
|
+
they use the configured default value.
|
|
221
245
|
|
|
222
|
-
The valid log levels to use are
|
|
223
|
-
and
|
|
246
|
+
The valid log levels to use are `TRACE`, `DEBUG`, `INFO` (default),
|
|
247
|
+
and `WARN`. Levels below `INFO` are not shown in log files by default
|
|
224
248
|
whereas warnings are shown more prominently.
|
|
225
249
|
|
|
226
|
-
The [
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
connection. Special level ``NONE`` con be used to disable the logging
|
|
233
|
-
altogether.
|
|
250
|
+
The [telnetlib] used by this library has a custom logging system for
|
|
251
|
+
logging content it sends and receives. These messages are written using
|
|
252
|
+
the `TRACE` level by default, but the level is configurable with the
|
|
253
|
+
`telnetlib_log_level` argument when [importing] the library, with
|
|
254
|
+
the [Open Connection] keyword and by using the [Set Telnetlib Log Level]
|
|
255
|
+
keyword. Special level `NONE` can be used to disable logging altogether.
|
|
234
256
|
|
|
235
|
-
|
|
257
|
+
# Time string format
|
|
236
258
|
|
|
237
259
|
Timeouts and other times used must be given as a time string using format
|
|
238
|
-
like
|
|
239
|
-
a number, for example,
|
|
260
|
+
like `15 seconds` or `1min 10s`. If the timeout is given as just
|
|
261
|
+
a number, for example, `10` or `1.5`, it is considered to be seconds.
|
|
240
262
|
The time string format is described in more detail in an appendix of
|
|
241
|
-
[
|
|
263
|
+
[Robot Framework User Guide].
|
|
242
264
|
|
|
243
|
-
|
|
265
|
+
# Boolean arguments
|
|
244
266
|
|
|
245
267
|
Some keywords accept arguments that are handled as Boolean values true or
|
|
246
268
|
false. If such an argument is given as a string, it is considered false if
|
|
247
|
-
it is an empty string or equal to
|
|
248
|
-
|
|
249
|
-
their value, and other
|
|
250
|
-
[
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
False examples:
|
|
259
|
-
| `Open Connection` | lolcathost | terminal_emulation=False | # String ``false`` is false. |
|
|
260
|
-
| `Open Connection` | lolcathost | terminal_emulation=no | # Also string ``no`` is false. |
|
|
261
|
-
| `Open Connection` | lolcathost | terminal_emulation=${EMPTY} | # Empty string is false. |
|
|
262
|
-
| `Open Connection` | lolcathost | terminal_emulation=${FALSE} | # Python ``False`` is false. |
|
|
263
|
-
|
|
264
|
-
Considering string ``NONE`` false is new in Robot Framework 3.0.3 and
|
|
265
|
-
considering also ``OFF`` and ``0`` false is new in Robot Framework 3.1.
|
|
269
|
+
it is an empty string or equal to `FALSE`, `NONE`, `NO`, `OFF` or
|
|
270
|
+
`0`, case-insensitively. Other strings are considered true regardless
|
|
271
|
+
their value, and other values are considered true or false based on their
|
|
272
|
+
[truth value](https://docs.python.org/library/stdtypes.html#truth).
|
|
273
|
+
|
|
274
|
+
[telnetlib-313-and-up]: https://pypi.org/project/telnetlib-313-and-up
|
|
275
|
+
[pyte]: https://pyte.readthedocs.io
|
|
276
|
+
[telnetlib]: https://docs.python.org/library/telnetlib.html
|
|
277
|
+
[re]: https://docs.python.org/library/re.html
|
|
278
|
+
[Robot Framework User Guide]: https://robotframework.org/robotframework/#user-guide
|
|
266
279
|
"""
|
|
267
280
|
ROBOT_LIBRARY_SCOPE = 'SUITE'
|
|
268
|
-
|
|
281
|
+
ROBOT_LIBRARY_DOC_FORMAT = 'Markdown'
|
|
282
|
+
ROBOT_LIBRARY_VERSION = '1.0.2'
|
|
269
283
|
|
|
270
284
|
def __init__(self, timeout='3 seconds', newline='CRLF',
|
|
271
285
|
prompt=None, prompt_is_regexp=False,
|
|
@@ -274,28 +288,43 @@ class TelnetLibrary:
|
|
|
274
288
|
environ_user=None, terminal_emulation=False,
|
|
275
289
|
terminal_type=None, telnetlib_log_level='TRACE',
|
|
276
290
|
connection_timeout=None):
|
|
277
|
-
"""TelnetLibrary can be imported with optional configuration parameters.
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
291
|
+
r"""TelnetLibrary can be imported with optional configuration parameters.
|
|
292
|
+
|
|
293
|
+
Args:
|
|
294
|
+
timeout: Default timeout used when reading output.
|
|
295
|
+
newline: Default newline used by [Write].
|
|
296
|
+
prompt: Default prompt used by [Read Until Prompt] and [Login].
|
|
297
|
+
prompt_is_regexp: When true, the prompt is considered to be
|
|
298
|
+
a regular expression by default.
|
|
299
|
+
encoding: Default encoding used for writing and reading.
|
|
300
|
+
encoding_errors: Default error handler used with encoding.
|
|
301
|
+
default_log_level: Default log level used for logging.
|
|
302
|
+
window_size: Default terminal window size for negotiation.
|
|
303
|
+
environ_user: Default `USER` environment variable value.
|
|
304
|
+
terminal_emulation: When true, [terminal emulation] is enabled
|
|
305
|
+
by default.
|
|
306
|
+
terminal_type: Default terminal type for negotiation.
|
|
307
|
+
telnetlib_log_level: Default log level for the underlying `telnetlib`.
|
|
308
|
+
connection_timeout: Default timeout used when opening connections.
|
|
309
|
+
|
|
310
|
+
Configuration parameters are used as default values when new connections
|
|
311
|
+
are opened with the [Open Connection] keyword. They can also be overridden
|
|
312
|
+
after opening the connection using the [Set Timeout], [Set Newline],
|
|
313
|
+
[Set Prompt], [Set Encoding], [Set Default Log Level] and [Set Telnetlib
|
|
314
|
+
Log Level] keywords. See these keywords as well as [Configuration],
|
|
315
|
+
[Terminal emulation] and [Logging] sections above for more information
|
|
316
|
+
about these parameters and their possible values.
|
|
317
|
+
|
|
318
|
+
See the [Time string format] and [Boolean arguments] sections for
|
|
287
319
|
information about using arguments accepting times and Boolean values,
|
|
288
320
|
respectively.
|
|
289
321
|
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
| Library | TelnetLibrary | prompt=(> |# ) | prompt_is_regexp=yes | | # set prompt as a regular expression |
|
|
297
|
-
| Library | TelnetLibrary | terminal_emulation=True | terminal_type=vt100 | window_size=400x100 | # use terminal emulation with defined window size and terminal type |
|
|
298
|
-
| Library | TelnetLibrary | telnetlib_log_level=NONE | | | # disable logging messages from the underlying telnetlib |
|
|
322
|
+
Example:
|
|
323
|
+
|
|
324
|
+
```robotframework
|
|
325
|
+
*** Settings ***
|
|
326
|
+
Library TelnetLibrary newline=LF encoding=ISO-8859-1
|
|
327
|
+
```
|
|
299
328
|
"""
|
|
300
329
|
self._timeout = timeout or 3.0
|
|
301
330
|
self._set_connection_timeout(connection_timeout)
|
|
@@ -357,19 +386,41 @@ class TelnetLibrary:
|
|
|
357
386
|
connection_timeout=None):
|
|
358
387
|
"""Opens a new Telnet connection to the given host and port.
|
|
359
388
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
389
|
+
Args:
|
|
390
|
+
host: Host name or IP address of the Telnet server.
|
|
391
|
+
alias: Optional alias for the opened connection.
|
|
392
|
+
port: Port of the Telnet server.
|
|
393
|
+
timeout: Timeout used when reading output.
|
|
394
|
+
newline: Newline used by [Write].
|
|
395
|
+
prompt: Prompt used by [Read Until Prompt] and [Login].
|
|
396
|
+
prompt_is_regexp: When true, the problem is considered to be a regular
|
|
397
|
+
expression.
|
|
398
|
+
encoding: Encoding used for writing and reading.
|
|
399
|
+
encoding_errors: Error handler used with encoding.
|
|
400
|
+
default_log_level: Default log level used for logging.
|
|
401
|
+
window_size: Terminal window size for negotiation.
|
|
402
|
+
environ_user: Value for the `USER` environment variable.
|
|
403
|
+
terminal_emulation: When true, [terminal emulation] is enabled.
|
|
404
|
+
terminal_type: Terminal type for negotiation.
|
|
405
|
+
telnetlib_log_level: Log level for the underlying `telnetlib`.
|
|
406
|
+
connection_timeout: Timeout used when opening the connection.
|
|
407
|
+
|
|
408
|
+
Returns:
|
|
409
|
+
Index of the opened connection.
|
|
410
|
+
|
|
411
|
+
The `timeout`, `newline`, `prompt`, `prompt_is_regexp`, `encoding`,
|
|
412
|
+
`default_log_level`, `window_size`, `environ_user`, `terminal_emulation`,
|
|
413
|
+
`terminal_type` and `telnetlib_log_level` arguments get default values
|
|
414
|
+
when [importing] the library. Setting them here overrides those values
|
|
415
|
+
for the opened connection. Seet the [Configuration], [Terminal emulation]
|
|
416
|
+
and [Logging] sections for more information about these parameters and
|
|
417
|
+
their possible values.
|
|
418
|
+
|
|
419
|
+
Possible already opened connections are cached, and it is possible to
|
|
420
|
+
switch back to them using the [Switch Connection] keyword. It is possible
|
|
421
|
+
to switch either by using explicitly given `alias` or by using the index
|
|
422
|
+
returned by this keyword. Indexing starts from 1 and is reset back to it
|
|
423
|
+
by the [Close All Connections] keyword.
|
|
373
424
|
"""
|
|
374
425
|
timeout = timeout or self._timeout
|
|
375
426
|
connection_timeout = (timestr_to_secs(connection_timeout)
|
|
@@ -423,34 +474,44 @@ class TelnetLibrary:
|
|
|
423
474
|
def switch_connection(self, index_or_alias):
|
|
424
475
|
"""Switches between active connections using an index or an alias.
|
|
425
476
|
|
|
426
|
-
|
|
427
|
-
|
|
477
|
+
Args:
|
|
478
|
+
index_or_alias: Index or alias of the connection to activate.
|
|
479
|
+
|
|
480
|
+
Returns:
|
|
481
|
+
Index of the previously active connection.
|
|
428
482
|
|
|
429
|
-
|
|
483
|
+
Aliases can be given to the [Open Connection] keyword which also always
|
|
484
|
+
returns the connection index.
|
|
430
485
|
|
|
431
486
|
Example:
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
487
|
+
|
|
488
|
+
```robotframework
|
|
489
|
+
*** Test Cases ***
|
|
490
|
+
Switch connection
|
|
491
|
+
Open Connection myhost.net
|
|
492
|
+
Login john secret
|
|
493
|
+
Open Connection yourhost.com alias=admin
|
|
494
|
+
Login root password
|
|
495
|
+
Switch Connection 1 # index
|
|
496
|
+
Write I'm John!
|
|
497
|
+
Switch Connection admin # alias
|
|
498
|
+
Write I'm an admin!
|
|
499
|
+
[Teardown] Close All Connections
|
|
500
|
+
```
|
|
444
501
|
|
|
445
502
|
The example above expects that there were no other open
|
|
446
503
|
connections when opening the first one, because it used index
|
|
447
|
-
|
|
504
|
+
`1` when switching to the connection later. If you are not
|
|
448
505
|
sure about that, you can store the index into a variable as
|
|
449
506
|
shown below.
|
|
450
507
|
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
508
|
+
```robotframework
|
|
509
|
+
*** Test Cases ***
|
|
510
|
+
Switch connection
|
|
511
|
+
${index} = Open Connection myhost.net
|
|
512
|
+
Do Something
|
|
513
|
+
Switch Connection ${index}
|
|
514
|
+
```
|
|
454
515
|
"""
|
|
455
516
|
old_index = self._cache.current_index
|
|
456
517
|
self._conn = self._cache.switch(index_or_alias)
|
|
@@ -462,9 +523,9 @@ class TelnetLibrary:
|
|
|
462
523
|
If multiple connections are opened, this keyword should be used in
|
|
463
524
|
a test or suite teardown to make sure that all connections are closed.
|
|
464
525
|
It is not an error if some of the connections have already been closed
|
|
465
|
-
by
|
|
526
|
+
by the [Close Connection] keyword.
|
|
466
527
|
|
|
467
|
-
After this keyword, new
|
|
528
|
+
After this keyword, new indices returned by the [Open Connection]
|
|
468
529
|
keyword are reset to 1.
|
|
469
530
|
"""
|
|
470
531
|
self._conn = self._cache.close_all()
|
|
@@ -503,20 +564,30 @@ class TelnetConnection(telnetlib.Telnet):
|
|
|
503
564
|
def set_timeout(self, timeout):
|
|
504
565
|
"""Sets the timeout used for waiting output in the current connection.
|
|
505
566
|
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
567
|
+
Args:
|
|
568
|
+
timeout: Timeout used when waiting for output.
|
|
569
|
+
|
|
570
|
+
Returns:
|
|
571
|
+
Old timeout as a time string.
|
|
509
572
|
|
|
510
|
-
|
|
511
|
-
|
|
573
|
+
Read operations that expect some output to appear ([Read Until],
|
|
574
|
+
[Read Until Regexp], [Read Until Prompt], [Login]) use this timeout and
|
|
575
|
+
fail if the expected output does not appear before this timeout expires.
|
|
576
|
+
|
|
577
|
+
The `timeout` must be given in [Time string format].
|
|
512
578
|
|
|
513
579
|
Example:
|
|
514
|
-
| ${old} = | `Set Timeout` | 2 minute 30 seconds |
|
|
515
|
-
| `Do Something` |
|
|
516
|
-
| `Set Timeout` | ${old} |
|
|
517
580
|
|
|
518
|
-
|
|
519
|
-
|
|
581
|
+
```robotframework
|
|
582
|
+
*** Test Cases ***
|
|
583
|
+
Set timeout
|
|
584
|
+
${old} = Set Timeout 2 minute 30 seconds
|
|
585
|
+
Do Something
|
|
586
|
+
Set Timeout ${old}
|
|
587
|
+
```
|
|
588
|
+
|
|
589
|
+
See the [Configuration] section for more information about
|
|
590
|
+
global and connection specific configuration.
|
|
520
591
|
"""
|
|
521
592
|
self._verify_connection()
|
|
522
593
|
old = self._timeout
|
|
@@ -527,16 +598,22 @@ class TelnetConnection(telnetlib.Telnet):
|
|
|
527
598
|
self._timeout = timestr_to_secs(timeout)
|
|
528
599
|
|
|
529
600
|
def set_newline(self, newline):
|
|
530
|
-
"""Sets the newline used by
|
|
601
|
+
"""Sets the newline used by the current connection.
|
|
602
|
+
|
|
603
|
+
Args:
|
|
604
|
+
newline: Newline used by the [Write] keyword.
|
|
605
|
+
|
|
606
|
+
Returns:
|
|
607
|
+
Old newline.
|
|
531
608
|
|
|
532
609
|
The old newline is returned and can be used to restore the newline later.
|
|
533
|
-
See
|
|
610
|
+
See the [Set Timeout] for a similar example.
|
|
534
611
|
|
|
535
|
-
If terminal emulation is used, the newline can not be changed
|
|
536
|
-
connection.
|
|
612
|
+
If terminal emulation is used, the newline can not be changed after
|
|
613
|
+
opening the connection.
|
|
537
614
|
|
|
538
|
-
See
|
|
539
|
-
connection specific configuration.
|
|
615
|
+
See the [Configuration] section for more information about
|
|
616
|
+
global and connection specific configuration.
|
|
540
617
|
"""
|
|
541
618
|
self._verify_connection()
|
|
542
619
|
if self._terminal_emulator:
|
|
@@ -550,24 +627,35 @@ class TelnetConnection(telnetlib.Telnet):
|
|
|
550
627
|
self._newline = newline.replace('LF', '\n').replace('CR', '\r')
|
|
551
628
|
|
|
552
629
|
def set_prompt(self, prompt, prompt_is_regexp=False):
|
|
553
|
-
"""Sets the prompt used by
|
|
630
|
+
"""Sets the prompt used by the current connection.
|
|
631
|
+
|
|
632
|
+
Args:
|
|
633
|
+
prompt: Prompt to wait for when reading output with [Read Until Prompt]
|
|
634
|
+
and [Login].
|
|
635
|
+
prompt_is_regexp: Whether the prompt is a regular expression.
|
|
554
636
|
|
|
555
|
-
|
|
556
|
-
|
|
637
|
+
Returns:
|
|
638
|
+
A tuple containing the old prompt and Boolean true ot false depending
|
|
639
|
+
on was the prompt a regular expression or not.
|
|
557
640
|
|
|
558
|
-
|
|
641
|
+
If `prompt_is_regexp` is given a true value, the given `prompt` is
|
|
642
|
+
considered to be a regular expression.
|
|
559
643
|
|
|
560
644
|
Example:
|
|
561
|
-
| ${prompt} | ${regexp} = | `Set Prompt` | $ |
|
|
562
|
-
| `Do Something` |
|
|
563
|
-
| `Set Prompt` | ${prompt} | ${regexp} |
|
|
564
645
|
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
646
|
+
```robotframework
|
|
647
|
+
*** Test Cases ***
|
|
648
|
+
Set prompt
|
|
649
|
+
${prompt} ${regexp} = Set Prompt $
|
|
650
|
+
Do Something
|
|
651
|
+
Set Prompt ${prompt} ${regexp}
|
|
652
|
+
```
|
|
653
|
+
|
|
654
|
+
See the documentation of the Python's [re] module for more information
|
|
655
|
+
about the supported regular expression syntax. Notice that possible
|
|
656
|
+
backslashes need to be escaped in Robot Framework data.
|
|
569
657
|
|
|
570
|
-
See
|
|
658
|
+
See the [Configuration] section for more information about global and
|
|
571
659
|
connection specific configuration.
|
|
572
660
|
"""
|
|
573
661
|
self._verify_connection()
|
|
@@ -588,23 +676,30 @@ class TelnetConnection(telnetlib.Telnet):
|
|
|
588
676
|
|
|
589
677
|
@keyword(types=None)
|
|
590
678
|
def set_encoding(self, encoding=None, errors=None):
|
|
591
|
-
"""Sets the encoding
|
|
679
|
+
"""Sets the encoding for the current connection.
|
|
592
680
|
|
|
593
|
-
|
|
594
|
-
|
|
681
|
+
Args:
|
|
682
|
+
encoding: Encoding to use when [writing and reading].
|
|
683
|
+
errors: Error handler to use if encoding or decoding fails.
|
|
684
|
+
|
|
685
|
+
Returns:
|
|
686
|
+
Old encoding and error handler as a tuple.
|
|
687
|
+
|
|
688
|
+
The given `encoding` specifies the encoding to use when written/read
|
|
689
|
+
text is encoded/decoded, and `errors` specifies the error handler to
|
|
595
690
|
use if encoding/decoding fails. Either of these can be omitted and in
|
|
596
|
-
that case the old value is not affected. Use string
|
|
691
|
+
that case the old value is not affected. Use string `NONE` to disable
|
|
597
692
|
encoding altogether.
|
|
598
693
|
|
|
599
|
-
See
|
|
600
|
-
error handlers, as well as global and connection specific
|
|
601
|
-
in general.
|
|
694
|
+
See the [Configuration] section for more information about encoding
|
|
695
|
+
and error handlers, as well as global and connection specific
|
|
696
|
+
configuration in general.
|
|
602
697
|
|
|
603
698
|
The old values are returned and can be used to restore the encoding
|
|
604
|
-
and the error handler later. See
|
|
699
|
+
and the error handler later. See [Set Prompt] for a similar example.
|
|
605
700
|
|
|
606
|
-
If terminal emulation is used, the encoding can not be changed
|
|
607
|
-
connection.
|
|
701
|
+
If terminal emulation is used, the encoding can not be changed after
|
|
702
|
+
opening a connection.
|
|
608
703
|
"""
|
|
609
704
|
self._verify_connection()
|
|
610
705
|
if self._terminal_emulator:
|
|
@@ -629,10 +724,16 @@ class TelnetConnection(telnetlib.Telnet):
|
|
|
629
724
|
return bytes.decode(*self._encoding)
|
|
630
725
|
|
|
631
726
|
def set_telnetlib_log_level(self, level):
|
|
632
|
-
"""Sets the log level
|
|
727
|
+
"""Sets the `telnetlib` log level for the current connection.
|
|
728
|
+
|
|
729
|
+
Args:
|
|
730
|
+
level: Log level to use with `telnetlib` messages.
|
|
731
|
+
|
|
732
|
+
Returns:
|
|
733
|
+
The old `telnetlib` log level.
|
|
734
|
+
|
|
735
|
+
See the [Logging] section for more information.
|
|
633
736
|
|
|
634
|
-
Note that ``telnetlib`` can be very noisy thus using the level ``NONE``
|
|
635
|
-
can shutdown the messages generated by this library.
|
|
636
737
|
"""
|
|
637
738
|
self._verify_connection()
|
|
638
739
|
old = self._telnetlib_log_level
|
|
@@ -647,13 +748,19 @@ class TelnetConnection(telnetlib.Telnet):
|
|
|
647
748
|
self._telnetlib_log_level = level.upper()
|
|
648
749
|
|
|
649
750
|
def set_default_log_level(self, level):
|
|
650
|
-
"""Sets the default log level
|
|
751
|
+
"""Sets the default log level for the current connection.
|
|
752
|
+
|
|
753
|
+
Args:
|
|
754
|
+
level: Default log level to use for logging.
|
|
755
|
+
|
|
756
|
+
Returns:
|
|
757
|
+
The old default log level.
|
|
651
758
|
|
|
652
759
|
The old default log level is returned and can be used to restore the
|
|
653
760
|
log level later.
|
|
654
761
|
|
|
655
|
-
See
|
|
656
|
-
connection specific configuration.
|
|
762
|
+
See the [Configuration] section for more information about
|
|
763
|
+
global and connection specific configuration.
|
|
657
764
|
"""
|
|
658
765
|
self._verify_connection()
|
|
659
766
|
old = self._default_log_level
|
|
@@ -675,13 +782,19 @@ class TelnetConnection(telnetlib.Telnet):
|
|
|
675
782
|
def close_connection(self, loglevel=None):
|
|
676
783
|
"""Closes the current Telnet connection.
|
|
677
784
|
|
|
785
|
+
Args:
|
|
786
|
+
loglevel: Optional log level to use when logging the remaining output.
|
|
787
|
+
|
|
788
|
+
Returns:
|
|
789
|
+
Remaining output read from the connection.
|
|
790
|
+
|
|
678
791
|
Remaining output in the connection is read, logged, and returned.
|
|
679
792
|
It is not an error to close an already closed connection.
|
|
680
793
|
|
|
681
|
-
Use
|
|
794
|
+
Use [Close All Connections] if you want to make sure all opened
|
|
682
795
|
connections are closed.
|
|
683
796
|
|
|
684
|
-
See
|
|
797
|
+
See the [Logging] section for more information about log levels.
|
|
685
798
|
"""
|
|
686
799
|
if self.sock:
|
|
687
800
|
self.sock.shutdown(socket.SHUT_RDWR)
|
|
@@ -695,26 +808,37 @@ class TelnetConnection(telnetlib.Telnet):
|
|
|
695
808
|
login_incorrect='Login incorrect'):
|
|
696
809
|
"""Logs in to the Telnet server with the given user information.
|
|
697
810
|
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
811
|
+
Args:
|
|
812
|
+
username: Username to log in with.
|
|
813
|
+
password: Password to log in with.
|
|
814
|
+
login_prompt: Prompt that indicates username is expected.
|
|
815
|
+
password_prompt: Prompt that indicates password is expected.
|
|
816
|
+
login_timeout: Time to wait for login output if prompt is not set.
|
|
817
|
+
login_incorrect: Text indicating login failure if prompt is not set.
|
|
818
|
+
|
|
819
|
+
Returns:
|
|
820
|
+
Output read during the login process.
|
|
821
|
+
|
|
822
|
+
This keyword reads from the connection until the `login_prompt` is
|
|
823
|
+
encountered and then types the given `username`. Then it reads until
|
|
824
|
+
the `password_prompt` and types the given `password`. In both cases
|
|
701
825
|
a newline is appended automatically and the connection specific
|
|
702
826
|
timeout used when waiting for outputs.
|
|
703
827
|
|
|
704
|
-
How logging status is verified depends on whether
|
|
705
|
-
this connection or not:
|
|
828
|
+
How logging status is verified depends on whether the [prompt] is set
|
|
829
|
+
for this connection or not:
|
|
706
830
|
|
|
707
|
-
1
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
831
|
+
1. If the prompt is set, this keyword reads the output until the prompt
|
|
832
|
+
is found using the normal timeout. If no prompt is found, login is
|
|
833
|
+
considered failed and also this keyword fails. Note that in this case
|
|
834
|
+
both `login_timeout` and `login_incorrect` arguments are ignored.
|
|
711
835
|
|
|
712
|
-
2
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
836
|
+
2. If the prompt is not set, this keyword sleeps until `login_timeout`
|
|
837
|
+
and then reads all the output available on the connection. If the
|
|
838
|
+
output contains `login_incorrect` text, login is considered failed
|
|
839
|
+
and also this keyword fails.
|
|
716
840
|
|
|
717
|
-
See
|
|
841
|
+
See the [Configuration] section for more information about setting
|
|
718
842
|
newline, timeout, and prompt.
|
|
719
843
|
"""
|
|
720
844
|
output = self._submit_credentials(username, password, login_prompt,
|
|
@@ -748,19 +872,28 @@ class TelnetConnection(telnetlib.Telnet):
|
|
|
748
872
|
def write(self, text, loglevel=None):
|
|
749
873
|
"""Writes the given text plus a newline into the connection.
|
|
750
874
|
|
|
751
|
-
|
|
752
|
-
|
|
875
|
+
Args:
|
|
876
|
+
text: Text to write into the connection.
|
|
877
|
+
loglevel: Optional log level to use when logging output.
|
|
878
|
+
|
|
879
|
+
Returns:
|
|
880
|
+
Output consumed from the connection after writing.
|
|
881
|
+
|
|
882
|
+
The newline character sequence to use can be configured
|
|
883
|
+
both globally and per connection basis. The default value is `CRLF`.
|
|
753
884
|
|
|
754
885
|
This keyword consumes the written text, until the added newline, from
|
|
755
886
|
the output and logs and returns it. The given text itself must not
|
|
756
|
-
contain newlines. Use
|
|
757
|
-
causes a problem.
|
|
887
|
+
contain newlines. Use the [Write Bare] keyword if either of these
|
|
888
|
+
features causes a problem.
|
|
889
|
+
|
|
758
890
|
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
891
|
+
> [!note]
|
|
892
|
+
> This keyword does not return the possible output of the executed
|
|
893
|
+
> command. To get the output, one of the [Read] keywords must be
|
|
894
|
+
> used. See the [Writing and reading] section for more details.
|
|
762
895
|
|
|
763
|
-
See
|
|
896
|
+
See the [Logging] section for more information about log levels.
|
|
764
897
|
"""
|
|
765
898
|
newline = self._get_newline_for(text)
|
|
766
899
|
if newline in text:
|
|
@@ -778,11 +911,13 @@ class TelnetConnection(telnetlib.Telnet):
|
|
|
778
911
|
def write_bare(self, text, char_delay=None):
|
|
779
912
|
"""Writes the given text, and nothing else, into the connection.
|
|
780
913
|
|
|
781
|
-
|
|
782
|
-
|
|
914
|
+
Args:
|
|
915
|
+
text: Text to write into the connection.
|
|
916
|
+
char_delay: Optional delay, in seconds, between characters. If
|
|
917
|
+
given, the text is sent character by character.
|
|
783
918
|
|
|
784
919
|
This keyword does not append a newline nor consume the written text.
|
|
785
|
-
Use
|
|
920
|
+
Use the [Write] keyword if these features are desired.
|
|
786
921
|
"""
|
|
787
922
|
self._verify_connection()
|
|
788
923
|
if char_delay:
|
|
@@ -794,26 +929,36 @@ class TelnetConnection(telnetlib.Telnet):
|
|
|
794
929
|
|
|
795
930
|
def write_until_expected_output(self, text, expected, timeout,
|
|
796
931
|
retry_interval, loglevel=None):
|
|
797
|
-
"""Writes the given
|
|
932
|
+
r"""Writes the given `text` repeatedly, until `expected` appears in the output.
|
|
933
|
+
|
|
934
|
+
Args:
|
|
935
|
+
text: Text to write into the connection.
|
|
936
|
+
expected: Expected output to wait for.
|
|
937
|
+
timeout: Maximum time to wait for the expected output.
|
|
938
|
+
retry_interval: Time to wait before writing `text` again.
|
|
939
|
+
loglevel: Optional log level to use when logging output.
|
|
798
940
|
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
appear in the output within ``timeout``, this keyword fails.
|
|
941
|
+
Returns:
|
|
942
|
+
Output read when `expected` appears.
|
|
802
943
|
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
the
|
|
944
|
+
`text` is written without appending a newline and it is consumed from
|
|
945
|
+
the output before trying to find `expected`. If `expected` does not
|
|
946
|
+
appear in the output within `timeout`, this keyword fails.
|
|
806
947
|
|
|
807
|
-
Both
|
|
808
|
-
|
|
948
|
+
Both `timeout` and `retry_interval` must be given in [Time string format].
|
|
949
|
+
See the [Logging] section for more information about log levels.
|
|
809
950
|
|
|
810
951
|
Example:
|
|
811
|
-
| Write Until Expected Output | ps -ef| grep myprocess\\r\\n | myprocess |
|
|
812
|
-
| ... | 5 s | 0.5 s |
|
|
813
952
|
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
953
|
+
```robotframework
|
|
954
|
+
*** Test Cases ***
|
|
955
|
+
Write until expected output
|
|
956
|
+
Write Until Expected Output ps -ef| grep myprocess\r\n myprocess 5 s 0.5 s
|
|
957
|
+
```
|
|
958
|
+
|
|
959
|
+
The above example writes command `ps -ef | grep myprocess\r\n` until
|
|
960
|
+
`myprocess` appears in the output. The command is written every 0.5
|
|
961
|
+
seconds and the keyword fails if `myprocess` does not appear in
|
|
817
962
|
the output in 5 seconds.
|
|
818
963
|
"""
|
|
819
964
|
timeout = timestr_to_secs(timeout)
|
|
@@ -832,16 +977,24 @@ class TelnetConnection(telnetlib.Telnet):
|
|
|
832
977
|
def write_control_character(self, character):
|
|
833
978
|
"""Writes the given control character into the connection.
|
|
834
979
|
|
|
835
|
-
|
|
980
|
+
Args:
|
|
981
|
+
character: Control character name or number to send.
|
|
982
|
+
|
|
983
|
+
The control character is prepended with an IAC (Interpret As Command)
|
|
836
984
|
character.
|
|
837
985
|
|
|
838
|
-
The following control character names are supported: BRK
|
|
839
|
-
EC
|
|
840
|
-
control character.
|
|
986
|
+
The following control character names are supported: `BRK`, `IP`, `AO`,
|
|
987
|
+
`AYT`, `EC`, `EL`, `NOP`. Additionally, you can use arbitrary numbers
|
|
988
|
+
to send any control character.
|
|
841
989
|
|
|
842
990
|
Example:
|
|
843
|
-
|
|
844
|
-
|
|
991
|
+
|
|
992
|
+
```robotframework
|
|
993
|
+
*** Test Cases ***
|
|
994
|
+
Write control character
|
|
995
|
+
Write Control Character BRK # Send Break command
|
|
996
|
+
Write Control Character 241 # Send No operation command
|
|
997
|
+
```
|
|
845
998
|
"""
|
|
846
999
|
self._verify_connection()
|
|
847
1000
|
self.sock.sendall(telnetlib.IAC + self._get_control_character(character))
|
|
@@ -871,8 +1024,14 @@ class TelnetConnection(telnetlib.Telnet):
|
|
|
871
1024
|
def read(self, loglevel=None):
|
|
872
1025
|
"""Reads everything that is currently available in the output.
|
|
873
1026
|
|
|
874
|
-
|
|
875
|
-
|
|
1027
|
+
Args:
|
|
1028
|
+
loglevel: Optional log level to use when logging output.
|
|
1029
|
+
|
|
1030
|
+
Returns:
|
|
1031
|
+
All output currently available in the connection.
|
|
1032
|
+
|
|
1033
|
+
Read output is both returned and logged. See the [Logging] section
|
|
1034
|
+
for more information about log levels.
|
|
876
1035
|
"""
|
|
877
1036
|
self._verify_connection()
|
|
878
1037
|
output = self._decode(self.read_very_eager())
|
|
@@ -883,14 +1042,21 @@ class TelnetConnection(telnetlib.Telnet):
|
|
|
883
1042
|
return output
|
|
884
1043
|
|
|
885
1044
|
def read_until(self, expected, loglevel=None):
|
|
886
|
-
"""Reads output until
|
|
1045
|
+
"""Reads output until `expected` text is encountered.
|
|
1046
|
+
|
|
1047
|
+
Args:
|
|
1048
|
+
expected: Text to wait for in the output.
|
|
1049
|
+
loglevel: Optional log level to use when logging output.
|
|
1050
|
+
|
|
1051
|
+
Returns:
|
|
1052
|
+
Output up to and including the expected text.
|
|
887
1053
|
|
|
888
1054
|
Text up to and including the match is returned and logged. If no match
|
|
889
1055
|
is found, this keyword fails. How much to wait for the output depends
|
|
890
|
-
on the
|
|
1056
|
+
on the configured timeout.
|
|
891
1057
|
|
|
892
|
-
See
|
|
893
|
-
|
|
1058
|
+
See the [Logging] section for more information about log levels.
|
|
1059
|
+
Use [Read Until Regexp] if more complex matching is needed.
|
|
894
1060
|
"""
|
|
895
1061
|
success, output = self._read_until(expected)
|
|
896
1062
|
self._log(output, loglevel)
|
|
@@ -967,26 +1133,37 @@ class TelnetConnection(telnetlib.Telnet):
|
|
|
967
1133
|
return re.compile(self._encode(pattern))
|
|
968
1134
|
|
|
969
1135
|
def read_until_regexp(self, *expected):
|
|
970
|
-
"""Reads output until any of the
|
|
1136
|
+
r"""Reads output until any of the `expected` regular expressions match.
|
|
1137
|
+
|
|
1138
|
+
Args:
|
|
1139
|
+
*expected: Regular expression patterns to wait for. The last argument
|
|
1140
|
+
can optionally be a log level.
|
|
1141
|
+
|
|
1142
|
+
Returns:
|
|
1143
|
+
Output up to and including the first matching regular expression.
|
|
971
1144
|
|
|
972
1145
|
This keyword accepts any number of regular expressions patterns or
|
|
973
1146
|
compiled Python regular expression objects as arguments. Text up to
|
|
974
1147
|
and including the first match to any of the regular expressions is
|
|
975
1148
|
returned and logged. If no match is found, this keyword fails. How much
|
|
976
|
-
to wait for the output depends on the
|
|
1149
|
+
to wait for the output depends on the configured timeout.
|
|
977
1150
|
|
|
978
|
-
If the last given argument is a
|
|
979
|
-
as
|
|
1151
|
+
If the last given argument is a valid log level, it is used
|
|
1152
|
+
as `loglevel` similarly as with the [Read Until] keyword.
|
|
980
1153
|
|
|
981
|
-
See the documentation of
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
Notice that possible backslashes need to be escaped in Robot Framework data.
|
|
1154
|
+
See the documentation of the Python's [re] for more information about
|
|
1155
|
+
the supported regular expression syntax. Notice that possible backslashes
|
|
1156
|
+
need to be escaped in Robot Framework data.
|
|
985
1157
|
|
|
986
1158
|
Examples:
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
1159
|
+
|
|
1160
|
+
```robotframework
|
|
1161
|
+
*** Test Cases ***
|
|
1162
|
+
Read until regexp
|
|
1163
|
+
Read Until Regexp (#|$)
|
|
1164
|
+
Read Until Regexp first_regexp second_regexp
|
|
1165
|
+
Read Until Regexp \\d{4}-\\d{2}-\\d{2} DEBUG
|
|
1166
|
+
```
|
|
990
1167
|
"""
|
|
991
1168
|
if not expected:
|
|
992
1169
|
raise RuntimeError('At least one pattern required')
|
|
@@ -1006,20 +1183,27 @@ class TelnetConnection(telnetlib.Telnet):
|
|
|
1006
1183
|
def read_until_prompt(self, loglevel=None, strip_prompt=False):
|
|
1007
1184
|
"""Reads output until the prompt is encountered.
|
|
1008
1185
|
|
|
1009
|
-
|
|
1010
|
-
|
|
1186
|
+
Args:
|
|
1187
|
+
loglevel: Optional log level to use when logging output.
|
|
1188
|
+
strip_prompt: Whether to exclude the prompt from the returned output.
|
|
1189
|
+
|
|
1190
|
+
Returns:
|
|
1191
|
+
Output read from the connection.
|
|
1192
|
+
|
|
1193
|
+
This keyword requires the prompt to be configured when [importing]
|
|
1194
|
+
the library, with [Open Connection] or with [Set Prompt].
|
|
1011
1195
|
|
|
1012
1196
|
By default, text up to and including the prompt is returned and logged.
|
|
1013
1197
|
If no prompt is found, this keyword fails. How much to wait for the
|
|
1014
|
-
output depends on the
|
|
1198
|
+
output depends on the configured timeout.
|
|
1015
1199
|
|
|
1016
1200
|
If you want to exclude the prompt from the returned output, set
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1201
|
+
`strip_prompt` to a true value. If your prompt is a regular expression,
|
|
1202
|
+
make sure that the expression spans the whole prompt, because only
|
|
1203
|
+
the part of the output that matches the regular expression is stripped
|
|
1204
|
+
away.
|
|
1021
1205
|
|
|
1022
|
-
See
|
|
1206
|
+
See the [Logging] section for more information about log levels.
|
|
1023
1207
|
"""
|
|
1024
1208
|
if not self._prompt_is_set():
|
|
1025
1209
|
raise RuntimeError('Prompt is not set.')
|
|
@@ -1049,21 +1233,30 @@ class TelnetConnection(telnetlib.Telnet):
|
|
|
1049
1233
|
return output[:-length]
|
|
1050
1234
|
|
|
1051
1235
|
def execute_command(self, command, loglevel=None, strip_prompt=False):
|
|
1052
|
-
"""Executes the given
|
|
1236
|
+
"""Executes the given `command` and reads, logs, and returns resulting output.
|
|
1237
|
+
|
|
1238
|
+
Args:
|
|
1239
|
+
command: Command to execute on the connection.
|
|
1240
|
+
loglevel: Optional log level to use when logging output.
|
|
1241
|
+
strip_prompt: Whether to exclude the prompt from the returned output.
|
|
1053
1242
|
|
|
1054
|
-
|
|
1055
|
-
|
|
1243
|
+
Returns:
|
|
1244
|
+
Output read from the connection.
|
|
1056
1245
|
|
|
1057
|
-
This is a convenience keyword that uses
|
|
1246
|
+
This is a convenience keyword that uses [Write] and [Read Until Prompt]
|
|
1058
1247
|
internally. Following two examples are thus functionally identical:
|
|
1059
1248
|
|
|
1060
|
-
|
|
1249
|
+
```robotframework
|
|
1250
|
+
*** Test Cases ***
|
|
1251
|
+
Execute command
|
|
1252
|
+
${out} = Execute Command pwd
|
|
1061
1253
|
|
|
1062
|
-
|
|
1063
|
-
|
|
1254
|
+
Write and Read Until Prompt
|
|
1255
|
+
Write pwd
|
|
1256
|
+
${out} = Read Until Prompt
|
|
1257
|
+
```
|
|
1064
1258
|
|
|
1065
|
-
See
|
|
1066
|
-
Until Prompt` for more information about the ``strip_prompt`` parameter.
|
|
1259
|
+
See the [Logging] section for more information about log levels.
|
|
1067
1260
|
"""
|
|
1068
1261
|
self.write(command, loglevel)
|
|
1069
1262
|
return self.read_until_prompt(loglevel, strip_prompt)
|
|
@@ -1107,7 +1300,9 @@ class TelnetConnection(telnetlib.Telnet):
|
|
|
1107
1300
|
self._opt_environ_user(opt, self._environ_user)
|
|
1108
1301
|
elif cmd == telnetlib.DO and opt == telnetlib.NAWS and self._window_size:
|
|
1109
1302
|
self._opt_window_size(opt, *self._window_size)
|
|
1110
|
-
|
|
1303
|
+
# telnetlib passes NOOPT for commands without an option, such as SB and
|
|
1304
|
+
# SE. NOOPT is also option 0, BINARY, so check the command instead.
|
|
1305
|
+
elif cmd in (telnetlib.DO, telnetlib.DONT, telnetlib.WILL, telnetlib.WONT):
|
|
1111
1306
|
self._opt_dont_and_wont(cmd, opt)
|
|
1112
1307
|
|
|
1113
1308
|
def _opt_echo_on(self, opt):
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: robotframework-telnetlibrary
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.2
|
|
4
4
|
Summary: A Robot Framework library for communication via Telnet protocol
|
|
5
5
|
Maintainer-email: Sergii Dmytruk <sergii.dmytruk@3mdeb.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/MarketSquare/robotframework-telnet-library
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|