<s> from __future__ import absolute_import , division , print_function , unicode_literals <EOL> import os <EOL> import platform <EOL> import re <EOL> import shutil <EOL> import string <EOL> import subprocess <EOL> import sys <EOL> import tempfile <EOL> import time <EOL> import glob <EOL> import argparse <EOL> import socket <EOL> import json <EOL> try : <EOL> from urllib . parse import urlparse , urlencode <EOL> from urllib . request import urlopen , Request <EOL> from urllib . error import HTTPError <EOL> except ImportError : <EOL> from urlparse import urlparse <EOL> from urllib import urlencode <EOL> from urllib2 import urlopen , Request , HTTPError <EOL> Python3 = sys . version_info >= ( <NUM_LIT:3> , <NUM_LIT:0> ) <EOL> def getFileByUrl ( url ) : <EOL> try : <EOL> f = urlopen ( url ) <EOL> return f . read ( ) . decode ( "<STR_LIT>" ) <EOL> except : <EOL> print ( "<STR_LIT>" , url ) <EOL> def myInput ( msg = "<STR_LIT>" ) : <EOL> if Python3 : <EOL> return input ( msg ) <EOL> else : <EOL> return raw_input ( msg ) <EOL> def writeData ( f , data ) : <EOL> if Python3 : <EOL> f . write ( bytes ( data , "<STR_LIT>" ) ) <EOL> else : <EOL> f . write ( str ( data ) . encode ( "<STR_LIT>" ) ) <EOL> def listdir_nohidden ( path ) : <EOL> return glob . glob ( os . path . join ( path , "<STR_LIT:*>" ) ) <EOL> BASEDIR_PATH = os . path . dirname ( os . path . realpath ( __file__ ) ) <EOL> defaults = { <EOL> "<STR_LIT>" : <NUM_LIT:0> , <EOL> "<STR_LIT>" : os . path . join ( BASEDIR_PATH , "<STR_LIT:data>" ) , <EOL> "<STR_LIT>" : True , <EOL> "<STR_LIT:replace>" : False , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : False , <EOL> "<STR_LIT>" : os . path . join ( BASEDIR_PATH , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : os . path . join ( BASEDIR_PATH , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : { } , <EOL> "<STR_LIT>" : os . path . join ( BASEDIR_PATH , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : "<STR_LIT>" , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ ] , <EOL> "<STR_LIT>" : [ "<STR_LIT>" ] , <EOL> "<STR_LIT>" : os . path . join ( BASEDIR_PATH , "<STR_LIT>" ) } <EOL> def main ( ) : <EOL> parser = argparse . ArgumentParser ( description = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , default = False , action = "<STR_LIT:store_true>" , help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , default = False , action = "<STR_LIT:store_true>" , help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , default = [ ] , nargs = "<STR_LIT:*>" , help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , default = "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , default = False , action = "<STR_LIT:store_true>" , help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , default = False , action = "<STR_LIT:store_true>" , help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT>" , default = "<STR_LIT>" , help = "<STR_LIT>" ) <EOL> parser . add_argument ( "<STR_LIT>" , "<STR_LIT>" , dest = "<STR_LIT:replace>" , default = False , action = "<STR_LIT:store_true>" , help = "<STR_LIT>" ) <EOL> global settings <EOL> options = vars ( parser . parse_args ( ) ) <EOL> options [ "<STR_LIT>" ] = os . path . join ( BASEDIR_PATH , options [ "<STR_LIT>" ] ) <EOL> options [ "<STR_LIT>" ] = not options [ "<STR_LIT>" ] <EOL> settings = { } <EOL> settings . update ( defaults ) <EOL> settings . update ( options ) <EOL> settings [ "<STR_LIT>" ] = listdir_nohidden ( settings [ "<STR_LIT>" ] ) <EOL> settings [ "<STR_LIT>" ] = listdir_nohidden ( settings [ "<STR_LIT>" ] ) <EOL> settings [ "<STR_LIT>" ] = [ os . path . basename ( item ) for item in listdir_nohidden ( settings [ "<STR_LIT>" ] ) ] <EOL> settings [ "<STR_LIT>" ] = sorted ( list ( set ( options [ "<STR_LIT>" ] ) . intersection ( settings [ "<STR_LIT>" ] ) ) ) <EOL> with open ( settings [ "<STR_LIT>" ] , "<STR_LIT:r>" ) as f : <EOL> settings [ "<STR_LIT>" ] = json . load ( f ) <EOL> promptForUpdate ( ) <EOL> promptForExclusions ( ) <EOL> mergeFile = createInitialFile ( ) <EOL> removeOldHostsFile ( ) <EOL> finalFile = removeDupsAndExcl ( mergeFile ) <EOL> finalizeFile ( finalFile ) <EOL> updateReadmeData ( ) <EOL> printSuccess ( "<STR_LIT>" + settings [ "<STR_LIT>" ] + "<STR_LIT>" + <EOL> "<STR_LIT>" . format ( settings [ "<STR_LIT>" ] ) + "<STR_LIT>" ) <EOL> promptForMove ( finalFile ) <EOL> def promptForUpdate ( ) : <EOL> if not os . path . isfile ( os . path . join ( BASEDIR_PATH , "<STR_LIT>" ) ) : <EOL> try : <EOL> open ( os . path . join ( BASEDIR_PATH , "<STR_LIT>" ) , "<STR_LIT>" ) . close ( ) <EOL> except : <EOL> printFailure ( "<STR_LIT>" ) <EOL> if not settings [ "<STR_LIT>" ] : <EOL> return <EOL> response = "<STR_LIT:yes>" if settings [ "<STR_LIT>" ] else query_yes_no ( "<STR_LIT>" ) <EOL> if response == "<STR_LIT:yes>" : <EOL> updateAllSources ( ) <EOL> else : <EOL> if not settings [ "<STR_LIT>" ] : <EOL> print ( "<STR_LIT>" ) <EOL> def promptForExclusions ( ) : <EOL> response = "<STR_LIT>" if settings [ "<STR_LIT>" ] else query_yes_no ( "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> if response == "<STR_LIT:yes>" : <EOL> displayExclusionOptions ( ) <EOL> else : <EOL> if not settings [ "<STR_LIT>" ] : <EOL> print ( "<STR_LIT>" ) <EOL> def promptForMoreCustomExclusions ( question = "<STR_LIT>" ) : <EOL> return query_yes_no ( question ) == "<STR_LIT:yes>" <EOL> def promptForMove ( finalFile ) : <EOL> if settings [ "<STR_LIT:replace>" ] and not settings [ "<STR_LIT>" ] : <EOL> response = "<STR_LIT:yes>" <EOL> else : <EOL> response = "<STR_LIT>" if settings [ "<STR_LIT>" ] or settings [ "<STR_LIT>" ] else query_yes_no ( "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> if response == "<STR_LIT:yes>" : <EOL> moveHostsFileIntoPlace ( finalFile ) <EOL> else : <EOL> return False <EOL> def displayExclusionOptions ( ) : <EOL> for exclusionOption in settings [ "<STR_LIT>" ] : <EOL> response = query_yes_no ( "<STR_LIT>" + exclusionOption + "<STR_LIT>" ) <EOL> if response == "<STR_LIT:yes>" : <EOL> excludeDomain ( exclusionOption ) <EOL> else : <EOL> continue <EOL> response = query_yes_no ( "<STR_LIT>" ) <EOL> if response == "<STR_LIT:yes>" : <EOL> gatherCustomExclusions ( ) <EOL> def gatherCustomExclusions ( ) : <EOL> while True : <EOL> domainFromUser = myInput ( "<STR_LIT>" ) <EOL> if isValidDomainFormat ( domainFromUser ) : <EOL> excludeDomain ( domainFromUser ) <EOL> if not promptForMoreCustomExclusions ( ) : <EOL> return <EOL> def excludeDomain ( domain ) : <EOL> settings [ "<STR_LIT>" ] . append ( re . compile ( settings [ "<STR_LIT>" ] + domain ) ) <EOL> def matchesExclusions ( strippedRule ) : <EOL> strippedDomain = strippedRule . split ( ) [ <NUM_LIT:1> ] <EOL> for exclusionRegex in settings [ "<STR_LIT>" ] : <EOL> if exclusionRegex . search ( strippedDomain ) : <EOL> return True <EOL> return False <EOL> def updateAllSources ( ) : <EOL> allsources = list ( set ( settings [ "<STR_LIT>" ] ) | set ( settings [ "<STR_LIT>" ] ) ) <EOL> for source in allsources : <EOL> if os . path . isdir ( source ) : <EOL> for updateURL in getUpdateURLsFromFile ( source ) : <EOL> print ( "<STR_LIT>" + os . path . basename ( source ) + "<STR_LIT>" + updateURL ) <EOL> updatedFile = getFileByUrl ( updateURL ) <EOL> try : <EOL> updatedFile = updatedFile . replace ( "<STR_LIT:\r>" , "<STR_LIT>" ) <EOL> dataFile = open ( os . path . join ( settings [ "<STR_LIT>" ] , source , settings [ "<STR_LIT>" ] ) , "<STR_LIT:wb>" ) <EOL> writeData ( dataFile , updatedFile ) <EOL> dataFile . close ( ) <EOL> except : <EOL> print ( "<STR_LIT>" ) <EOL> def getUpdateURLsFromFile ( source ) : <EOL> pathToUpdateFile = os . path . join ( settings [ "<STR_LIT>" ] , source , settings [ "<STR_LIT>" ] ) <EOL> if os . path . exists ( pathToUpdateFile ) : <EOL> updateFile = open ( pathToUpdateFile , "<STR_LIT:r>" ) <EOL> retURLs = updateFile . readlines ( ) <EOL> updateFile . close ( ) <EOL> else : <EOL> retURL = None <EOL> printFailure ( "<STR_LIT>" + source + "<STR_LIT:\n>" + <EOL> "<STR_LIT>" + pathToUpdateFile ) <EOL> return retURLs <EOL> def getUpdateURLFromFile ( source ) : <EOL> pathToUpdateFile = os . path . join ( settings [ "<STR_LIT>" ] , source , settings [ "<STR_LIT>" ] ) <EOL> if os . path . exists ( pathToUpdateFile ) : <EOL> with open ( pathToUpdateFile , "<STR_LIT:r>" ) as updateFile : <EOL> return updateFile . readline ( ) . strip ( ) <EOL> printFailure ( "<STR_LIT>" + source + "<STR_LIT:\n>" + <EOL> "<STR_LIT>" + pathToUpdateFile ) <EOL> return None <EOL> def createInitialFile ( ) : <EOL> mergeFile = tempfile . NamedTemporaryFile ( ) <EOL> for source in settings [ "<STR_LIT>" ] : <EOL> filename = os . path . join ( settings [ "<STR_LIT>" ] , source , settings [ "<STR_LIT>" ] ) <EOL> with open ( filename , "<STR_LIT:r>" ) as curFile : <EOL> writeData ( mergeFile , curFile . read ( ) ) <EOL> for source in settings [ "<STR_LIT>" ] : <EOL> filename = os . path . join ( settings [ "<STR_LIT>" ] , source , settings [ "<STR_LIT>" ] ) <EOL> with open ( filename , "<STR_LIT:r>" ) as curFile : <EOL> writeData ( mergeFile , curFile . read ( ) ) <EOL> return mergeFile <EOL> def removeDupsAndExcl ( mergeFile ) : <EOL> numberOfRules = settings [ "<STR_LIT>" ] <EOL> if os . path . isfile ( settings [ "<STR_LIT>" ] ) : <EOL> with open ( settings [ "<STR_LIT>" ] , "<STR_LIT:r>" ) as ins : <EOL> for line in ins : <EOL> line = line . strip ( "<STR_LIT>" ) <EOL> if line and not line . startswith ( "<STR_LIT:#>" ) : <EOL> settings [ "<STR_LIT>" ] . append ( line ) <EOL> if not os . path . exists ( settings [ "<STR_LIT>" ] ) : <EOL> os . makedirs ( settings [ "<STR_LIT>" ] ) <EOL> finalFile = open ( os . path . join ( settings [ "<STR_LIT>" ] , "<STR_LIT>" ) , <EOL> "<STR_LIT>" if Python3 else "<STR_LIT>" ) <EOL> mergeFile . seek ( <NUM_LIT:0> ) <EOL> hostnames = set ( ) <EOL> hostnames . add ( "<STR_LIT:localhost>" ) <EOL> hostnames . add ( "<STR_LIT>" ) <EOL> hostnames . add ( "<STR_LIT>" ) <EOL> hostnames . add ( "<STR_LIT>" ) <EOL> exclusions = settings [ "<STR_LIT>" ] <EOL> for line in mergeFile . readlines ( ) : <EOL> write = "<STR_LIT:true>" <EOL> line = line . decode ( "<STR_LIT>" ) <EOL> line = line . replace ( "<STR_LIT>" , "<STR_LIT:U+0020>" ) <EOL> line = line . rstrip ( ) + "<STR_LIT:\n>" <EOL> if line [ <NUM_LIT:0> ] == "<STR_LIT:#>" or re . match ( r'<STR_LIT>' , line [ <NUM_LIT:0> ] ) : <EOL> writeData ( finalFile , line ) <EOL> continue <EOL> if "<STR_LIT>" in line : <EOL> continue <EOL> strippedRule = stripRule ( line ) <EOL> if not strippedRule or matchesExclusions ( strippedRule ) : <EOL> continue <EOL> hostname , normalizedRule = normalizeRule ( strippedRule ) <EOL> for exclude in exclusions : <EOL> if exclude in line : <EOL> write = "<STR_LIT:false>" <EOL> break <EOL> if normalizedRule and ( hostname not in hostnames ) and ( write == "<STR_LIT:true>" ) : <EOL> writeData ( finalFile , normalizedRule ) <EOL> hostnames . add ( hostname ) <EOL> numberOfRules += <NUM_LIT:1> <EOL> settings [ "<STR_LIT>" ] = numberOfRules <EOL> mergeFile . close ( ) <EOL> return finalFile <EOL> def normalizeRule ( rule ) : <EOL> result = re . search ( r'<STR_LIT>' , rule ) <EOL> if result : <EOL> hostname , suffix = result . group ( <NUM_LIT:2> , <NUM_LIT:3> ) <EOL> hostname = hostname . lower ( ) . strip ( ) <EOL> if suffix : <EOL> return hostname , "<STR_LIT>" % ( settings [ "<STR_LIT>" ] , hostname , suffix ) <EOL> else : <EOL> return hostname , "<STR_LIT>" % ( settings [ "<STR_LIT>" ] , hostname ) <EOL> print ( "<STR_LIT>" % rule ) <EOL> return None , None <EOL> def finalizeFile ( finalFile ) : <EOL> writeOpeningHeader ( finalFile ) <EOL> finalFile . close ( ) <EOL> def stripRule ( line ) : <EOL> splitLine = line . split ( ) <EOL> if len ( splitLine ) < <NUM_LIT:2> : <EOL> return "<STR_LIT>" <EOL> else : <EOL> return splitLine [ <NUM_LIT:0> ] + "<STR_LIT:U+0020>" + splitLine [ <NUM_LIT:1> ] <EOL> def writeOpeningHeader ( finalFile ) : <EOL> finalFile . seek ( <NUM_LIT:0> ) <EOL> fileContents = finalFile . read ( ) <EOL> finalFile . seek ( <NUM_LIT:0> ) <EOL> writeData ( finalFile , "<STR_LIT>" ) <EOL> writeData ( finalFile , "<STR_LIT>" ) <EOL> writeData ( finalFile , "<STR_LIT>" + time . strftime ( "<STR_LIT>" , time . gmtime ( ) ) + "<STR_LIT:\n>" ) <EOL> if settings [ "<STR_LIT>" ] : <EOL> writeData ( finalFile , "<STR_LIT>" + "<STR_LIT:U+002CU+0020>" . join ( settings [ "<STR_LIT>" ] ) + "<STR_LIT:\n>" ) <EOL> writeData ( finalFile , "<STR_LIT>" + "<STR_LIT>" . format ( settings [ "<STR_LIT>" ] ) ) <EOL> writeData ( finalFile , "<STR_LIT>" + os . path . join ( settings [ "<STR_LIT>" ] , "<STR_LIT>" ) + "<STR_LIT>" ) <EOL> writeData ( finalFile , "<STR_LIT>" ) <EOL> writeData ( finalFile , "<STR_LIT>" ) <EOL> writeData ( finalFile , "<STR_LIT:\n>" ) <EOL> if not settings [ "<STR_LIT>" ] : <EOL> writeData ( finalFile , "<STR_LIT>" ) <EOL> writeData ( finalFile , "<STR_LIT>" ) <EOL> writeData ( finalFile , "<STR_LIT>" ) <EOL> writeData ( finalFile , "<STR_LIT>" ) <EOL> writeData ( finalFile , "<STR_LIT>" ) <EOL> writeData ( finalFile , "<STR_LIT>" ) <EOL> if platform . system ( ) == "<STR_LIT>" : <EOL> writeData ( finalFile , "<STR_LIT>" + socket . gethostname ( ) + "<STR_LIT:\n>" ) <EOL> writeData ( finalFile , "<STR_LIT:\n>" ) <EOL> preamble = os . path . join ( BASEDIR_PATH , "<STR_LIT>" ) <EOL> if os . path . isfile ( preamble ) : <EOL> with open ( preamble , "<STR_LIT:r>" ) as f : <EOL> writeData ( finalFile , f . read ( ) ) <EOL> finalFile . write ( fileContents ) <EOL> def updateReadmeData ( ) : <EOL> extensionsKey = "<STR_LIT>" <EOL> hostsLocation = "<STR_LIT>" <EOL> if settings [ "<STR_LIT>" ] : <EOL> extensionsKey = "<STR_LIT:->" . join ( settings [ "<STR_LIT>" ] ) <EOL> generationData = { "<STR_LIT:location>" : os . path . join ( settings [ "<STR_LIT>" ] , "<STR_LIT>" ) , <EOL> "<STR_LIT>" : settings [ "<STR_LIT>" ] } <EOL> settings [ "<STR_LIT>" ] [ extensionsKey ] = generationData <EOL> with open ( settings [ "<STR_LIT>" ] , "<STR_LIT:w>" ) as f : <EOL> json . dump ( settings [ "<STR_LIT>" ] , f ) <EOL> def moveHostsFileIntoPlace ( finalFile ) : <EOL> if os . name == "<STR_LIT>" : <EOL> dnsCacheFound = False <EOL> print ( "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> if subprocess . call ( [ "<STR_LIT>" , "<STR_LIT>" , os . path . abspath ( finalFile . name ) , "<STR_LIT>" ] ) : <EOL> printFailure ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" ) <EOL> if platform . system ( ) == "<STR_LIT>" : <EOL> dnsCacheFound = True <EOL> if subprocess . call ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) : <EOL> printFailure ( "<STR_LIT>" ) <EOL> else : <EOL> if os . path . isfile ( "<STR_LIT>" ) : <EOL> dnsCacheFound = True <EOL> if subprocess . call ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) : <EOL> printFailure ( "<STR_LIT>" ) <EOL> else : <EOL> printSuccess ( "<STR_LIT>" ) <EOL> if os . path . isfile ( "<STR_LIT>" ) : <EOL> dnsCacheFound = True <EOL> if subprocess . call ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) : <EOL> printFailure ( "<STR_LIT>" ) <EOL> else : <EOL> printSuccess ( "<STR_LIT>" ) <EOL> if os . path . isfile ( "<STR_LIT>" ) : <EOL> dnsCacheFound = True <EOL> if subprocess . call ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) : <EOL> printFailure ( "<STR_LIT>" ) <EOL> else : <EOL> printSuccess ( "<STR_LIT>" ) <EOL> if os . path . isfile ( "<STR_LIT>" ) : <EOL> dnsCacheFound = True <EOL> if subprocess . call ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) : <EOL> printFailure ( "<STR_LIT>" ) <EOL> else : <EOL> printSuccess ( "<STR_LIT>" ) <EOL> if os . path . isfile ( "<STR_LIT>" ) : <EOL> dnsCacheFound = True <EOL> if subprocess . call ( [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] ) : <EOL> printFailure ( "<STR_LIT>" ) <EOL> else : <EOL> printSuccess ( "<STR_LIT>" ) <EOL> if not dnsCacheFound : <EOL> printFailure ( "<STR_LIT>" ) <EOL> elif os . name == "<STR_LIT>" : <EOL> print ( "<STR_LIT>" ) <EOL> print ( "<STR_LIT>" ) <EOL> def removeOldHostsFile ( ) : <EOL> oldFilePath = os . path . join ( BASEDIR_PATH , "<STR_LIT>" ) <EOL> open ( oldFilePath , "<STR_LIT:a>" ) . close ( ) <EOL> if settings [ "<STR_LIT>" ] : <EOL> backupFilePath = os . path . join ( BASEDIR_PATH , "<STR_LIT>" . format ( time . strftime ( "<STR_LIT>" ) ) ) <EOL> shutil . copy ( oldFilePath , backupFilePath ) <EOL> os . remove ( oldFilePath ) <EOL> open ( oldFilePath , "<STR_LIT:a>" ) . close ( ) <EOL> def query_yes_no ( question , default = "<STR_LIT:yes>" ) : <EOL> """<STR_LIT>""" <EOL> valid = { "<STR_LIT:yes>" : "<STR_LIT:yes>" , "<STR_LIT:y>" : "<STR_LIT:yes>" , "<STR_LIT>" : "<STR_LIT:yes>" , <EOL> "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT:n>" : "<STR_LIT>" } <EOL> if default is None : <EOL> prompt = "<STR_LIT>" <EOL> elif default == "<STR_LIT:yes>" : <EOL> prompt = "<STR_LIT>" <EOL> elif default == "<STR_LIT>" : <EOL> prompt = "<STR_LIT>" <EOL> else : <EOL> raise ValueError ( "<STR_LIT>" % default ) <EOL> while <NUM_LIT:1> : <EOL> sys . stdout . write ( colorize ( question , colors . PROMPT ) + prompt ) <EOL> choice = myInput ( ) . lower ( ) <EOL> if default is not None and choice == "<STR_LIT>" : <EOL> return default <EOL> elif choice in valid . keys ( ) : <EOL> return valid [ choice ] <EOL> else : <EOL> printFailure ( "<STR_LIT>" "<STR_LIT>" ) <EOL> def isValidDomainFormat ( domain ) : <EOL> if domain == "<STR_LIT>" : <EOL> print ( "<STR_LIT>" ) <EOL> return False <EOL> domainRegex = re . compile ( "<STR_LIT>" ) <EOL> if domainRegex . match ( domain ) : <EOL> print ( "<STR_LIT>" + domain + "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> return False <EOL> else : <EOL> return True <EOL> class colors : <EOL> PROMPT = "<STR_LIT>" <EOL> SUCCESS = "<STR_LIT>" <EOL> FAIL = "<STR_LIT>" <EOL> ENDC = "<STR_LIT>" <EOL> def colorize ( text , color ) : <EOL> return color + text + colors . ENDC <EOL> def printSuccess ( text ) : <EOL> print ( colorize ( text , colors . SUCCESS ) ) <EOL> def printFailure ( text ) : <EOL> print ( colorize ( text , colors . FAIL ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
