TransRead: don't parse URL twice in case of ssh proto
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Thu, 19 Sep 2013 10:41:02 +0000 (13:41 +0300)
committerArtem Bityutskiy <artem.bityutskiy@intel.com>
Thu, 19 Sep 2013 11:36:23 +0000 (14:36 +0300)
_open_url() method already parses the URL. Let's use it instead of doing
parsing second time.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Artem Bityutskiy <artem.bityutskiy@intel.com>
bmaptools/TransRead.py

index 171b31fc267f258c7ec9989c5376a89a3b5f96cd..5790b15798b49d1794c2c51b2bfc34ebdee3c6fa 100644 (file)
@@ -339,7 +339,7 @@ class TransRead:
         except IOError as err:
             raise Error("cannot open file '%s': %s" % (self.name, err))
 
-    def _open_url_ssh(self, url):
+    def _open_url_ssh(self, parsed_url):
         """
         This function opens a file on a remote host using SSH. The URL has to
         have this format: "ssh://username@hostname:path". Currently we only
@@ -348,8 +348,6 @@ class TransRead:
 
         import subprocess
 
-        # Parse the URL
-        parsed_url = urlparse.urlparse(url)
         username = parsed_url.username
         password = parsed_url.password
         path = parsed_url.path
@@ -443,14 +441,15 @@ class TransRead:
         import socket
 
         parsed_url = urlparse.urlparse(url)
-        username = parsed_url.username
-        password = parsed_url.password
 
         if parsed_url.scheme == "ssh":
             # Unfortunately, liburl2 does not handle "ssh://" URLs
-            self._open_url_ssh(url)
+            self._open_url_ssh(parsed_url)
             return
 
+        username = parsed_url.username
+        password = parsed_url.password
+
         if username and password:
             # Unfortunately, in order to handle URLs which contain user name
             # and password (e.g., http://user:password@my.site.org), we need to