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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: robotframework-telnetlibrary
3
- Version: 1.0.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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "robotframework-telnetlibrary"
3
- version = "1.0.0"
3
+ version = "1.0.2"
4
4
  description = "A Robot Framework library for communication via Telnet protocol"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.7"
@@ -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
- ``TelnetLibrary`` is Robot Framework's library that makes it possible to
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
- == Table of contents ==
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
- = Connections =
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
- The first step of using ``TelnetLibrary`` is opening a connection with `Open
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
- It is possible to open multiple connections and switch the active one
49
- using `Switch Connection`. `Close All Connections` can be used to close
50
- all the connections, which is especially useful in suite teardowns to
51
- guarantee that all connections are always closed.
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
- = Writing and reading =
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 `Write`
57
- and `Write Bare` keywords. The main difference between these two is that
58
- the former adds a [#Configuration|configurable newline] after the text
59
- automatically.
60
-
61
- After writing something to the connection, the resulting output can be
62
- read using `Read`, `Read Until`, `Read Until Regexp`, and `Read Until
63
- Prompt` keywords. Which one to use depends on the context, but the latest
64
- one is often the most convenient.
65
-
66
- As a convenience when running a command, it is possible to use `Execute
67
- Command` that simply uses `Write` and `Read Until Prompt` internally.
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/decoded using a
72
- [#Configuration|configured encoding].
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
- normally returned as part of the read operation. If an escape code occurs
76
- in middle of a search pattern it may also prevent finding the searched
77
- string. `Terminal emulation` can be used to process these
78
- escape codes as they would be if a real terminal would be in use.
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
- = Configuration =
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
- [#Importing|library is imported], and these values can be overridden per
85
- connection by `Open Connection` or with setting specific keywords
86
- `Set Timeout`, `Set Newline`, `Set Prompt`, `Set Encoding`,
87
- `Set Default Log Level` and `Set Telnetlib Log Level`.
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 ``environ_user``, ``window_size``, ``terminal_emulation``, and
90
- ``terminal_type`` can not be changed after opening the connection.
99
+ Values of `environ_user`, `window_size`, `terminal_emulation`, and
100
+ `terminal_type` can not be changed after opening the connection.
91
101
 
92
- == Timeout ==
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 `Read Until`, `Read Until Regexp`,
96
- `Read Until Prompt`, and `Login` keywords. The default value is 3 seconds.
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
- == Connection Timeout ==
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 `Open Connection`.
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
- == Newline ==
114
+ ## Newline
105
115
 
106
- Newline defines which line separator `Write` keyword should use. The
107
- default value is ``CRLF`` that is typically used by Telnet connections.
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 ``\\n`` and ``\\r`` or
110
- with special ``LF`` and ``CR`` syntax.
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
- == Prompt ==
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 `Read Until Prompt`. It also makes
120
- it easier, and faster, to verify did `Login` succeed.
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 ``prompt_is_regexp`` argument a true value (see `Boolean
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
- == Encoding ==
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 ``NONE``. This is mainly useful if you need to get the bytes
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
- the library as Unicode and you need to use variables to use bytes.
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
- - ``ignore``: ignore characters that cannot be encoded (default)
151
- - ``strict``: fail if characters cannot be encoded
152
- - ``replace``: replace characters that cannot be encoded with a replacement
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
- == Default log level ==
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 `logging` unless
163
- they are given an explicit log level. The default value is ``INFO``, and
164
- changing it, for example, to ``DEBUG`` can be a good idea if there is lot
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
- == Terminal type ==
191
+ ## Terminal type
168
192
 
169
- By default the TelnetLibrary does not negotiate any specific terminal type
170
- with the server. If a specific terminal type, for example ``vt100``, is
171
- desired, the terminal type can be configured in `importing` and with
172
- `Open Connection`.
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
- == Window size ==
198
+ ## Window size
175
199
 
176
200
  Window size for negotiation with the server can be configured when
177
- `importing` the library and with `Open Connection`.
201
+ [importing] the library and with the [Open Connection] keyword.
178
202
 
179
- == USER environment variable ==
203
+ ## `USER` environment variable
180
204
 
181
- Telnet protocol allows the ``USER`` environment variable to be sent when
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 option ``environ_user`` can be used in
185
- `importing` and with `Open Connection`.
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
- = Terminal emulation =
211
+ # Terminal emulation
188
212
 
