<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from behave . _types import Unknown <EOL> def parse_bool ( text ) : <EOL> """<STR_LIT>""" <EOL> from distutils . util import strtobool <EOL> return bool ( strtobool ( text ) ) <EOL> def parse_user_define ( text ) : <EOL> """<STR_LIT>""" <EOL> text = text . strip ( ) <EOL> if "<STR_LIT:=>" in text : <EOL> text = unqote ( text ) <EOL> name , value = text . split ( "<STR_LIT:=>" , <NUM_LIT:1> ) <EOL> name = name . strip ( ) <EOL> value = unqote ( value . strip ( ) ) <EOL> else : <EOL> name = text <EOL> value = "<STR_LIT:true>" <EOL> return ( name , value ) <EOL> def unqote ( text ) : <EOL> """<STR_LIT>""" <EOL> if ( ( text . startswith ( '<STR_LIT:">' ) and text . endswith ( '<STR_LIT:">' ) ) or <EOL> ( text . startswith ( "<STR_LIT:'>" ) and text . endswith ( "<STR_LIT:'>" ) ) ) : <EOL> text = text [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> return text <EOL> class UserData ( dict ) : <EOL> """<STR_LIT>""" <EOL> def getas ( self , convert , name , default = None , valuetype = None ) : <EOL> """<STR_LIT>""" <EOL> if valuetype is None : <EOL> valuetype = convert <EOL> value = self . get ( name , Unknown ) <EOL> if value is Unknown : <EOL> return default <EOL> elif isinstance ( value , valuetype ) : <EOL> return value <EOL> else : <EOL> assert callable ( convert ) <EOL> return convert ( value ) <EOL> def getint ( self , name , default = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> return self . getas ( int , name , default ) <EOL> def getfloat ( self , name , default = <NUM_LIT:0.0> ) : <EOL> """<STR_LIT>""" <EOL> return self . getas ( float , name , default ) <EOL> def getbool ( self , name , default = False ) : <EOL> """<STR_LIT>""" <EOL> return self . getas ( parse_bool , name , default , valuetype = bool ) </s>
