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
 
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
 
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 AND 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
 
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 = TOr(TNonEmptyString, TNone)
a maybe non-empty string
  TMaybeBool = TOr(TBool, TNone)
a maybe boolean (bool or none)
  TMaybeDict = TOr(TDict, TNone)
Maybe a dictionary (dict or None)
  TPositiveInt = TAnd(TInt, WithDesc("EqualGreaterZero")(lambda ...
a positive integer
  TStrictPositiveInt = TAnd(TInt, WithDesc("GreaterThanZero")(la...
a strictly positive integer
  TStrictNegativeInt = TAnd(TInt, WithDesc("LessThanZero")(compa...
a strictly negative integer (0 > value)
  TPositiveFloat = TAnd(TFloat, WithDesc("EqualGreaterZero")(lam...
a positive float
  TJobId = WithDesc("JobId")(TOr(TPositiveInt, TRegex(re.compile...
Job ID
  TNumber = TOr(TInt, TFloat)
Number
  TRelativeJobId = WithDesc("RelativeJobId")(TStrictNegativeInt)
Relative job ID

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")

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")

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

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))

TPositiveInt

a positive integer

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

TStrictPositiveInt

a strictly positive integer

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

TStrictNegativeInt

a strictly negative integer (0 > value)

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

TPositiveFloat

a positive float

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

TJobId

Job ID

Value:
WithDesc("JobId")(TOr(TPositiveInt, TRegex(re.compile("^%s$" % constan\
ts.JOB_ID_TEMPLATE))))