Package ganeti :: Module ht
[hide private]
[frames] | no frames]

Module ht

source code

Module implementing the parameter types code.

Classes [hide private]
  _WrapperBase
  _DescWrapper
Wrapper class for description text.
  _CommentWrapper
Wrapper class for comment.
Functions [hide private]
 
Parens(text)
Enclose text in parens if necessary.
source code
 
WithDesc(text)
Builds wrapper class with description text.
source code
 
Comment(text)
Builds wrapper for adding comment to description text.
source code
 
CombinationDesc(op, args, fn)
Build description for combinating operator.
source code
 
EmptyList()
Returns an empty list.
source code
 
EmptyDict()
Returns an empty dict.
source code
 
TAny(_)
Accepts any value.
source code
 
TNotNone(val)
Checks if the given value is not None.
source code
 
TNone(val)
Checks if the given value is None.
source code
 
TValueNone(val)
Checks if the given value is constants.VALUE_NONE.
source code
 
TBool(val)
Checks if the given value is a boolean.
source code
 
TInt(val)
Checks if the given value is an integer.
source code
 
TFloat(val)
Checks if the given value is a float.
source code
 
TString(val)
Checks if the given value is a string.
source code
 
TTrue(val)
Checks if a given value evaluates to a boolean True value.
source code
 
TElemOf(target_list)
Builds a function that checks if a given value is a member of a list.
source code
 
TList(val)
Checks if the given value is a list.
source code
 
TTuple(val)
Checks if the given value is a tuple.
source code
 
TDict(val)
Checks if the given value is a dictionary.
source code
 
TIsLength(size)
Check is the given container is of the given size.
source code
 
TAnd(*args)
Combine multiple functions using an AND operation.
source code
 
TOr(*args)
Combine multiple functions using an OR operation.
source code
 
TMap(fn, test)
Checks that a modified version of the argument passes the given test.
source code
 
TRegex(pobj)
Checks whether a string matches a specific regular expression.
source code
 
TMaybe(test)
Wrap a test in a TOr(TNone, test).
source code
 
TMaybeValueNone(test)
Used for unsetting values.
source code
 
TMaybeBool(val)
a maybe boolean (bool or none)
source code
 
TMaybeDict(val)
Maybe a dictionary (dict or None)
source code
 
TMaybeList(val)
Maybe a list (list or None)
source code
 
TInstanceOf(cls)
Checks if a given value is an instance of cls.
source code
 
TListOf(my_type)
Checks if a given value is a list with all elements of the same type.
source code
 
TDictOf(key_type, val_type)
Checks a dict type for the type of its key/values.
source code
 
_TStrictDictCheck(require_all, exclusive, items, val)
Helper function for TStrictDict.
source code
 
TStrictDict(require_all, exclusive, items)
Strict dictionary check with specific keys.
source code
 
TItems(items)
Checks individual items of a container.
source code
Variables [hide private]
  _PAREN_RE = re.compile("^[a-zA-Z0-9_-]+$")
  NoDefault = object()
The without-default default value
  NoType = object()
