summaryrefslogtreecommitdiff
path: root/paramiko/config.py
diff options
context:
space:
mode:
authorChris Rose <offline@offby1.net>2018-05-16 10:29:46 -0400
committerChris Rose <offline@offby1.net>2018-05-16 17:18:50 -0400
commit2bc68629f386e1eb4771cc363d64665e51eebea0 (patch)
treead7ced37cfb43d8b084b051c9d802c9f1904f331 /paramiko/config.py
parent413bf37df7c9bf88d70d2b046935687c072980d4 (diff)
downloadparamiko-2bc68629f386e1eb4771cc363d64665e51eebea0.tar.gz
Add an SSHConfig dict to provide type conversion helpers
Diffstat (limited to 'paramiko/config.py')
-rw-r--r--paramiko/config.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/paramiko/config.py b/paramiko/config.py
index 038d84ea..22e2e2b3 100644
--- a/paramiko/config.py
+++ b/paramiko/config.py
@@ -21,6 +21,7 @@
Configuration file (aka ``ssh_config``) support.
"""
+import collections
import fnmatch
import os
import re
@@ -295,3 +296,28 @@ class LazyFqdn(object):
# Cache
self.fqdn = fqdn
return self.fqdn
+
+
+class SSHConfigDict(collections.UserDict):
+ """A dictionary wrapper for ssh host configurations.
+
+ This class introduces some usage niceties for consumers of SSHConfig,
+ specifically around the issue of variable type conversions. This offers
+ as_bool(key) and as_int(key) for the current raw string values in
+ SSHConfig"""
+
+ def __init__(self, initialdata=None):
+ super(SSHConfigDict, self).__init__(initialdata)
+
+ def as_bool(self, key):
+ """Express the key as a boolean value. Variations on 'yes' or boolean values
+ are accepted."""
+ val = self[key]
+ if isinstance(val, bool):
+ return val
+ return val.lower() == 'yes'
+
+ def as_int(self, key):
+ """Express the key as a true integer, if possible. Raises an Error otherwise
+ (following conventional int conversion rules)"""
+ return int(self[key])