#NEWLINE# def _todict( self ) : #NEWLINE# #INDENT# ' Get a dict representing this AST. This is the basis for\n        creating JSON, but can be used to compare AST trees as well.\n        ' #NEWLINE# d = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# d [ '_type' ] = self . __class__ . __name__ #NEWLINE# for name in self . __slots__ : #NEWLINE# #INDENT# val = getattr ( self , name ) #NEWLINE# if ( val is None ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if name . endswith ( '_node' ) : #NEWLINE# #INDENT# val = val . _todict ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if name . endswith ( '_nodes' ) : #NEWLINE# #INDENT# val = [ x . _todict ( ) for x in x ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( isinstance ( self , Bytes ) and isinstance ( val , bytes ) ) : #NEWLINE# #INDENT# val = ( 'BYTES:' + encodebytes ( val ) . decode ( 'utf-8' ) . rstrip ( ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( isinstance ( self , Num ) and isinstance ( val , complex ) ) : #NEWLINE# #INDENT# val = ( 'COMPLEX:' + repr ( val ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# d [ name ] = val #NEWLINE# #UNINDENT# return d