<s> """<STR_LIT>""" <EOL> import os , sys <EOL> from traits . api import Dict , HasTraits <EOL> class Namespace ( HasTraits ) : <EOL> """<STR_LIT>""" <EOL> locals = Dict <EOL> imports = Dict <EOL> _is_trait = Dict <EOL> def is_trait ( self , name ) : <EOL> """<STR_LIT>""" <EOL> return True <EOL> if name in self . locals : <EOL> if name in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] : <EOL> is_trait = True <EOL> elif not self . _is_trait . get ( name , False ) : <EOL> is_trait = False <EOL> else : <EOL> next = self . locals [ name ] <EOL> if len ( next . source ) > <NUM_LIT:0> : <EOL> is_trait = self . is_trait ( next . source ) <EOL> else : <EOL> is_trait = False <EOL> elif self . is_imported ( name ) : <EOL> module_name = self . get_next_module_name ( name ) <EOL> module = self . get_next_module ( module_name ) <EOL> if module is not None : <EOL> components = name . split ( '<STR_LIT:.>' ) <EOL> is_trait = module . is_trait ( components [ - <NUM_LIT:1> ] ) <EOL> else : <EOL> is_trait = False <EOL> elif self . namespace is not None : <EOL> is_trait = self . namespace . is_trait ( name ) <EOL> else : <EOL> is_trait = False <EOL> return is_trait <EOL> def is_imported ( self , name ) : <EOL> """<STR_LIT>""" <EOL> components = name . split ( '<STR_LIT:.>' ) <EOL> return components [ <NUM_LIT:0> ] in self . imports <EOL> def get_next_module_name ( self , symbol ) : <EOL> """<STR_LIT>""" <EOL> components = symbol . split ( '<STR_LIT:.>' ) <EOL> if len ( components ) == <NUM_LIT:1> : <EOL> module_name = self . imports [ symbol ] <EOL> else : <EOL> path = [ ] <EOL> value = self . imports [ components [ <NUM_LIT:0> ] ] <EOL> if len ( value ) > <NUM_LIT:0> : <EOL> path . append ( value ) <EOL> module_name = '<STR_LIT:.>' . join ( path ) <EOL> return module_name <EOL> path . append ( components [ <NUM_LIT:0> ] ) <EOL> for component in components [ <NUM_LIT:1> : - <NUM_LIT:1> ] : <EOL> path . append ( component ) <EOL> module_name = '<STR_LIT:.>' . join ( path ) <EOL> return module_name <EOL> def get_next_module ( self , module_name ) : <EOL> """<STR_LIT>""" <EOL> from . enclbr import find_module , read_file <EOL> dirname = os . path . dirname ( self . filename ) <EOL> filename = find_module ( module_name , [ dirname ] + sys . path ) <EOL> if filename is not None : <EOL> if os . path . isdir ( filename ) : <EOL> filename = os . path . join ( filename , '<STR_LIT>' ) <EOL> if filename . endswith ( '<STR_LIT>' ) or filename . endswith ( '<STR_LIT>' ) : <EOL> module = None <EOL> elif filename . startswith ( sys . prefix ) : <EOL> module = None <EOL> else : <EOL> module = read_file ( filename ) <EOL> else : <EOL> module = None <EOL> return module </s>
