def format_allowed_section(allowed):
 if (allowed.count(':') == 0):
  protocol = allowed
  ports = []
 elif (allowed.count(':') == 1):
  (protocol, ports) = allowed.split(':')
 else:
  return []
 if ports.count(','):
  ports = ports.split(',')
 else:
  ports = [ports]
 return_val = {'IPProtocol': protocol}
 if ports:
  return_val['ports'] = ports
 return return_val

def format_allowed_section ( allowed ) : if ( allowed . count ( ':' ) == 0 ) : protocol = allowed ports = [ ] elif ( allowed . count ( ':' ) == 1 ) : ( protocol , ports ) = allowed . split ( ':' ) else : return [ ] if ports . count ( ',' ) : ports = ports . split ( ',' ) else : ports = [ ports ] return_val = { 'IPProtocol' : protocol } if ports : return_val [ 'ports' ] = ports return return_val
format each section of the allowed list .