#NEWLINE# def compress( hostnames ) : #NEWLINE# #INDENT# '\n    Compress a list of host into a more compact range representation\n    ' #NEWLINE# domain_dict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# result = [ ] #NEWLINE# for host in hostnames : #NEWLINE# #INDENT# if ( '.' in host ) : #NEWLINE# #INDENT# domain = '.' . join ( host . split ( '.' ) [ 1 : ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# domain = '' #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# domain_dict [ domain ] . append ( host ) #NEWLINE# #UNINDENT# except KeyError : #NEWLINE# #INDENT# domain_dict [ domain ] = [ host ] #NEWLINE# #UNINDENT# #UNINDENT# domains = list ( domain_dict . keys ( ) ) #NEWLINE# domains . sort ( ) #NEWLINE# for domain in domains : #NEWLINE# #INDENT# hosts = compress_domain ( domain_dict [ domain ] ) #NEWLINE# result += hosts #NEWLINE# #UNINDENT# return result