#NEWLINE# def _Group( self , group ) : #NEWLINE# #INDENT# "If 1 item return it, else return [ item1 item2 ].\n\n    Args:\n      group: a list.  could be a list of strings (protocols) or a list of\n             tuples (ports)\n\n    Returns:\n      rval: a string surrounded by '[' and '];' if len(group) > 1\n            or with just ';' appended if len(group) == 1\n    " #NEWLINE# def _FormattedGroup( el ) : #NEWLINE# #INDENT# "Return the actual formatting of an individual element.\n\n      Args:\n        el: either a string (protocol) or a tuple (ports)\n\n      Returns:\n        string: either the lower()'ed string or the ports, hyphenated\n                if they're a range, or by itself if it's not.\n      " #NEWLINE# if isinstance ( el , str ) : #NEWLINE# #INDENT# return el . lower ( ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( el , int ) : #NEWLINE# #INDENT# return str ( el ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( el [ 0 ] == el [ 1 ] ) : #NEWLINE# #INDENT# return ( '%d' % el [ 0 ] ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( '%d-%d' % ( el [ 0 ] , el [ 1 ] ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# if ( len ( rval ) > 1 ) : #NEWLINE# #INDENT# rval = ( ( '[ ' + ' ' . join ( [ _FormattedGroup ( x ) for x in group ] ) ) + ' ];' ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# rval = ( _FormattedGroup ( group [ 0 ] ) + ';' ) #NEWLINE# #UNINDENT# return rval