<s> class ParameterGroup ( dict ) : <EOL> def __init__ ( self , connection = None ) : <EOL> dict . __init__ ( self ) <EOL> self . connection = connection <EOL> self . name = None <EOL> self . description = None <EOL> self . engine = None <EOL> self . _current_param = None <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % self . name <EOL> def startElement ( self , name , attrs , connection ) : <EOL> if name == '<STR_LIT>' : <EOL> if self . _current_param : <EOL> self [ self . _current_param . name ] = self . _current_param <EOL> self . _current_param = Parameter ( self ) <EOL> return self . _current_param <EOL> def endElement ( self , name , value , connection ) : <EOL> if name == '<STR_LIT>' : <EOL> self . name = value <EOL> elif name == '<STR_LIT>' : <EOL> self . description = value <EOL> elif name == '<STR_LIT>' : <EOL> self . engine = value <EOL> else : <EOL> setattr ( self , name , value ) <EOL> def modifiable ( self ) : <EOL> mod = [ ] <EOL> for key in self : <EOL> p = self [ key ] <EOL> if p . is_modifiable : <EOL> mod . append ( p ) <EOL> return mod <EOL> def get_params ( self ) : <EOL> pg = self . connection . get_all_dbparameters ( self . name ) <EOL> self . update ( pg ) <EOL> def add_param ( self , name , value , apply_method ) : <EOL> param = Parameter ( ) <EOL> param . name = name <EOL> param . value = value <EOL> param . apply_method = apply_method <EOL> self . params . append ( param ) <EOL> class Parameter ( object ) : <EOL> """<STR_LIT>""" <EOL> ValidTypes = { '<STR_LIT>' : int , <EOL> '<STR_LIT:string>' : str , <EOL> '<STR_LIT>' : bool } <EOL> ValidSources = [ '<STR_LIT:user>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> ValidApplyTypes = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> ValidApplyMethods = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> def __init__ ( self , group = None , name = None ) : <EOL> self . group = group <EOL> self . name = name <EOL> self . _value = None <EOL> self . type = str <EOL> self . source = None <EOL> self . is_modifiable = True <EOL> self . description = None <EOL> self . apply_method = None <EOL> self . allowed_values = None <EOL> def __repr__ ( self ) : <EOL> return '<STR_LIT>' % self . name <EOL> def startElement ( self , name , attrs , connection ) : <EOL> pass <EOL> def endElement ( self , name , value , connection ) : <EOL> if name == '<STR_LIT>' : <EOL> self . name = value <EOL> elif name == '<STR_LIT>' : <EOL> self . _value = value <EOL> elif name == '<STR_LIT>' : <EOL> if value in self . ValidTypes : <EOL> self . type = value <EOL> elif name == '<STR_LIT>' : <EOL> if value in self . ValidSources : <EOL> self . source = value <EOL> elif name == '<STR_LIT>' : <EOL> if value . lower ( ) == '<STR_LIT:true>' : <EOL> self . is_modifiable = True <EOL> else : <EOL> self . is_modifiable = False <EOL> elif name == '<STR_LIT>' : <EOL> self . description = value <EOL> elif name == '<STR_LIT>' : <EOL> if value in self . ValidApplyTypes : <EOL> self . apply_type = value <EOL> elif name == '<STR_LIT>' : <EOL> self . allowed_values = value <EOL> else : <EOL> setattr ( self , name , value ) <EOL> def merge ( self , d , i ) : <EOL> prefix = '<STR_LIT>' % i <EOL> if self . name : <EOL> d [ prefix + '<STR_LIT>' ] = self . name <EOL> if self . _value is not None : <EOL> d [ prefix + '<STR_LIT>' ] = self . _value <EOL> if self . apply_type : <EOL> d [ prefix + '<STR_LIT>' ] = self . apply_method <EOL> def _set_string_value ( self , value ) : <EOL> if not isinstance ( value , str ) or isinstance ( value , unicode ) : <EOL> raise ValueError , '<STR_LIT>' <EOL> if self . allowed_values : <EOL> choices = self . allowed_values . split ( '<STR_LIT:U+002C>' ) <EOL> if value not in choices : <EOL> raise ValueError , '<STR_LIT>' % self . allowed_values <EOL> self . _value = value <EOL> def _set_integer_value ( self , value ) : <EOL> if isinstance ( value , str ) or isinstance ( value , unicode ) : <EOL> value = int ( value ) <EOL> if isinstance ( value , int ) or isinstance ( value , long ) : <EOL> if self . allowed_values : <EOL> min , max = self . allowed_values . split ( '<STR_LIT:->' ) <EOL> if value < int ( min ) or value > int ( max ) : <EOL> raise ValueError , '<STR_LIT>' % self . allowed_values <EOL> self . _value = value <EOL> else : <EOL> raise ValueError , '<STR_LIT>' <EOL> def _set_boolean_value ( self , value ) : <EOL> if isinstance ( value , bool ) : <EOL> self . _value = value <EOL> elif isinstance ( value , str ) or isinstance ( value , unicode ) : <EOL> if value . lower ( ) == '<STR_LIT:true>' : <EOL> self . _value = True <EOL> else : <EOL> self . _value = False <EOL> else : <EOL> raise ValueError , '<STR_LIT>' <EOL> def set_value ( self , value ) : <EOL> if self . type == '<STR_LIT:string>' : <EOL> self . _set_string_value ( value ) <EOL> elif self . type == '<STR_LIT>' : <EOL> self . _set_integer_value ( value ) <EOL> elif self . type == '<STR_LIT>' : <EOL> self . _set_boolean_value ( value ) <EOL> else : <EOL> raise TypeError , '<STR_LIT>' % self . type <EOL> def get_value ( self ) : <EOL> if self . _value == None : <EOL> return self . _value <EOL> if self . type == '<STR_LIT:string>' : <EOL> return self . _value <EOL> elif self . type == '<STR_LIT>' : <EOL> if not isinstance ( self . _value , int ) and not isinstance ( self . _value , long ) : <EOL> self . _set_integer_value ( self . _value ) <EOL> return self . _value <EOL> elif self . type == '<STR_LIT>' : <EOL> if not isinstance ( self . _value , bool ) : <EOL> self . _set_boolean_value ( self . _value ) <EOL> return self . _value <EOL> else : <EOL> raise TypeError , '<STR_LIT>' % self . type <EOL> value = property ( get_value , set_value , '<STR_LIT>' ) <EOL> def apply ( self , immediate = False ) : <EOL> if immediate : <EOL> self . apply_method = '<STR_LIT>' <EOL> else : <EOL> self . apply_method = '<STR_LIT>' <EOL> self . group . connection . modify_parameter_group ( self . group . name , [ self ] ) </s>
