#NEWLINE# def text_fd_to_metric_families( fd ) : #NEWLINE# #INDENT# "Parse Prometheus text format from a file descriptor.\n\n    This is a laxer parser than the main Go parser,\n    so successful parsing does not imply that the parsed\n    text meets the specification.\n\n    Yields core.Metric's.\n    " #NEWLINE# name = '' #NEWLINE# documentation = '' #NEWLINE# typ = 'untyped' #NEWLINE# samples = [ ] #NEWLINE# allowed_names = [ ] #NEWLINE# def build_metric( name , documentation , typ , samples ) : #NEWLINE# #INDENT# metric = core . Metric ( name , documentation , typ ) #NEWLINE# metric . samples = samples #NEWLINE# return metric #NEWLINE# #UNINDENT# for line in fd : #NEWLINE# #INDENT# line = line . strip ( ) #NEWLINE# if line . startswith ( '#' ) : #NEWLINE# #INDENT# parts = line . split ( None , 3 ) #NEWLINE# if ( len ( parts ) < 2 ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( parts [ 1 ] == 'HELP' ) : #NEWLINE# #INDENT# if ( parts [ 2 ] != name ) : #NEWLINE# #INDENT# if ( name != '' ) : #NEWLINE# #INDENT# ( yield build_metric ( name , documentation , typ , samples ) ) #NEWLINE# #UNINDENT# name = parts [ 2 ] #NEWLINE# typ = 'untyped' #NEWLINE# samples = [ ] #NEWLINE# allowed_names = [ parts [ 2 ] ] #NEWLINE# #UNINDENT# if ( len ( parts ) == 4 ) : #NEWLINE# #INDENT# documentation = _unescape_help ( parts [ 3 ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# documentation = '' #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( parts [ 1 ] == 'TYPE' ) : #NEWLINE# #INDENT# if ( parts [ 2 ] != name ) : #NEWLINE# #INDENT# if ( name != '' ) : #NEWLINE# #INDENT# ( yield build_metric ( name , documentation , typ , samples ) ) #NEWLINE# #UNINDENT# name = parts [ 2 ] #NEWLINE# documentation = '' #NEWLINE# samples = [ ] #NEWLINE# #UNINDENT# typ = parts [ 3 ] #NEWLINE# allowed_names = { #NEWLINE# #INDENT# 'counter' : [ '' ] , #NEWLINE# 'gauge' : [ '' ] , #NEWLINE# 'summary' : [ '_count' , '_sum' , '' ] , #NEWLINE# 'histogram' : [ '_count' , '_sum' , '_bucket' ] , #NEWLINE# #UNINDENT# } . get ( typ , [ build_metric [ 2 ] ] ) #NEWLINE# allowed_names = [ ( name + n ) for n in allowed_names ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( line == '' ) : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# sample = _parse_sample ( line ) #NEWLINE# if ( sample [ 0 ] not in allowed_names ) : #NEWLINE# #INDENT# if ( name != '' ) : #NEWLINE# #INDENT# ( yield build_metric ( name , documentation , typ , samples ) ) #NEWLINE# #UNINDENT# name = '' #NEWLINE# documentation = '' #NEWLINE# typ = 'untyped' #NEWLINE# samples = [ ] #NEWLINE# allowed_names = [ ] #NEWLINE# ( yield build_metric ( sample [ 0 ] , documentation , typ , [ sample ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# samples . append ( sample ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( name != '' ) : #NEWLINE# #INDENT# ( yield build_metric ( name , documentation , typ , samples ) )