<s> """<STR_LIT>""" <EOL> from sys import maxint , float_info <EOL> from traits . api import HasTraits , MetaHasTraits , Any , Python , Instance <EOL> from traits . trait_types import _InstanceArgs <EOL> from inspect import getmro , ismodule , getmembers , isfunction , isclass <EOL> from openmdao . main . datatypes . api import Slot , Event <EOL> excludes = ( Any , Python , Event , type ) <EOL> def _print_funct ( funct , args , kw ) : <EOL> arglst = [ ] <EOL> if args : <EOL> for arg in args : <EOL> if isinstance ( arg , basestring ) : <EOL> arglst . append ( "<STR_LIT>" % arg ) <EOL> else : <EOL> arglst . append ( "<STR_LIT:%s>" % arg ) <EOL> argstr = '<STR_LIT:U+002CU+0020>' . join ( arglst ) <EOL> kwlst = [ ] <EOL> if kw : <EOL> for k , v in kw . items ( ) : <EOL> if isinstance ( v , basestring ) : <EOL> kwlst . append ( "<STR_LIT>" % ( k , v ) ) <EOL> else : <EOL> kwlst . append ( "<STR_LIT>" % ( k , v ) ) <EOL> kwstr = '<STR_LIT:U+002CU+0020>' . join ( kwlst ) <EOL> if kwstr and len ( argstr ) > <NUM_LIT:0> : <EOL> kwstr = '<STR_LIT:U+002CU+0020>' + kwstr <EOL> return "<STR_LIT>" % ( funct . __name__ , argstr , kwstr ) <EOL> def _get_instance_default ( trait ) : <EOL> if trait . factory : <EOL> return _print_funct ( trait . factory , trait . args , trait . kw ) <EOL> elif isinstance ( trait . default_value , _InstanceArgs ) : <EOL> return _print_funct ( trait . default_value . args [ <NUM_LIT:0> ] , <EOL> trait . default_value . args [ <NUM_LIT:1> : ] , <EOL> trait . default_value . kw ) <EOL> return trait . default_value <EOL> def get_traits_info ( app , what , name , obj , options , lines ) : <EOL> """<STR_LIT>""" <EOL> if name . endswith ( "<STR_LIT>" ) and ismodule ( obj ) : <EOL> fns = getmembers ( obj , isfunction ) <EOL> for n , v in fns : <EOL> filename = v . __module__ + "<STR_LIT>" <EOL> lines . append ( "<STR_LIT>" % ( n , filename ) ) <EOL> lines . append ( '<STR_LIT:\n>' ) <EOL> cls = getmembers ( obj , isclass ) <EOL> for n1 , v1 in cls : <EOL> module = v1 . __module__ <EOL> if module == "<STR_LIT>" : <EOL> filename2 = "<STR_LIT>" <EOL> lines . append ( "<STR_LIT>" % ( n1 , filename2 ) ) <EOL> else : <EOL> filename2 = module + "<STR_LIT>" <EOL> lines . append ( "<STR_LIT>" % ( n1 , filename2 ) ) <EOL> lines . append ( '<STR_LIT:\n>' ) <EOL> if not isinstance ( obj , ( MetaHasTraits , HasTraits ) ) : <EOL> return <EOL> classes = getmro ( obj ) <EOL> this_class_traits = obj . class_traits ( ) <EOL> base_class_traits = { } <EOL> for cls in classes [ <NUM_LIT:1> : ] : <EOL> if hasattr ( cls , '<STR_LIT>' ) : <EOL> base_class_traits . update ( cls . class_traits ( ) ) <EOL> keepers = { } <EOL> for trt , trt_val in this_class_traits . items ( ) : <EOL> if not base_class_traits . has_key ( trt ) : <EOL> keepers [ trt ] = trt_val <EOL> else : <EOL> if not trt_val == base_class_traits [ trt ] : <EOL> keepers [ trt ] = trt_val <EOL> keepers_in = { } <EOL> keepers_out = { } <EOL> keepers_instance = { } <EOL> keepers_undefined = { } <EOL> for t , val in keepers . items ( ) : <EOL> if not isinstance ( val . trait_type , excludes ) : <EOL> if val . trait_type . _metadata . has_key ( "<STR_LIT>" ) : <EOL> if val . trait_type . _metadata [ "<STR_LIT>" ] == "<STR_LIT>" : <EOL> keepers_in [ t ] = val <EOL> elif val . trait_type . _metadata [ "<STR_LIT>" ] == "<STR_LIT>" : <EOL> keepers_out [ t ] = val <EOL> elif type ( val . trait_type ) . __name__ in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> keepers_instance [ t ] = val <EOL> else : <EOL> keepers_undefined [ t ] = val <EOL> dicts = ( keepers_instance , keepers_in , keepers_out , keepers_undefined ) <EOL> dontdo_meta = set ( [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:type>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> for dic in dicts : <EOL> sortedDict = _sortedDictVals ( dic ) <EOL> for t , val in sortedDict : <EOL> lines . append ( '<STR_LIT>' ) <EOL> if val . is_trait_type ( Instance ) or val . is_trait_type ( Slot ) : <EOL> lines . extend ( [ "<STR_LIT>" <EOL> % ( type ( val . trait_type ) . __name__ , <EOL> val . trait_type . klass . __name__ , t ) ] ) <EOL> else : <EOL> lines . extend ( [ "<STR_LIT>" % ( type ( val . trait_type ) . __name__ , t ) ] ) <EOL> if val . desc is not None : <EOL> lines . extend ( [ "<STR_LIT>" % val . desc ] ) <EOL> lines . append ( '<STR_LIT>' ) <EOL> if val . is_trait_type ( Instance ) or val . is_trait_type ( Slot ) : <EOL> lines . extend ( [ "<STR_LIT>" <EOL> % _get_instance_default ( val . trait_type ) ] ) <EOL> else : <EOL> lines . extend ( [ "<STR_LIT>" <EOL> % ( val . trait_type ) . default_value ] ) <EOL> if val . iotype is not None : <EOL> lines . extend ( [ "<STR_LIT>" % val . iotype ] ) <EOL> if val . units is not None : <EOL> lines . extend ( [ "<STR_LIT>" % val . units ] ) <EOL> if val . low is not None : <EOL> if val . low == ( - <NUM_LIT:1> * maxint ) : <EOL> continue <EOL> elif val . low == ( - float_info . max ) : <EOL> continue <EOL> else : <EOL> lines . extend ( [ '<STR_LIT>' % val . low ] ) <EOL> if val . high is not None : <EOL> if val . high is maxint : <EOL> continue <EOL> elif val . high is float_info . max : <EOL> continue <EOL> else : <EOL> lines . extend ( [ '<STR_LIT>' % val . high ] ) <EOL> metadata = val . trait_type . _metadata . items ( ) <EOL> for m , v in metadata : <EOL> if m not in dontdo_meta : <EOL> if isinstance ( v , basestring ) : <EOL> v = "<STR_LIT>" % v <EOL> lines . extend ( [ '<STR_LIT>' % ( m , v ) ] ) <EOL> lines . append ( '<STR_LIT>' ) <EOL> def setup ( app ) : <EOL> """<STR_LIT>""" <EOL> app . connect ( '<STR_LIT>' , get_traits_info ) <EOL> def _sortedDictVals ( unsorted_dict ) : <EOL> """<STR_LIT>""" <EOL> items = unsorted_dict . items ( ) <EOL> items . sort ( ) <EOL> return items <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> from openmdao . lib . components . api import ExternalCode <EOL> lines = [ ] <EOL> get_traits_info ( None , '<STR_LIT:class>' , '<STR_LIT:foo>' , ExternalCode , None , lines ) <EOL> for line in lines : <EOL> print line </s>
