<s> from conary import errors <EOL> class MissingParameterError ( errors . WebError ) : <EOL> def __init__ ( self , param ) : <EOL> self . param = param <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % self . param <EOL> class BadParameterError ( errors . WebError ) : <EOL> def __init__ ( self , param , badvalue ) : <EOL> self . param = param <EOL> self . badvalue = badvalue <EOL> def __str__ ( self ) : <EOL> return "<STR_LIT>" % ( self . badvalue , self . param ) <EOL> def strFields ( ** params ) : <EOL> """<STR_LIT>""" <EOL> def deco ( func ) : <EOL> def wrapper ( self , ** kw ) : <EOL> for name , default in params . iteritems ( ) : <EOL> if name in kw : <EOL> value = str ( kw [ name ] ) <EOL> elif default is None : <EOL> raise MissingParameterError ( str ( name ) ) <EOL> else : <EOL> value = default <EOL> kw [ name ] = value <EOL> return func ( self , ** kw ) <EOL> return wrapper <EOL> return deco <EOL> def intFields ( ** params ) : <EOL> """<STR_LIT>""" <EOL> def deco ( func ) : <EOL> def wrapper ( self , ** kw ) : <EOL> for name , default in params . iteritems ( ) : <EOL> if name in kw : <EOL> try : <EOL> value = int ( kw [ name ] ) <EOL> except ValueError , ve : <EOL> raise BadParameterError ( param = name , badvalue = kw [ name ] ) <EOL> elif default is None : <EOL> raise MissingParameterError ( str ( name ) ) <EOL> else : <EOL> value = default <EOL> kw [ name ] = value <EOL> return func ( self , ** kw ) <EOL> return wrapper <EOL> return deco <EOL> def listFields ( memberType , ** params ) : <EOL> def deco ( func ) : <EOL> def wrapper ( self , ** kw ) : <EOL> for name , default in params . iteritems ( ) : <EOL> if name in kw : <EOL> if not isinstance ( kw [ name ] , list ) : <EOL> value = [ memberType ( kw [ name ] ) ] <EOL> else : <EOL> value = [ memberType ( x ) for x in kw [ name ] ] <EOL> elif default is None : <EOL> raise MissingParameterError ( name ) <EOL> else : <EOL> value = default <EOL> kw [ name ] = value <EOL> return func ( self , ** kw ) <EOL> return wrapper <EOL> return deco <EOL> def boolFields ( ** params ) : <EOL> def deco ( func ) : <EOL> def wrapper ( self , ** kw ) : <EOL> for name , default in params . iteritems ( ) : <EOL> if name in kw : <EOL> try : <EOL> value = bool ( int ( kw [ name ] ) ) <EOL> except ValueError , ve : <EOL> raise BadParameterError ( param = name , badvalue = kw [ name ] ) <EOL> elif default is None : <EOL> raise MissingParameterError ( name ) <EOL> else : <EOL> value = default <EOL> kw [ name ] = value <EOL> return func ( self , ** kw ) <EOL> return wrapper <EOL> return deco <EOL> def dictFields ( ** params ) : <EOL> def deco ( func ) : <EOL> def wrapper ( self , ** kw ) : <EOL> for key in kw . keys ( ) : <EOL> parts = key . split ( '<STR_LIT:.>' ) <EOL> if len ( parts ) > <NUM_LIT:1> and parts [ <NUM_LIT:0> ] in params : <EOL> d = kw <EOL> d . setdefault ( parts [ <NUM_LIT:0> ] , { } ) <EOL> while len ( parts ) > <NUM_LIT:1> : <EOL> d . setdefault ( parts [ <NUM_LIT:0> ] , { } ) <EOL> d = d [ parts [ <NUM_LIT:0> ] ] <EOL> parts = parts [ <NUM_LIT:1> : ] <EOL> value = kw [ key ] <EOL> d [ parts [ <NUM_LIT:0> ] ] = str ( value ) <EOL> del kw [ key ] <EOL> return func ( self , ** kw ) <EOL> return wrapper <EOL> return deco </s>
