Index: server/base_utils.py |
diff --git a/server/base_utils.py b/server/base_utils.py |
index 6d683b26deb49d8126b34a421e8539280dc0c958..1c58609a0fbe0dd6a2d0c90729bd3c2306227502 100644 |
--- a/server/base_utils.py |
+++ b/server/base_utils.py |
@@ -244,45 +244,27 @@ def form_ntuples_from_machines(machines, n=2, mapping_func=default_mappings): |
return (ntuples, failures) |
-def parse_machine(machine, user = 'root', port = 22, password = ''): |
+def parse_machine(machine, user='root', password='', port=22): |
""" |
Parse the machine string user:pass@host:port and return it separately, |
if the machine string is not complete, use the default parameters |
when appropriate. |
""" |
- user = user |
- port = port |
- password = password |
+ if '@' in machine: |
+ user, machine = machine.split('@', 1) |
- if re.search('@', machine): |
- machine = machine.split('@') |
+ if ':' in user: |
+ user, password = user.split(':', 1) |
- if re.search(':', machine[0]): |
- machine[0] = machine[0].split(':') |
- user = machine[0][0] |
- password = machine[0][1] |
+ if ':' in machine: |
+ machine, port = machine.split(':', 1) |
+ port = int(port) |
- else: |
- user = machine[0] |
- |
- if re.search(':', machine[1]): |
- machine[1] = machine[1].split(':') |
- hostname = machine[1][0] |
- port = int(machine[1][1]) |
- |
- else: |
- hostname = machine[1] |
- |
- elif re.search(':', machine): |
- machine = machine.split(':') |
- hostname = machine[0] |
- port = int(machine[1]) |
- |
- else: |
- hostname = machine |
+ if not machine or not user: |
+ raise ValueError |
- return hostname, user, password, port |
+ return machine, user, password, port |
def get_public_key(): |