def parse_fp(source, module_name, lexer=None, parser=None, enable_cache=True):
 if (not module_name.endswith('_thrift')):
  raise ThriftParserError("ThriftPy can only generate module with '_thrift' suffix")
 if (enable_cache and (module_name in thrift_cache)):
  return thrift_cache[module_name]
 if (not hasattr(source, 'read')):
  raise ThriftParserError("Except `source` to be a file-like object witha method named 'read'")
 if (lexer is None):
  lexer = lex.lex()
 if (parser is None):
  parser = yacc.yacc(debug=False, write_tables=0)
 data = source.read()
 thrift = types.ModuleType(module_name)
 setattr(thrift, '__thrift_file__', None)
 thrift_stack.append(thrift)
 lexer.lineno = 1
 parser.parse(data)
 thrift_stack.pop()
 if enable_cache:
  thrift_cache[module_name] = thrift
 return thrift

def parse_fp ( source , module_name , lexer = None , parser = None , enable_cache = True ) : if ( not module_name . endswith ( '_thrift' ) ) : raise ThriftParserError ( "ThriftPy can only generate module with '_thrift' suffix" ) if ( enable_cache and ( module_name in thrift_cache ) ) : return thrift_cache [ module_name ] if ( not hasattr ( source , 'read' ) ) : raise ThriftParserError ( "Except `source` to be a file-like object witha method named 'read'" ) if ( lexer is None ) : lexer = lex . lex ( ) if ( parser is None ) : parser = yacc . yacc ( debug = False , write_tables = 0 ) data = source . read ( ) thrift = types . ModuleType ( module_name ) setattr ( thrift , '__thrift_file__' , None ) thrift_stack . append ( thrift ) lexer . lineno = 1 parser . parse ( data ) thrift_stack . pop ( ) if enable_cache : thrift_cache [ module_name ] = thrift return thrift
parse a file-like object to thrift module object .