summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornoah <noah@656d521f-e311-0410-88e0-e7920216d269>2006-08-18 23:25:38 +0000
committernoah <noah@656d521f-e311-0410-88e0-e7920216d269>2006-08-18 23:25:38 +0000
commit573775a600566afcf59f0a2539444bd3674d8618 (patch)
treeda0ae05cdc7d0b26b895375fdfb70ea6410733a3
parentd7f7bd444dd2b7076e1116c3beb072f2b3834600 (diff)
downloadpexpect-573775a600566afcf59f0a2539444bd3674d8618.tar.gz
Added parse for host connect string.
git-svn-id: http://pexpect.svn.sourceforge.net/svnroot/pexpect/trunk@408 656d521f-e311-0410-88e0-e7920216d269
-rwxr-xr-xpexpect/examples/hive.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/pexpect/examples/hive.py b/pexpect/examples/hive.py
index 1f06c00..8844f2d 100755
--- a/pexpect/examples/hive.py
+++ b/pexpect/examples/hive.py
@@ -201,13 +201,30 @@ def resync (hive, hive_names, timeout=2, max_attempts=5):
so that servers that are already at the prompt will not slow
things down too much. If a server does match a prompt then
keep asking until it stops. This is a best effort to consume
- all input. It's kind of kludgy.
+ all input. It's kind of kludgy. Note that this will always
+ introduce a delay equal to the timeout for each machine. So for
+ 10 machines with a 2 second delay you will get AT LEAST a 20 second delay.
"""
+ # TODO This is ideal for threading.
for name in hive_names:
for attempts in xrange(0, max_attempts):
if not hive[name].prompt(timeout=timeout):
break
+def parse_host_connect_string (hcs):
+ """This parses a host connection string in the form username:password@hostname:port.
+ All fields are options expcet hostname. A dictionary is returned with all four keys.
+ Keys that were not included are set to None. Note that if your password has
+ the '@' character then you must backslash escape it.
+ """
+ if '@' in hcs:
+ p = re.compile (r'(?P<username>[^@:]*)(:?)(?P<password>.*)(?!\\)@(?P<hostname>[^:]*):?(?P<port>[0-9]*)')
+ else:
+ p = re.compile (r'(?P<username>)(?P<password>)(?P<hostname>[^:]*):?(?P<port>[0-9]*)')
+ m = p.search (hcs)
+ d = m.groupdict()
+ return m.groupdict()
+
if __name__ == "__main__":
try:
start_time = time.time()