#NEWLINE# def gen_with_imports( self , custom_exceptions , ast ) : #NEWLINE# #INDENT# if isinstance ( ast , Node ) : #NEWLINE# #INDENT# if ( ast . type == 'block' ) : #NEWLINE# #INDENT# e = ast . block #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# e = [ ast ] #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( ast , list ) : #NEWLINE# #INDENT# e = ast #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# e = [ ast ] #NEWLINE# #UNINDENT# #UNINDENT# ( definitions , main ) = ( [ ] , [ ] ) #NEWLINE# for node in e : #NEWLINE# #INDENT# if node . type . endswith ( '_definition' ) : #NEWLINE# #INDENT# definitions . append ( node ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# main . append ( node ) #NEWLINE# #UNINDENT# #UNINDENT# result = generate ( Node ( 'module' , definitions = definitions , custom_exceptions = custom_exceptions , dependencies = [ ] , constants = [ ] , main = main ) , self . _language ) #NEWLINE# if hasattr ( self , 'gen_special' ) : #NEWLINE# #INDENT# return self . gen_special ( result ) #NEWLINE# #UNINDENT# ls = result . split ( '\n' ) #NEWLINE# l = 0 #NEWLINE# imports = [ ] #NEWLINE# while ls [ l ] . startswith ( self . _import ) : #NEWLINE# #INDENT# imports . append ( self . _parse_import ( ls [ l ] ) . strip ( ) ) #NEWLINE# l += 1 #NEWLINE# #UNINDENT# if ( not ls [ l ] . strip ( ) ) : #NEWLINE# #INDENT# l += 1 #NEWLINE# #UNINDENT# source = '\n' . join ( ls [ l : ] ) #NEWLINE# if ( not hasattr ( self , '_no_strip' ) ) : #NEWLINE# #INDENT# source = source . strip ( ) #NEWLINE# #UNINDENT# if hasattr ( self , '_ignore_import' ) : #NEWLINE# #INDENT# imports . remove ( self . _ignore_import ) #NEWLINE# #UNINDENT# return ( imports , source )