Fix X509CertError definition in Haskell codebase
[ganeti-local] / lib / ht.py
index c28ff1a..2613be3 100644 (file)
--- a/lib/ht.py
+++ b/lib/ht.py
@@ -352,6 +352,14 @@ TNumber = TOr(TInt, TFloat)
 TRelativeJobId = WithDesc("RelativeJobId")(TStrictNegativeInt)
 
 
+def TInstanceOf(my_inst):
+  """Checks if a given value is an instance of my_inst.
+
+  """
+  desc = WithDesc("Instance of %s" % (Parens(my_inst), ))
+  return desc(lambda val: isinstance(val, my_inst))
+
+
 def TListOf(my_type):
   """Checks if a given value is a list with all elements of the same type.
 
@@ -360,6 +368,9 @@ def TListOf(my_type):
   return desc(TAnd(TList, lambda lst: compat.all(my_type(v) for v in lst)))
 
 
+TMaybeListOf = lambda item_type: TOr(TNone, TListOf(item_type))
+
+
 def TDictOf(key_type, val_type):
   """Checks a dict type for the type of its key/values.