3 new revisions:
Revision: 96ce20345501
Author: Anssi Syrjäsalo <[email protected]>
Date: Mon Jul 8 04:16:30 2013
Log: Encoding can be configured
http://code.google.com/p/robotframework-sshlibrary/source/detail?r=96ce20345501
Revision: b200b66f5745
Author: Anssi Syrjäsalo <[email protected]>
Date: Wed Jul 10 04:58:27 2013
Log: Remove old outputs before running tests
http://code.google.com/p/robotframework-sshlibrary/source/detail?r=b200b66f5745
Revision: ab8d288ffb18
Author: Anssi Syrjäsalo <[email protected]>
Date: Wed Jul 10 05:02:36 2013
Log: Encoding supported by Python and Java clients
http://code.google.com/p/robotframework-sshlibrary/source/detail?r=ab8d288ffb18
==============================================================================
Revision: 96ce20345501
Author: Anssi Syrjäsalo <[email protected]>
Date: Mon Jul 8 04:16:30 2013
Log: Encoding can be configured
http://code.google.com/p/robotframework-sshlibrary/source/detail?r=96ce20345501
Added:
/atest/non-ascii_characters.txt
/atest/resources/scripts/aaääöö.txt
Modified:
/atest/put_file.txt
/atest/resources/ssh_library_resources.txt
/src/SSHLibrary/abstractclient.py
/src/SSHLibrary/library.py
/src/SSHLibrary/pythonclient.py
=======================================
--- /dev/null
+++ /atest/non-ascii_characters.txt Mon Jul 8 04:16:30 2013
@@ -0,0 +1,19 @@
+*** Settings ***
+Default Tags pybot jybot
+Suite Setup Login And Move Test Files
+Suite Teardown Remove Test Files and Close Connections
+Resource resources/ssh_library_resources.txt
+
+*** Test Cases ***
+Listing Files Containing Non-ASCII Characters
+ ${output}= Execute Command ls
+ Should Contain ${output} aaääöö.txt
+
+Reading And Writing
+ Write Bare ./${INTERACTIVE TEST SCRIPT NAME}\n
+ ${output} = Read Until name?
+ Write Bare ääöö\n
+ ${output2} = Read Until Prompt
+ Should Contain ${output} Give your name?
+ Should Contain ${output2} Hello ääöö
+ Should Contain ${output2} ${PROMPT}
=======================================
--- /dev/null
+++ /atest/resources/scripts/aaääöö.txt Mon Jul 8 04:16:30 2013
@@ -0,0 +1,4 @@
+This is a test file used to test non-ASCII character encoding
+
+ää
+öö
=======================================
--- /atest/put_file.txt Tue Jun 18 07:13:27 2013
+++ /atest/put_file.txt Mon Jul 8 04:16:30 2013
@@ -2,7 +2,7 @@
Documentation This suite contains test for 'Put File 'keywords These
tests use some dummy test files from under the scripts directory.
Force Tags pybot jybot
Suite Setup Login As Valid User
-Suite Teardown Run Keywords Close Connection Remove Local Tempdir
+Suite Teardown Run Keywords Remove Test Files and Close Connections
Remove Local Tempdir
Resource resources/ssh_library_resources.txt
Library String
=======================================
--- /atest/resources/ssh_library_resources.txt Mon Jul 1 06:01:29 2013
+++ /atest/resources/ssh_library_resources.txt Mon Jul 8 04:16:30 2013
@@ -19,6 +19,8 @@
${TEST FILE PATTERN} ${SCRIPTS}test*.txt
${FILE WITH NEWLINES NAME} file_with_newlines.txt
${FILE WITH NEWLINES} ${SCRIPTS}${FILE WITH NEWLINES NAME}
+${FILE WITH NON-ASCII NAME} aaääöö.txt
+${FILE WITH NON-ASCII} ${SCRIPTS}${FILE WITH NON-ASCII NAME}
${SPECIAL CHARS FILE} ${SCRIPTS}foo%2Fbar.txt
*** Keywords ***
@@ -28,9 +30,10 @@
Put File ${INTERACTIVE TEST SCRIPT} ${USER HOME}/${INTERACTIVE TEST
SCRIPT NAME}
Put File ${REPEAT TEST SCRIPT} ${USER HOME}/${REPEAT TEST SCRIPT
NAME}
Put File ${FILE WITH NEWLINES} ${USER HOME}/
+ Put File ${FILE WITH NON-ASCII} ${USER HOME}/
Remove Test Files And Close Connections
- Execute Command rm -f ${INTERACTIVE TEST SCRIPT NAME} ${TEST SCRIPT
NAME} ${REPEAT TEST SCRIPT NAME} ${COUNTER NAME} ${FILE WITH NEWLINES NAME}
+ Execute Command rm -f ${INTERACTIVE TEST SCRIPT NAME} ${TEST SCRIPT
NAME} ${REPEAT TEST SCRIPT NAME} ${COUNTER NAME} ${FILE WITH NEWLINES NAME}
${FILE WITH NON-ASCII NAME}
Close All Connections
Login As Valid User
=======================================
--- /src/SSHLibrary/abstractclient.py Mon Jun 17 07:33:08 2013
+++ /src/SSHLibrary/abstractclient.py Mon Jul 8 04:16:30 2013
@@ -33,7 +33,8 @@
class ClientConfig(Configuration):
def __init__(self, host, alias=None, port=22, timeout=3, newline='LF',
- prompt=None, term_type='vt100', width=80, height=24):
+ prompt=None, encoding='utf-8', term_type='vt100',
width=80,
+ height=24):
Configuration.__init__(self,
host=StringEntry(host),
alias=StringEntry(alias),
@@ -41,6 +42,7 @@
timeout=TimeEntry(timeout),
newline=NewlineEntry(newline),
prompt=StringEntry(prompt),
+ encoding=StringEntry(encoding),
term_type=StringEntry(term_type),
width=IntegerEntry(width),
height=IntegerEntry(height))
@@ -53,10 +55,11 @@
"""
def __init__(self, host, alias=None, port=22, timeout=3, newline='LF',
- prompt=None, term_type='vt100', width=80, height=24):
+ prompt=None, encoding='utf-8', term_type='vt100',
width=80,
+ height=24):
"""Create new SSHClient based on arguments."""
self.config = ClientConfig(host, alias, port, timeout, newline,
- prompt, term_type, width, height)
+ prompt, encoding, term_type, width,
height)
self.client = self._create_client()
self._commands = []
@@ -148,11 +151,6 @@
:param bool add_newline: if True, a newline will be added to
`text`.
"""
self._ensure_prompt_is_set()
- try:
- text = str(text)
- except UnicodeError:
- raise SSHClientException('Invalid input, only ASCII
characters '
- 'are allowed. Got: %s' % text)
if add_newline:
text += self.config.newline
self._write(text)
@@ -235,13 +233,14 @@
% (expected, timeout))
def _read_until(self, matcher, expected, timeout=None):
- ret = ''
+ ret = u''
timeout = TimeEntry(timeout) if timeout else
self.config.get('timeout')
start_time = time.time()
while time.time() < float(timeout.value) + start_time:
ret += self._read_char()
if matcher(ret):
return ret
+
raise SSHClientException("No match found for '%s'
in %s\nOutput:\n%s"
% (expected, timeout, ret))
=======================================
--- /src/SSHLibrary/library.py Mon Jul 1 06:01:29 2013
+++ /src/SSHLibrary/library.py Mon Jul 8 04:16:30 2013
@@ -57,7 +57,7 @@
ROBOT_LIBRARY_VERSION = __version__
def __init__(self, timeout=3, newline='LF', prompt=None,
- loglevel='INFO'):
+ encoding='utf-8', loglevel='INFO'):
"""SSH Library allows some import time configuration.
`timeout`, `newline` and `prompt` set default values for new
@@ -74,14 +74,15 @@
| Library | SSHLibrary | timeout=10 | prompt=> |
"""
self._cache = ConnectionCache()
- self._config = DefaultConfig(timeout, newline, prompt, loglevel)
+ self._config = DefaultConfig(timeout, newline, prompt, loglevel,
+ encoding)
@property
def ssh_client(self):
return self._cache.current
def set_default_configuration(self, timeout=None, newline=None,
- prompt=None, loglevel=None):
+ prompt=None, encoding=None,
loglevel=None):
"""Update the default configuration values.
Only parameters whose value is other than `None` are updated.
@@ -90,10 +91,11 @@
| Set Default Configuration | newline=CRLF | prompt=$ |
"""
self._config.update(timeout=timeout, newline=newline,
prompt=prompt,
- loglevel=loglevel)
+ loglevel=loglevel, encoding=encoding)
def set_client_configuration(self, timeout=None, newline=None,
prompt=None,
- term_type='vt100', width=80, height=24):
+ encoding=None, term_type='vt100',
width=80,
+ height=24):
"""Update the client configuration values.
Works on the currently selected connection. At least one connection
@@ -105,12 +107,13 @@
| Set Client Configuration | term_type=ansi | timeout=2 hours |
"""
self.ssh_client.config.update(timeout=timeout, newline=newline,
- prompt=prompt, term_type=term_type,
+ prompt=prompt, encoding=encoding,
+ term_type=term_type,
width=width, height=height)
def open_connection(self, host, alias=None, port=22, timeout=None,
- newline=None, prompt=None, term_type='vt100',
- width=80, height=24):
+ newline=None, prompt=None, encoding=None,
+ term_type='vt100', width=80, height=24):
"""Opens a new SSH connection to given `host` and `port`.
Possible already opened connections are cached.
@@ -144,8 +147,9 @@
timeout = timeout or self._config.timeout
newline = newline or self._config.newline
prompt = prompt or self._config.prompt
+ encoding = encoding or self._config.encoding
client = SSHClient(host, alias, port, timeout, newline, prompt,
- term_type, width, height)
+ encoding, term_type, width, height)
return self._cache.register(client, alias)
def get_connection_id(self):
@@ -319,6 +323,7 @@
"""
self._info("Executing command '%s'" % command)
opts = self._output_options(return_stdout, return_stderr,
return_rc)
+ command = command.encode(self._config.encoding)
stdout, stderr, rc = self.ssh_client.execute_command(command)
return self._return_command_output(stdout, stderr, rc, *opts)
@@ -368,9 +373,9 @@
return_stdout, return_stderr, return_rc):
ret = []
if return_stdout:
- ret.append(stdout.rstrip('\n'))
+ ret.append(stdout.decode(self._config.encoding).rstrip('\n'))
if return_stderr:
- ret.append(stderr.rstrip('\n'))
+ ret.append(stderr.decode(self._config.encoding).rstrip('\n'))
if return_rc:
ret.append(rc)
if len(ret) == 1:
@@ -398,8 +403,9 @@
self._write(text)
def _write(self, text, add_newline=False):
- self._info("Writing %s" % repr(text))
+ self._info("Writing %s" % text)
try:
+ text = text.encode(self._config.encoding)
self.ssh_client.write(text, add_newline)
except SSHClientException, e:
raise RuntimeError(e)
@@ -480,7 +486,7 @@
| Write Until Expected Output | ps -ef| grep myprocess\\n |
myprocess |
| ... | 5s | 0.5s |
- This will write the 'ps -ef | grep myprocess\\n' until 'myprocess'
+ This will write the 'ps -ef | grep myprocess\\n' until 'myprocess'
appears on the output. The command is written every 0.5 seconds and
the keyword will fail if 'myprocess' does not appear on the output
in
5 seconds.
@@ -605,9 +611,10 @@
class DefaultConfig(Configuration):
- def __init__(self, timeout, newline, prompt, loglevel):
+ def __init__(self, timeout, newline, prompt, loglevel, encoding):
Configuration.__init__(self,
timeout=TimeEntry(timeout or 3),
newline=NewlineEntry(newline or 'LF'),
prompt=StringEntry(prompt),
- loglevel=LogLevelEntry(loglevel or 'INFO'))
+ loglevel=LogLevelEntry(loglevel or 'INFO'),
+ encoding=StringEntry(encoding))
=======================================
--- /src/SSHLibrary/pythonclient.py Thu Aug 30 00:50:42 2012
+++ /src/SSHLibrary/pythonclient.py Mon Jul 8 04:16:30 2013
@@ -94,9 +94,16 @@
return data
def _read_char(self):
+ data = ''
if self.shell.recv_ready():
- return self.shell.recv(1)
- return ''
+ while True:
+ try:
+ data += self.shell.recv(1)
+ data.decode(self.config.encoding)
+ break
+ except UnicodeDecodeError:
+ pass
+ return data.decode(self.config.encoding)
def _create_sftp_client(self):
return SFTPClient(self.client)
==============================================================================
Revision: b200b66f5745
Author: Anssi Syrjäsalo <[email protected]>
Date: Wed Jul 10 04:58:27 2013
Log: Remove old outputs before running tests
http://code.google.com/p/robotframework-sshlibrary/source/detail?r=b200b66f5745
Modified:
/atest/run_atests.sh
=======================================
--- /atest/run_atests.sh Tue Jun 18 03:59:17 2013
+++ /atest/run_atests.sh Wed Jul 10 04:58:27 2013
@@ -3,10 +3,14 @@
if [ "$1" == "jython" ]; then
shift
- jybot $COMMON_ARGS -P lib/trilead-ssh2-build213.jar -d
$OUTPUT_ROOT/jython -i jybot $*
+ OUTPUT_DIR="$OUTPUT_ROOT/jython"
+ rm -rf $OUTPUT_DIR 2> /dev/null
+ jybot $COMMON_ARGS -P lib/trilead-ssh2-build213.jar -d $OUTPUT_DIR -i
jybot $*
elif [ "$1" == "python" ]; then
shift
- pybot $COMMON_ARGS -d $OUTPUT_ROOT/python -i pybot $*
+ OUTPUT_DIR="$OUTPUT_ROOT/python"
+ rm -rf $OUTPUT_DIR 2> /dev/null
+ pybot $COMMON_ARGS -d $OUTPUT_DIR -i pybot $*
else
echo "Usage: atest/run_atests.sh (python|jython) <target>"
exit 1
==============================================================================
Revision: ab8d288ffb18
Author: Anssi Syrjäsalo <[email protected]>
Date: Wed Jul 10 05:02:36 2013
Log: Encoding supported by Python and Java clients
http://code.google.com/p/robotframework-sshlibrary/source/detail?r=ab8d288ffb18
Modified:
/atest/non-ascii_characters.txt
/src/SSHLibrary/abstractclient.py
/src/SSHLibrary/javaclient.py
/src/SSHLibrary/library.py
/src/SSHLibrary/pythonclient.py
=======================================
--- /atest/non-ascii_characters.txt Mon Jul 8 04:16:30 2013
+++ /atest/non-ascii_characters.txt Wed Jul 10 05:02:36 2013
@@ -12,8 +12,8 @@
Reading And Writing
Write Bare ./${INTERACTIVE TEST SCRIPT NAME}\n
${output} = Read Until name?
- Write Bare ääöö\n
+ Write Bare aaääöö\n
${output2} = Read Until Prompt
Should Contain ${output} Give your name?
- Should Contain ${output2} Hello ääöö
+ Should Contain ${output2} Hello aaääöö
Should Contain ${output2} ${PROMPT}
=======================================
--- /src/SSHLibrary/abstractclient.py Mon Jul 8 04:16:30 2013
+++ /src/SSHLibrary/abstractclient.py Wed Jul 10 05:02:36 2013
@@ -233,14 +233,17 @@
% (expected, timeout))
def _read_until(self, matcher, expected, timeout=None):
- ret = u''
+ ret = ''
timeout = TimeEntry(timeout) if timeout else
self.config.get('timeout')
start_time = time.time()
while time.time() < float(timeout.value) + start_time:
- ret += self._read_char()
- if matcher(ret):
- return ret
-
+ try:
+ ret += self._read_char()
+ decoded_string = ret.decode(self.config.encoding)
+ if matcher(decoded_string):
+ return decoded_string
+ except UnicodeDecodeError:
+ pass
raise SSHClientException("No match found for '%s'
in %s\nOutput:\n%s"
% (expected, timeout, ret))
@@ -404,8 +407,9 @@
class AbstractCommand(object):
"""Base class for remote commands."""
- def __init__(self, command):
+ def __init__(self, command, encoding):
self._command = command
+ self._encoding = encoding
self._session = None
def run_in(self, session):
=======================================
--- /src/SSHLibrary/javaclient.py Wed Aug 29 05:46:34 2012
+++ /src/SSHLibrary/javaclient.py Wed Jul 10 05:02:36 2013
@@ -55,7 +55,7 @@
self.client.close()
def _start_command(self, command):
- cmd = RemoteCommand(command)
+ cmd = RemoteCommand(command, self.config.encoding)
cmd.run_in(self.client.openSession())
return cmd
@@ -72,19 +72,18 @@
self._writer.flush()
def _read(self):
- data = ''
- if self._stdout.available():
- buf = jarray.zeros(self._stdout.available(), 'b')
- self._stdout.read(buf)
- data += ''.join([chr(b) for b in buf])
- return data
+ data = ''
+ if self._stdout.available():
+ buf = jarray.zeros(self._stdout.available(), 'b')
+ self._stdout.read(buf)
+ data = ''.join([chr(c) for c in buf])
+ return data
def _read_char(self):
- if self._stdout.available():
- buf = jarray.zeros(1, 'b')
- self._stdout.read(buf)
- return chr(buf[0])
- return ''
+ data = ''
+ if self._stdout.available():
+ data = chr(self._stdout.read())
+ return data
def _create_sftp_client(self):
return SFTPClient(self.client)
@@ -167,7 +166,7 @@
return stdout, stderr, rc
def _read_from_stream(self, stream):
- reader = BufferedReader(InputStreamReader(StreamGobbler(stream)))
+ reader = BufferedReader(InputStreamReader(StreamGobbler(stream),
self._encoding))
result = ''
line = reader.readLine()
while line is not None:
=======================================
--- /src/SSHLibrary/library.py Mon Jul 8 04:16:30 2013
+++ /src/SSHLibrary/library.py Wed Jul 10 05:02:36 2013
@@ -373,9 +373,9 @@
return_stdout, return_stderr, return_rc):
ret = []
if return_stdout:
- ret.append(stdout.decode(self._config.encoding).rstrip('\n'))
+ ret.append(stdout.rstrip('\n'))
if return_stderr:
- ret.append(stderr.decode(self._config.encoding).rstrip('\n'))
+ ret.append(stderr.rstrip('\n'))
if return_rc:
ret.append(rc)
if len(ret) == 1:
=======================================
--- /src/SSHLibrary/pythonclient.py Mon Jul 8 04:16:30 2013
+++ /src/SSHLibrary/pythonclient.py Wed Jul 10 05:02:36 2013
@@ -76,7 +76,7 @@
self.client.close()
def _start_command(self, command):
- cmd = RemoteCommand(command)
+ cmd = RemoteCommand(command, self.config.encoding)
cmd.run_in(self.client.get_transport().open_session())
return cmd
@@ -94,16 +94,10 @@
return data
def _read_char(self):
- data = ''
- if self.shell.recv_ready():
- while True:
- try:
- data += self.shell.recv(1)
- data.decode(self.config.encoding)
- break
- except UnicodeDecodeError:
- pass
- return data.decode(self.config.encoding)
+ data = ''
+ if self.shell.recv_ready():
+ data = self.shell.recv(1)
+ return data
def _create_sftp_client(self):
return SFTPClient(self.client)
@@ -158,8 +152,8 @@
self._session.exec_command(self._command)
def _read_outputs(self):
- stdout = self._session.makefile('rb', -1).read()
- stderr = self._session.makefile_stderr('rb', -1).read()
+ stdout = self._session.makefile('rb',
-1).read().decode(self._encoding)
+ stderr = self._session.makefile_stderr('rb',
-1).read().decode(self._encoding)
rc = self._session.recv_exit_status()
self._session.close()
return stdout, stderr, rc
--
---
You received this message because you are subscribed to the Google Groups "robotframework-commit" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.