The no-type (value too complex to check it in the type system)
  TNonEmptyString = WithDesc("NonEmptyString")(TAnd(TString, TTr...
a non-empty string
  TMaybeString = TMaybe(TNonEmptyString)
a maybe non-empty string
  TNonNegativeInt = TAnd(TInt, WithDesc("EqualOrGreaterThanZero"...
a non-negative integer (value >= 0)
  TPositiveInt = TAnd(TInt, WithDesc("GreaterThanZero")(lambda v...
a positive integer (value > 0)
  TMaybePositiveInt = TMaybe(TPositiveInt)
a maybe positive integer (positive integer or None)
  TNegativeInt = TAnd(TInt, WithDesc("LessThanZero")(compat.part...
a negative integer (value < 0)
  TNonNegativeFloat = TAnd(TFloat, WithDesc("EqualOrGreaterThanZ...
a positive float
  TJobId = WithDesc("JobId")(TOr(TNonNegativeInt, TRegex(re.comp...
Job ID
  TNumber = TOr(TInt, TFloat)
Number
  TRelativeJobId = WithDesc("RelativeJobId")(TNegativeInt)
Relative job ID
  TMaybeListOf = lambda item_type:

Imports: re, operator, compat, utils, constants


Function Details [hide private]

Parens(text)

source code 

Enclose text in parens if necessary.

Parameters:
  • text - Text

WithDesc(text)

source code 

Builds wrapper class with description text.

Parameters:
  • text (string) - Description text
Returns:
Callable class

Comment(text)

source code 

Builds wrapper for adding comment to description text.

Parameters:
  • text (string) - Comment text
Returns:
Callable class

CombinationDesc(op, args, fn)

source code 

Build description for combinating operator.

Parameters:
  • op (string) - Operator as text (e.g. "and")
  • args (list) - Operator arguments
  • fn (callable) - Wrapped function

EmptyList()

source code 

Returns an empty list.

Decorators:
  • @WithDesc(str([]))

EmptyDict()

source code 

Returns an empty dict.

Decorators:
  • @WithDesc(str({}))

TAny(_)

source code 

Accepts any value.

Decorators:
  • @WithDesc("Anything")

TNotNone(val)

source code 

Checks if the given value is not None.

Decorators:
  • @WithDesc("NotNone")

TNone(val)

source code 

Checks if the given value is None.

Decorators:
  • @WithDesc("None")

TValueNone(val)

source code 

Checks if the given value is constants.VALUE_NONE.

Decorators:
  • @WithDesc("ValueNone")

TBool(val)

source code 

Checks if the given value is a boolean.

Decorators:
  • @WithDesc("Boolean")

TInt(val)

source code 

Checks if the given value is an integer.

Decorators:
  • @WithDesc("Integer")

TFloat(val)

source code 

Checks if the given value is a float.

Decorators:
  • @WithDesc("Float")

TString(val)

source code 

Checks if the given value is a string.

Decorators:
  • @WithDesc("String")

TTrue(val)

source code 

Checks if a given value evaluates to a boolean True value.

Decorators:
  • @WithDesc("EvalToTrue")

TList(val)

source code 

Checks if the given value is a list.

Decorators:
  • @WithDesc("List")

TTuple(val)

source code 

Checks if the given value is a tuple.

Decorators:
  • @WithDesc("Tuple")

TDict(val)

source code 

Checks if the given value is a dictionary.

Decorators:
  • @WithDesc("Dictionary")

TRegex(pobj)

source code 

Checks whether a string matches a specific regular expression.

Parameters:
  • pobj - Compiled regular expression as returned by re.compile

TMaybe(test)

source code 

Wrap a test in a TOr(TNone, test).

This makes it easier to define TMaybe* types.

TMaybeBool(val)

source code 

a maybe boolean (bool or none)

Decorators:
  • @WithDesc("Boolean")

TMaybeDict(val)

source code 

Maybe a dictionary (dict or None)

Decorators:
  • @WithDesc("Dictionary")

TMaybeList(val)

source code 

Maybe a list (list or None)

Decorators:
  • @WithDesc("List")

TInstanceOf(cls)

source code 

Checks if a given value is an instance of cls.

Parameters:
  • cls (class) - Class object

TStrictDict(require_all, exclusive, items)

source code 

Strict dictionary check with specific keys.

Parameters:
  • require_all (boolean) - Whether all keys in items are required
  • exclusive (boolean) - Whether only keys listed in items should be accepted
  • items (dictionary) - Mapping from key (string) to verification function

TItems(items)

source code 

Checks individual items of a container.

If the verified value and the list of expected items differ in length, this check considers only as many items as are contained in the shorter list. Use TIsLength to enforce a certain length.

Parameters:
  • items (list) - List of checks

Variables Details [hide private]

TNonEmptyString

a non-empty string

Value:
WithDesc("NonEmptyString")(TAnd(TString, TTrue))

TNonNegativeInt

a non-negative integer (value >= 0)

Value:
TAnd(TInt, WithDesc("EqualOrGreaterThanZero")(lambda v: v >= 0))

TPositiveInt

a positive integer (value > 0)

Value:
TAnd(TInt, WithDesc("GreaterThanZero")(lambda v: v > 0))

TNegativeInt

a negative integer (value < 0)

Value:
TAnd(TInt, WithDesc("LessThanZero")(compat.partial(operator.gt, 0)))

TNonNegativeFloat

a positive float

Value:
TAnd(TFloat, WithDesc("EqualOrGreaterThanZero")(lambda v: v >= 0.0))

TJobId

Job ID

Value:
WithDesc("JobId")(TOr(TNonNegativeInt, TRegex(re.compile("^%s$" % cons\
tants.JOB_ID_TEMPLATE))))