(self, path)
Read the hosts file at the given location and parse the contents
Read the hosts file at the given location and parse the contents
Read the hosts file at the given location and parse the contents
def read(self, path):
        """Read the hosts file at the given location and parse the contents"""
        # regexp to match lines "host onion"
        # lines starting with comments are also ignored
        try:
            with open(path, 'r') as hosts_file:
                for line in hosts_file.read().split('\n'):
                    parts = re.split('\s+', line)
                    host = parts[0]
                    onion = parts[1]
                    dp = parts[2] if len(parts) == 3 else None
                    self.hosts[host] = {
                        'onion': onion,
                        'dp': dp
                    }
        except Exception:
            pass
def read ( self , path ) : # regexp to match lines "host onion" # lines starting with comments are also ignored try : with open ( path , 'r' ) as hosts_file : for line in hosts_file . read ( ) . split ( '\n' ) : parts = re . split ( '\s+' , line ) host = parts [ 0 ] onion = parts [ 1 ] dp = parts [ 2 ] if len ( parts ) == 3 else None self . hosts [ host ] = { 'onion' : onion , 'dp' : dp } except Exception : pass