Revision: 94
Author: janne.t.harkonen
Date: Wed Nov 3 06:48:16 2010
Log: Got rid of DataError
http://code.google.com/p/robotframework-sshlibrary/source/detail?r=94
Modified:
/trunk/src/SSHLibrary/__init__.py
/trunk/src/SSHLibrary/client.py
/trunk/src/SSHLibrary/javaclient.py
/trunk/src/SSHLibrary/pythonclient.py
=======================================
--- /trunk/src/SSHLibrary/__init__.py Wed Nov 3 06:30:21 2010
+++ /trunk/src/SSHLibrary/__init__.py Wed Nov 3 06:48:16 2010
@@ -18,10 +18,10 @@
import re
import posixpath
-from robot.errors import DataError
from robot import utils
from connectioncache import ConnectionCache
+from client import AuthenticationException
if utils.is_jython:
from javaclient import SSHClient
else:
@@ -209,17 +209,17 @@
% (self._host, self._port, username))
try:
self._client.login_with_public_key(username, keyfile, password)
- except DataError:
- raise DataError('Login with public key failed')
+ except AuthenticationException:
+ raise RuntimeError('Login with public key failed')
return self._prompt and self.read_until_prompt() or self.read()
def _verify_key_file(self, keyfile):
if not os.path.exists(keyfile):
- raise DataError("Given key file '%s' does not exist" % keyfile)
+ raise RuntimeError("Given key file '%s' does not exist" %
keyfile)
try:
open(keyfile).close()
except IOError:
- raise DataError("Could not read key file '%s'" % keyfile)
+ raise RuntimeError("Could not read key file '%s'" % keyfile)
def execute_command(self, command, ret_mode='stdout'):
=======================================
--- /trunk/src/SSHLibrary/client.py Wed Nov 3 06:30:21 2010
+++ /trunk/src/SSHLibrary/client.py Wed Nov 3 06:48:16 2010
@@ -12,6 +12,9 @@
# See the License for the specific language governing permissions and
# limitations under the License.
+class AuthenticationException(RuntimeError): pass
+
+
class SSHLibraryClient(object):
def put_file(self, source, dest, mode, newline_char):
=======================================
--- /trunk/src/SSHLibrary/javaclient.py Wed Nov 3 06:30:21 2010
+++ /trunk/src/SSHLibrary/javaclient.py Wed Nov 3 06:48:16 2010
@@ -14,15 +14,15 @@
import jarray
-from java.io import File, BufferedReader, InputStreamReader, IOException,
FileOutputStream
+from java.io import (File, BufferedReader, InputStreamReader, IOException,
+ FileOutputStream)
try:
from com.trilead.ssh2 import StreamGobbler, Connection, SFTPv3Client,
SFTPException
except ImportError:
raise ImportError('Importing Trilead SSH classes failed. '
'Make sure you have the Trilead jar file in
CLASSPATH.')
-from robot.errors import DataError
-from client import SSHLibraryClient
+from client import SSHLibraryClient, AuthenticationException
class SSHClient(SSHLibraryClient):
@@ -34,14 +34,11 @@
def login(self, username, password):
if not self.client.authenticateWithPassword(username, password):
- raise AssertionError("Authentication failed for user: %s" %
username)
+ raise AuthenticationException("Authentication failed for
user: %s" % username)
def login_with_public_key(self, username, key, password):
- try:
- if not self.client.authenticateWithPublicKey(username,
File(key), password):
- raise AssertionError("Authentication failed for
user: %s" % username)
- except IOException:
- raise DataError()
+ if not self.client.authenticateWithPublicKey(username, File(key),
password):
+ raise AuthenticationException()
def close(self):
self.client.close()
=======================================
--- /trunk/src/SSHLibrary/pythonclient.py Wed Nov 3 06:30:21 2010
+++ /trunk/src/SSHLibrary/pythonclient.py Wed Nov 3 06:48:16 2010
@@ -20,8 +20,7 @@
raise ImportError('Importing paramiko SSH module or its dependencies
failed. '
'Make sure you have the required modules installed.')
-from robot.errors import DataError
-from client import SSHLibraryClient
+from client import SSHLibraryClient, AuthenticationException
# There doesn't seem to be a simpler way to increase banner timeout
def _monkey_patched_start_client(self, event=None):
@@ -51,7 +50,7 @@
self.client.connect(self.host, self.port, username, password,
key_filename=keyfile)
except paramiko.AuthenticationException:
- raise DataError()
+ raise AuthenticationException()
def close(self):
self.client.close()