def create_blocklist(directory, blocked_hosts=BLOCKLIST_HOSTS, name='hosts', line_format='one_per_line'):
 blocklist_file = (directory / name)
 with open(str(blocklist_file), 'w', encoding='UTF-8') as blocklist:
  blocklist.write('# Blocked Hosts List #\n\n')
  if (line_format == 'etc_hosts'):
   for host in blocked_hosts:
    blocklist.write((('127.0.0.1  ' + host) + '\n'))
  elif (line_format == 'one_per_line'):
   for host in blocked_hosts:
    blocklist.write((host + '\n'))
  elif (line_format == 'not_correct'):
   for host in blocked_hosts:
    blocklist.write((host + ' This is not a correct hosts file\n'))
  else:
   raise ValueError('Incorrect line_format argument')
 return str(blocklist_file)

def create_blocklist ( directory , blocked_hosts = BLOCKLIST_HOSTS , name = 'hosts' , line_format = 'one_per_line' ) : blocklist_file = ( directory / name ) with open ( str ( blocklist_file ) , 'w' , encoding = 'UTF-8' ) as blocklist : blocklist . write ( '# Blocked Hosts List #\n\n' ) if ( line_format == 'etc_hosts' ) : for host in blocked_hosts : blocklist . write ( ( ( '127.0.0.1  ' + host ) + '\n' ) ) elif ( line_format == 'one_per_line' ) : for host in blocked_hosts : blocklist . write ( ( host + '\n' ) ) elif ( line_format == 'not_correct' ) : for host in blocked_hosts : blocklist . write ( ( host + ' This is not a correct hosts file\n' ) ) else : raise ValueError ( 'Incorrect line_format argument' ) return str ( blocklist_file )
return a path to a blocklist file .