summaryrefslogtreecommitdiff
path: root/paramiko/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'paramiko/util.py')
-rw-r--r--paramiko/util.py12
1 files changed, 12 insertions, 0 deletions
diff --git a/paramiko/util.py b/paramiko/util.py
index f4ee3ad..88ca2bc 100644
--- a/paramiko/util.py
+++ b/paramiko/util.py
@@ -320,3 +320,15 @@ def constant_time_bytes_eq(a, b):
for i in (xrange if PY2 else range)(len(a)):
res |= byte_ord(a[i]) ^ byte_ord(b[i])
return res == 0
+
+
+class ClosingContextManager(object):
+ def __enter__(self):
+ return self
+
+ def __exit__(self, type, value, traceback):
+ self.close()
+
+
+def clamp_value(minimum, val, maximum):
+ return max(minimum, min(val, maximum))