#NEWLINE# def read_resolv_conf( self , f ) : #NEWLINE# #INDENT# 'Process f as a file in the /etc/resolv.conf format.  If f is\n        a string, it is used as the name of the file to open; otherwise it\n        is treated as the file itself.' #NEWLINE# if ( isinstance ( f , str ) or isinstance ( f , unicode ) ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# f = open ( f , 'r' ) #NEWLINE# #UNINDENT# except IOError : #NEWLINE# #INDENT# self . nameservers = [ '127.0.0.1' ] #NEWLINE# return #NEWLINE# #UNINDENT# want_close = True #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# want_close = False #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# for l in f : #NEWLINE# #INDENT# if ( ( len ( l ) == 0 ) or ( l [ 0 ] == '#' ) or ( l [ 0 ] == ';' ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# tokens = l . split ( ) #NEWLINE# if ( len ( tokens ) == 0 ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# if ( tokens [ 0 ] == 'nameserver' ) : #NEWLINE# #INDENT# self . nameservers . append ( tokens [ 1 ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( tokens [ 0 ] == 'domain' ) : #NEWLINE# #INDENT# self . domain = dns . name . from_text ( l [ 1 ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( tokens [ 0 ] == 'search' ) : #NEWLINE# #INDENT# for suffix in tokens [ 1 : ] : #NEWLINE# #INDENT# self . search . append ( dns . name . from_text ( suffix ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# finally : #NEWLINE# #INDENT# if want_close : #NEWLINE# #INDENT# f . close ( ) #NEWLINE# #UNINDENT# #UNINDENT# if ( len ( self . nameservers ) == 0 ) : #NEWLINE# #INDENT# self . nameservers . append ( '127.0.0.1' )