189
- TelnetLibrary supports terminal
190
- emulation with [http://pyte.readthedocs.io|Pyte]. Terminal emulation
191
- will process the output in a virtual screen. This means that ANSI escape
192
- codes, like cursor movements, and also control characters, like
193
- carriage returns and backspaces, have the same effect on the result as they
194
- would have on a normal terminal screen. For example the sequence
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 ``terminal_emulation``
198
- argument a true value (see `Boolean arguments`) either in the library
199
- initialization or with `Open Connection`.
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 Pyte approximates vt-style terminal, you may also want to set the
202
- terminal type as ``vt100``. We also recommend that you increase the window
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 `newline` and `encoding` can not be
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
- Due to backwards incompatible changes in Pyte, versions of Pyte older than
213
- 0.6 are not supported. Latest Pyte version can be installed (or upgraded)
214
- with ``pip install --upgrade pyte``.
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
- = Logging =
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 [#Configuration|configured] default value.
244
+ they use the configured default value.
221
245
 
222
- The valid log levels to use are ``TRACE``, ``DEBUG``, ``INFO`` (default),
223
- and ``WARN``. Levels below ``INFO`` are not shown in log files by default
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 [http://docs.python.org/library/telnetlib.html|telnetlib module]
227
- used by this library has a custom logging system for logging content it
228
- sends and receives. By default these messages are written using ``TRACE``
229
- level, but the level is configurable with the ``telnetlib_log_level``
230
- option either in the library initialization, to the `Open Connection`
231
- or by using the `Set Telnetlib Log Level` keyword to the active
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
- = Time string format =
257
+ # Time string format
236
258
 
237
259
  Timeouts and other times used must be given as a time string using format
238
- like ``15 seconds`` or ``1min 10s``. If the timeout is given as just
239
- a number, for example, ``10`` or ``1.5``, it is considered to be seconds.
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
- [http://robotframework.org/robotframework/#user-guide|Robot Framework User Guide].
263
+ [Robot Framework User Guide].
242
264
 
243
- = Boolean arguments =
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 ``FALSE``, ``NONE``, ``NO``, ``OFF`` or
248
- ``0``, case-insensitively. Other strings are considered true regardless
249
- their value, and other argument types are tested using the same
250
- [http://docs.python.org/library/stdtypes.html#truth|rules as in Python].
251
-
252
- True examples:
253
- | `Open Connection` | lolcathost | terminal_emulation=True | # Strings are generally true. |
254
- | `Open Connection` | lolcathost | terminal_emulation=yes | # Same as the above. |
255
- | `Open Connection` | lolcathost | terminal_emulation=${TRUE} | # Python ``True`` is true. |
256
- | `Open Connection` | lolcathost | terminal_emulation=${42} | # Numbers other than 0 are true. |
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
- ROBOT_LIBRARY_VERSION = '1.0.0'
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
- Configuration parameters are used as default values when new
280
- connections are opened with `Open Connection` keyword. They can also be
281
- overridden after opening the connection using the `Set ...` `keywords`.
282
- See these keywords as well as `Configuration`, `Terminal emulation` and
283
- `Logging` sections above for more information about these parameters
284
- and their possible values.
285
-
286
- See `Time string format` and `Boolean arguments` sections for
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
- Examples (use only one of these):
291
- | = Setting = | = Value = | = Value = | = Value = | = Value = | = Comment = |
292
- | Library | TelnetLibrary | | | | # default values |
293
- | Library | TelnetLibrary | 5 seconds | | | # set only timeout |
294
- | Library | TelnetLibrary | newline=LF | encoding=ISO-8859-1 | | # set newline and encoding using named arguments |
295
- | Library | TelnetLibrary | prompt=$ | | | # set prompt |
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
- The ``timeout``, ``newline``, ``prompt``, ``prompt_is_regexp``,
361
- ``encoding``, ``default_log_level``, ``window_size``, ``environ_user``,
362
- ``terminal_emulation``, ``terminal_type`` and ``telnetlib_log_level``
363
- arguments get default values when the library is [#Importing|imported].
364
- Setting them here overrides those values for the opened connection.
365
- See `Configuration`, `Terminal emulation` and `Logging` sections for
366
- more information about these parameters and their possible values.
367
-
368
- Possible already opened connections are cached and it is possible to
369
- switch back to them using `Switch Connection` keyword. It is possible to
370
- switch either using explicitly given ``alias`` or using index returned
371
- by this keyword. Indexing starts from 1 and is reset back to it by
372
- `Close All Connections` keyword.
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
- Aliases can be given to `Open Connection` keyword which also always
427
- returns the connection index.
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
- This keyword returns the index of previous active connection.
483
+ Aliases can be given to the [Open Connection] keyword which also always
484
+ returns the connection index.
430
485
 
431
486
  Example:
432
- | `Open Connection` | myhost.net | | |
433
- | `Login` | john | secret | |
434
- | `Write` | some command | | |
435
- | `Open Connection` | yourhost.com | 2nd conn | |
436
- | `Login` | root | password | |
437
- | `Write` | another cmd | | |
438
- | ${old index}= | `Switch Connection` | 1 | # index |
439
- | `Write` | something | | |
440
- | `Switch Connection` | 2nd conn | | # alias |
441
- | `Write` | whatever | | |
442
- | `Switch Connection` | ${old index} | | # back to original |
443
- | [Teardown] | `Close All Connections` | | |
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
- ``1`` when switching to the connection later. If you are not
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
- | ${index} = | `Open Connection` | myhost.net |
452
- | `Do Something` | | |
453
- | `Switch Connection` | ${index} | |
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 `Close Connection`.
526
+ by the [Close Connection] keyword.
466
527
 
467
- After this keyword, new indexes returned by `Open Connection`
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
- Read operations that expect some output to appear (`Read Until`, `Read
507
- Until Regexp`, `Read Until Prompt`, `Login`) use this timeout and fail
508
- if the expected output does not appear before this timeout expires.
567
+ Args:
568
+ timeout: Timeout used when waiting for output.
569
+
570
+ Returns:
571
+ Old timeout as a time string.
509
572
 
510
- The ``timeout`` must be given in `time string format`. The old timeout
511
- is returned and can be used to restore the timeout later.
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
- See `Configuration` section for more information about global and
519
- connection specific configuration.
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 `Write` keyword in the current connection.
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 `Set Timeout` for a similar example.
610
+ See the [Set Timeout] for a similar example.
534
611
 
535
- If terminal emulation is used, the newline can not be changed on an open
536
- connection.
612
+ If terminal emulation is used, the newline can not be changed after
613
+ opening the connection.
537
614
 
538
- See `Configuration` section for more information about global and
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 `Read Until Prompt` and `Login` in the current connection.
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
- If ``prompt_is_regexp`` is given a true value (see `Boolean arguments`),
556
- the given ``prompt`` is considered to be a regular expression.
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
- The old prompt is returned and can be used to restore the prompt later.
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
- See the documentation of
566
- [http://docs.python.org/library/re.html|Python re module]
567
- for more information about the supported regular expression syntax.
568
- Notice that possible backslashes need to be escaped in Robot Framework data.
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 `Configuration` section for more information about global and
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 to use for `writing and reading` in the current connection.
679
+ """Sets the encoding for the current connection.
592
680
 
593
- The given ``encoding`` specifies the encoding to use when written/read
594
- text is encoded/decoded, and ``errors`` specifies the error handler to
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 ``NONE`` to disable
691
+ that case the old value is not affected. Use string `NONE` to disable
597
692
  encoding altogether.
598
693
 
599
- See `Configuration` section for more information about encoding and
600
- error handlers, as well as global and connection specific configuration
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 `Set Prompt` for a similar example.
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 on an open
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 used for `logging` in the underlying ``telnetlib``.
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 used for `logging` in the current connection.
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 `Configuration` section for more information about global and
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 `Close All Connections` if you want to make sure all opened
794
+ Use [Close All Connections] if you want to make sure all opened
682
795
  connections are closed.
683
796
 
684
- See `Logging` section for more information about log levels.
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
- This keyword reads from the connection until the ``login_prompt`` is
699
- encountered and then types the given ``username``. Then it reads until
700
- the ``password_prompt`` and types the given ``password``. In both cases
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 a prompt is set for
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) If the prompt is set, this keyword reads the output until the prompt
708
- is found using the normal timeout. If no prompt is found, login is
709
- considered failed and also this keyword fails. Note that in this case
710
- both ``login_timeout`` and ``login_incorrect`` arguments are ignored.
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) If the prompt is not set, this keywords sleeps until ``login_timeout``
713
- and then reads all the output available on the connection. If the
714
- output contains ``login_incorrect`` text, login is considered failed
715
- and also this keyword fails.
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 `Configuration` section for more information about setting
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
- The newline character sequence to use can be [#Configuration|configured]
752
- both globally and per connection basis. The default value is ``CRLF``.
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 `Write Bare` instead if either of these features
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
- *Note:* This keyword does not return the possible output of the executed
760
- command. To get the output, one of the `Read ...` `keywords` must be
761
- used. See `Writing and reading` section for more details.
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 `Logging` section for more information about log levels.
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
- If ``char_delay`` is specified, the text is sent character by
782
- character with the given delay, in seconds, between them.
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 `Write` if these features are needed.
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 ``text`` repeatedly, until ``expected`` appears in the output.
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
- ``text`` is written without appending a newline and it is consumed from
800
- the output before trying to find ``expected``. If ``expected`` does not
801
- appear in the output within ``timeout``, this keyword fails.
941
+ Returns:
942
+ Output read when `expected` appears.
802
943
 
803
- ``retry_interval`` defines the time to wait ``expected`` to appear before
804
- writing the ``text`` again. Consuming the written ``text`` is subject to
805
- the normal [#Configuration|configured timeout].
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 ``timeout`` and ``retry_interval`` must be given in `time string
808
- format`. See `Logging` section for more information about log levels.
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
- The above example writes command ``ps -ef | grep myprocess\\r\\n`` until
815
- ``myprocess`` appears in the output. The command is written every 0.5
816
- seconds and the keyword fails if ``myprocess`` does not appear in
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
- The control character is prepended with an IAC (interpret as command)
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, IP, AO, AYT,
839
- EC, EL, NOP. Additionally, you can use arbitrary numbers to send any
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
- | Write Control Character | BRK | # Send Break command |
844
- | Write Control Character | 241 | # Send No operation command |
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
- Read output is both returned and logged. See `Logging` section for more
875
- information about log levels.
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 ``expected`` text is encountered.
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 [#Configuration|configured timeout].
1056
+ on the configured timeout.
891
1057
 
892
- See `Logging` section for more information about log levels. Use
893
- `Read Until Regexp` if more complex matching is needed.
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 ``expected`` regular expressions match.
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 [#Configuration|configured timeout].
1149
+ to wait for the output depends on the configured timeout.
977
1150
 
978
- If the last given argument is a [#Logging|valid log level], it is used
979
- as ``loglevel`` similarly as with `Read Until` keyword.
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
- [http://docs.python.org/library/re.html|Python re module]
983
- for more information about the supported regular expression syntax.
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
- | `Read Until Regexp` | (#|$) |
988
- | `Read Until Regexp` | first_regexp | second_regexp |
989
- | `Read Until Regexp` | \\\\d{4}-\\\\d{2}-\\\\d{2} | DEBUG |
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
- This keyword requires the prompt to be [#Configuration|configured]
1010
- either in `importing` or with `Open Connection` or `Set Prompt` keyword.
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 [#Configuration|configured timeout].
1198
+ output depends on the configured timeout.
1015
1199
 
1016
1200
  If you want to exclude the prompt from the returned output, set
1017
- ``strip_prompt`` to a true value (see `Boolean arguments`). If your
1018
- prompt is a regular expression, make sure that the expression spans the
1019
- whole prompt, because only the part of the output that matches the
1020
- regular expression is stripped away.
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 `Logging` section for more information about log levels.
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 ``command`` and reads, logs, and returns everything until the prompt.
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
- This keyword requires the prompt to be [#Configuration|configured]
1055
- either in `importing` or with `Open Connection` or `Set Prompt` keyword.
1243
+ Returns:
1244
+ Output read from the connection.
1056
1245
 
1057
- This is a convenience keyword that uses `Write` and `Read Until Prompt`
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
- | ${out} = | `Execute Command` | pwd |
1249
+ ```robotframework
1250
+ *** Test Cases ***
1251
+ Execute command
1252
+ ${out} = Execute Command pwd
1061
1253
 
1062
- | `Write` | pwd |
1063
- | ${out} = | `Read Until Prompt` |
1254
+ Write and Read Until Prompt
1255
+ Write pwd
1256
+ ${out} = Read Until Prompt
1257
+ ```
1064
1258
 
1065
- See `Logging` section for more information about log levels and `Read
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
- elif opt != telnetlib.NOOPT:
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.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