<s> import errno <EOL> import numbers <EOL> from . import constants as _c , FSQEnvError <EOL> from . internal import coerce_unicode <EOL> def const ( const ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> return getattr ( _c , const ) <EOL> except AttributeError : <EOL> raise FSQEnvError ( errno . EINVAL , u'<STR_LIT>' u'<STR_LIT>' . format ( const ) ) <EOL> except TypeError : <EOL> raise TypeError ( errno . EINVAL , u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' . format ( const . __class__ . __name__ ) ) <EOL> def set_const ( const , val ) : <EOL> '''<STR_LIT>''' <EOL> try : <EOL> cur = getattr ( _c , const ) <EOL> except AttributeError : <EOL> raise FSQEnvError ( errno . ENOENT , u'<STR_LIT>' u'<STR_LIT>' . format ( const ) ) <EOL> except TypeError : <EOL> raise TypeError ( errno . EINVAL , u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' . format ( const . __class__ . __name__ ) ) <EOL> should_be = cur . __class__ <EOL> try : <EOL> if not isinstance ( val , should_be ) : <EOL> if should_be is unicode or cur is None : <EOL> val = coerce_unicode ( val , _c . FSQ_CHARSET ) <EOL> elif should_be is int and const . endswith ( '<STR_LIT>' ) : <EOL> val = int ( val , <NUM_LIT:8> ) <EOL> elif isinstance ( cur , numbers . Integral ) : <EOL> val = int ( val ) <EOL> else : <EOL> should_be ( val ) <EOL> except ( TypeError , ValueError , ) : <EOL> raise FSQEnvError ( errno . EINVAL , u'<STR_LIT>' u'<STR_LIT>' u'<STR_LIT>' . format ( const , should_be . __name__ , <EOL> val . __class__ . __name__ ) ) <EOL> setattr ( _c , const , val ) <EOL> return val </s>
