#NEWLINE# def _getMicrodescriptorsFromCacheFile( fname = MICRO_DESC_CACHE_FILE ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# with open ( fname , 'r' ) as f : #NEWLINE# #INDENT# data = f . read ( ) #NEWLINE# #UNINDENT# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# msg = 'Failed to read microdescriptor cache file. Reason: {}.' . format ( e ) #NEWLINE# logging . debug ( msg ) #NEWLINE# return None #NEWLINE# #UNINDENT# micro_descs = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# cached_descs = [ ( 'onion-key' + m ) for m in REGEX . split ( data ) ] #NEWLINE# for m in desc : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# desc = microdescriptor . Microdescriptor ( m ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# micro_descs [ desc . digest ] = desc #NEWLINE# #UNINDENT# msg = 'Read {} cached microdescriptors.' . format ( len ( micro_descs ) ) #NEWLINE# logging . debug ( msg ) #NEWLINE# return ( micro_descs if ( len ( micro_descs ) > 0 ) else None )