4 new revisions:
Revision: ce6d4e80386b
Branch: default
Author: Robot Framework Developers ([email protected])
Date: Wed Jan 9 01:39:40 2013
Log: made telnet test a little less flakey
http://code.google.com/p/robotframework/source/detail?r=ce6d4e80386b
Revision: cb29c6de85b2
Branch: default
Author: Robot Framework Developers ([email protected])
Date: Wed Jan 9 01:52:47 2013
Log: Telnet: Fixed `Read Until Regexp` with compiled regexps....
http://code.google.com/p/robotframework/source/detail?r=cb29c6de85b2
Revision: 4360852e9a6b
Branch: default
Author: Robot Framework Developers ([email protected])
Date: Wed Jan 9 05:40:09 2013
Log: Telnet library: Possibility to specify error hander when
encoding/deco...
http://code.google.com/p/robotframework/source/detail?r=4360852e9a6b
Revision: c3fb1fdb47f1
Branch: default
Author: Robot Framework Developers ([email protected])
Date: Wed Jan 9 05:40:17 2013
Log: Automated merge with https://robotframework.googlecode.com/hg/
http://code.google.com/p/robotframework/source/detail?r=c3fb1fdb47f1
==============================================================================
Revision: ce6d4e80386b
Branch: default
Author: Robot Framework Developers ([email protected])
Date: Wed Jan 9 01:39:40 2013
Log: made telnet test a little less flakey
http://code.google.com/p/robotframework/source/detail?r=ce6d4e80386b
Modified:
/atest/robot/standard_libraries/telnet/connections.txt
/atest/testdata/standard_libraries/telnet/connections.txt
=======================================
--- /atest/robot/standard_libraries/telnet/connections.txt Fri Dec 21
02:08:23 2012
+++ /atest/robot/standard_libraries/telnet/connections.txt Wed Jan 9
01:39:40 2013
@@ -10,7 +10,7 @@
Close Connection
${tc} = Check Test Case ${TEST NAME}
- Check Log Message ${tc.kws[0].msgs[0]} *hello pattern=yes
+ Check Log Message ${tc.kws[1].msgs[0]} *hello pattern=yes
Closing already closed connection is OK
Check Test Case ${TEST NAME}
=======================================
--- /atest/testdata/standard_libraries/telnet/connections.txt Fri Dec 21
02:08:23 2012
+++ /atest/testdata/standard_libraries/telnet/connections.txt Wed Jan 9
01:39:40 2013
@@ -10,6 +10,7 @@
Close Connection
[Documentation] FAIL No connection open
+ Read Until login:
Write hello
Close Connection
Write this fails
==============================================================================
Revision: cb29c6de85b2
Branch: default
Author: Robot Framework Developers ([email protected])
Date: Wed Jan 9 01:52:47 2013
Log: Telnet: Fixed `Read Until Regexp` with compiled regexps.
Update issue 1327
Status: Done
Owner: pekka.klarck
Fixed with a test.
http://code.google.com/p/robotframework/source/detail?r=cb29c6de85b2
Modified:
/atest/robot/standard_libraries/telnet/read_and_write.txt
/atest/testdata/standard_libraries/telnet/read_and_write.txt
/src/robot/libraries/Telnet.py
=======================================
--- /atest/robot/standard_libraries/telnet/read_and_write.txt Fri Dec 21
02:15:33 2012
+++ /atest/robot/standard_libraries/telnet/read_and_write.txt Wed Jan 9
01:52:47 2013
@@ -40,6 +40,11 @@
Check Log Message ${tc.kws[1].msgs[0]} ${HOME}
Check Log Message ${tc.kws[3].msgs[0]} ${PROMPT START} DEBUG
+Read Until Regexp With Compiled Regexp
+ ${tc} = Check Test Case ${TEST NAME}
+ Check Log Message ${tc.kws[2].msgs[0]} ${HOME}
+ Check Log Message ${tc.kws[5].msgs[0]} ${PROMPT START} DEBUG
+
Read Until Regexp Non-ASCII
${tc} = Check Test Case ${TEST NAME}
Check Log Message ${tc.kws[1].msgs[0]} Päivää DEBUG
=======================================
--- /atest/testdata/standard_libraries/telnet/read_and_write.txt Thu Dec 27
07:30:51 2012
+++ /atest/testdata/standard_libraries/telnet/read_and_write.txt Wed Jan 9
01:52:47 2013
@@ -60,6 +60,15 @@
Should Be Equal ${out} ${HOME}\r\n
${out} = Read Until Regexp no match .*@ blaah deBUG
Should Be Equal ${out} ${PROMPT START}
+
+Read Until Regexp With Compiled Regexp
+ Write pwd
+ ${regexp} = Evaluate re.compile('/h[abo]me.${USERNAME}\\s+')
modules=re
+ ${out} = Read Until Regexp ${regexp}
+ Should Be Equal ${out} ${HOME}\r\n
+ ${regexp} = Evaluate re.compile('.*@') modules=re
+ ${out} = Read Until Regexp no match ${regexp} blaah
deBUG
+ Should Be Equal ${out} ${PROMPT START}
Read Until Regexp Non-ASCII
Write echo Päivää
=======================================
--- /src/robot/libraries/Telnet.py Sat Dec 29 14:34:01 2012
+++ /src/robot/libraries/Telnet.py Wed Jan 9 01:52:47 2013
@@ -441,7 +441,11 @@
self._default_log_level = level.upper()
def _is_valid_log_level(self, level):
- return level is None or level.upper() in
('TRACE', 'DEBUG', 'INFO', 'WARN')
+ if level is None:
+ return True
+ if not isinstance(level, basestring):
+ return False
+ return level.upper() in ('TRACE', 'DEBUG', 'INFO', 'WARN')
def close_connection(self, loglevel=None):
"""Closes the current Telnet connection.
==============================================================================
Revision: 4360852e9a6b
Branch: default
Author: Robot Framework Developers ([email protected])
Date: Wed Jan 9 05:40:09 2013
Log: Telnet library: Possibility to specify error hander when
encoding/decoding fails. Also ignore error by default.
Update issue 1328
Status: Done
Implemented, tested, and documented.
http://code.google.com/p/robotframework/source/detail?r=4360852e9a6b
Modified:
/atest/robot/standard_libraries/telnet/configuration.txt
/atest/testdata/standard_libraries/telnet/configuration.txt
/src/robot/libraries/Telnet.py
=======================================
--- /atest/robot/standard_libraries/telnet/configuration.txt Fri Dec 28
04:30:27 2012
+++ /atest/robot/standard_libraries/telnet/configuration.txt Wed Jan 9
05:40:09 2013
@@ -40,6 +40,9 @@
Set Encoding Keyword
Check Test Case ${TEST NAME}
+
+Use Configured Encoding
+ Check Test Case ${TEST NAME}
Default Log Level In Init
Check Test Case ${TEST NAME}
=======================================
--- /atest/testdata/standard_libraries/telnet/configuration.txt Fri Dec 28
04:30:27 2012
+++ /atest/testdata/standard_libraries/telnet/configuration.txt Wed Jan 9
05:40:09 2013
@@ -1,11 +1,10 @@
*** Setting ***
Test Setup Open Connection ${HOST}
Test Teardown Close All Connections
-Library Telnet 123 CRLF $ REGEXP ASCII DeBuG
+Library Telnet 3.142 CRLF $ REGEXP ASCII
strict DeBuG
Resource telnet_resource.txt
-
-*** Test Case ***
+*** Test Cases ***
Prompt Set In Init
Prompt Should Be $ ${TRUE}
@@ -24,7 +23,7 @@
Prompt Should Be >\\s+ ${TRUE}
Timeout Set In Init
- Timeout Should Be 2 minutes 3 seconds
+ Timeout Should Be 3 seconds 142 milliseconds
Timeout Set In Open Connection
Open Connection ${HOST} timeout=0.5s
@@ -53,17 +52,33 @@
Newline Should Be \n\rFOO
Encoding Set In Init
- Encoding Should Be ASCII
+ Encoding Should Be ASCII strict
Encoding Set In Open Connection
- Open Connection ${HOST} encoding=ISO-8859-15
- Encoding Should Be ISO-8859-15
+ Open Connection ${HOST} encoding=ISO-8859-15
encoding_errors=xxx
+ Encoding Should Be ISO-8859-15 xxx
Open Connection ${HOST} encoding=Latin1
- Encoding Should Be Latin1
+ Encoding Should Be Latin1 strict
Set Encoding Keyword
Set Encoding us-ascii
- Encoding Should Be us-ascii
+ Encoding Should Be us-ascii strict
+ Set Encoding xxx yyy
+ Encoding Should Be xxx yyy
+ Set Encoding encoding=ASCII
+ Encoding Should Be ASCII yyy
+ Set Encoding errors=ignore
+ Encoding Should Be ASCII ignore
+
+Use Configured Encoding
+ Login and set prompt
+ Run Keyword And Expect Error UnicodeEncodeError:* Write echo
päivää
+ Set Encoding errors=ignore
+ Write echo hyvää päivää
+ Read Until hyv piv
+ Set Encoding UTF-8
+ Write echo hyvää päivää
+ Read Until hyvää päivää
Default Log Level In Init
Default Log Level Should Be DEBUG
@@ -100,7 +115,7 @@
Prompt Should Be ${NONE} ${FALSE}
Timeout Should Be 3 seconds
Newline Should Be \r\n
- Encoding Should Be UTF-8
+ Encoding Should Be UTF-8 ignore
Default Log Level Should Be INFO
*** Keywords ***
@@ -128,11 +143,13 @@
Should Be Equal ${newline} \r\n
Encoding Should Be
- [Arguments] ${expected}
- ${encoding} = Set Encoding ASCII
- Should Be Equal ${encoding} ${expected}
- ${encoding} = Set Encoding ${encoding}
+ [Arguments] ${expected encoding} ${expected errors}
+ ${encoding} ${errors} = Set Encoding ASCII ignore
+ Should Be Equal ${encoding} ${expected encoding}
+ Should Be Equal ${errors} ${expected errors}
+ ${encoding} ${errors} = Set Encoding ${encoding} ${errors}
Should Be Equal ${encoding} ASCII
+ Should Be Equal ${errors} ignore
Default Log Level Should Be
[Arguments] ${expected}
=======================================
--- /src/robot/libraries/Telnet.py Wed Jan 9 01:52:47 2013
+++ /src/robot/libraries/Telnet.py Wed Jan 9 05:40:09 2013
@@ -98,8 +98,8 @@
with special 'LF' and 'CR' syntax.
Examples:
- | Set Newline | \\n |
- | Set Newline | CRLF |
+ | `Set Newline` | \\n |
+ | `Set Newline` | CRLF |
== Prompt ==
@@ -116,9 +116,26 @@
Encoding is needed when written or read text contains non-ASCII
characters.
The default encoding is UTF-8 that works also with ASCII.
- Using UTF-8 encoding by default and being able to configure encoding
are
- new features in Robot Framework 2.7.6. In earlier versions only ASCII
was
- supported.
+ It is also possible to configure the error handler to use if encoding
+ or decoding characters fails. Accepted values are the same that
+ encode/decode functions in Python strings accept. In practice the
following
+ values are the most useful:
+
+ - `ignore`: ignore characters that cannot be encoded (default)
+ - `strict`: fail if characters cannot be encoded
+ - `replace`: replace characters that cannot be encoded with a
replacement
+ character
+
+ Examples:
+ | `Open Connection` | lolcathost | encoding=Latin1 |
encoding_errors=strict |
+ | `Set Encoding` | ISO-8859-15 |
+ | `Set Encoding` | errors=ignore |
+
+ Using UTF-8 encoding by default and being able to configure the
encoding
+ are new features in Robot Framework 2.7.6. In earlier versions only
ASCII
+ was supported and encoding errors were silently ignored. Robot
Framework
+ 2.7.7 added a possibility to specify the error handler and changed the
+ default behavior back to ignoring errors.
== Default log level ==
@@ -152,8 +169,10 @@
ROBOT_LIBRARY_SCOPE = 'TEST_SUITE'
ROBOT_LIBRARY_VERSION = get_version()
- def __init__(self, timeout='3 seconds', newline='CRLF', prompt=None,
- prompt_is_regexp=False, encoding='UTF-8',
default_log_level='INFO'):
+ def __init__(self, timeout='3 seconds', newline='CRLF',
+ prompt=None, prompt_is_regexp=False,
+ encoding='UTF-8', encoding_errors='ignore',
+ default_log_level='INFO'):
"""Telnet library can be imported with optional configuration
parameters.
Configuration parameters are used as default values when new
@@ -178,6 +197,7 @@
self._newline = newline or 'CRLF'
self._prompt = (prompt, bool(prompt_is_regexp))
self._encoding = encoding
+ self._encoding_errors = encoding_errors
self._default_log_level = default_log_level
self._cache = utils.ConnectionCache()
self._conn = None
@@ -219,7 +239,7 @@
def open_connection(self, host, alias=None, port=23, timeout=None,
newline=None, prompt=None, prompt_is_regexp=False,
- encoding=None, default_log_level=None):
+ encoding=None, encoding_errors=None,
default_log_level=None):
"""Opens a new Telnet connection to the given host and port.
The `timeout`, `newline`, `prompt`, `prompt_is_regexp`, `encoding`,
@@ -236,6 +256,7 @@
timeout = timeout or self._timeout
newline = newline or self._newline
encoding = encoding or self._encoding
+ encoding_errors = encoding_errors or self._encoding_errors
default_log_level = default_log_level or self._default_log_level
if not prompt:
prompt, prompt_is_regexp = self._prompt
@@ -243,7 +264,8 @@
% (host, port, prompt))
self._conn = self._get_connection(host, port, timeout, newline,
prompt, prompt_is_regexp,
- encoding, default_log_level)
+ encoding, encoding_errors,
+ default_log_level)
return self._cache.register(self._conn, alias)
def _get_connection(self, *args):
@@ -303,13 +325,14 @@
class TelnetConnection(telnetlib.Telnet):
def __init__(self, host=None, port=23, timeout=3.0, newline='CRLF',
- prompt=None, prompt_is_regexp=False, encoding='UTF-8',
+ prompt=None, prompt_is_regexp=False,
+ encoding='UTF-8', encoding_errors='ignore',
default_log_level='INFO'):
telnetlib.Telnet.__init__(self, host, int(port) if port else 23)
self._set_timeout(timeout)
self._set_newline(newline)
self._set_prompt(prompt, prompt_is_regexp)
- self._set_encoding(encoding)
+ self._set_encoding(encoding, encoding_errors)
self._set_default_log_level(default_log_level)
self.set_option_negotiation_callback(self._negotiate_echo_on)
@@ -343,6 +366,7 @@
"""Sets the newline used by `Write` keyword in the current
connection.
The old newline is returned and can be used to restore the newline
later.
+ See `Set Timeout` for a similar example.
See `Configuration` section for more information about global and
connection specific configuration.
@@ -393,33 +417,39 @@
def _prompt_is_set(self):
return self._prompt[0] is not None
- def set_encoding(self, encoding):
+ def set_encoding(self, encoding=None, errors=None):
"""Sets the encoding to use for `writing and reading` in the
current connection.
- The old encoding is returned and can be used to restore the
encoding
- later.
+ The given `encoding` specifies the encoding to use when
written/read
+ text is encoded/decoded, and `errors` specifies the error handler
to
+ use if encoding/decoding fails. Either of these can be omitted and
in
+ that case the old value is not affected.
+
+ See `Configuration` section for more information about encoding and
+ error handlers, as well as global and connection specific
configuration
+ in general.
- See `Configuration` section for more information about global and
- connection specific configuration.
+ The old values are returned and can be used to restore the encoding
+ and the error handler later. See `Set Prompt` for a similar
example.
- Setting encoding is a new feature in Robot Framework 2.7.6. Earlier
- versions only supported ASCII.
+ Setting encoding in general is a new feature in Robot Framework
2.7.6
+ and specifying the error handler was added in Robot Framework
2.7.7.
"""
self._verify_connection()
old = self._encoding
- self._set_encoding(encoding)
+ self._set_encoding(encoding or old[0], errors or old[1])
return old
- def _set_encoding(self, encoding):
- self._encoding = encoding
+ def _set_encoding(self, encoding, errors):
+ self._encoding = (encoding, errors)
def _encode(self, text):
if isinstance(text, str):
return text
- return text.encode(self._encoding)
+ return text.encode(*self._encoding)
def _decode(self, bytes):
- return bytes.decode(self._encoding)
+ return bytes.decode(*self._encoding)
def set_default_log_level(self, level):
"""Sets the default log level used for `logging` in the current
connection.
==============================================================================
Revision: c3fb1fdb47f1
Branch: default
Author: Robot Framework Developers ([email protected])
Date: Wed Jan 9 05:40:17 2013
Log: Automated merge with https://robotframework.googlecode.com/hg/
http://code.google.com/p/robotframework/source/detail?r=c3fb1fdb47f1