def _ports_match(protocol, module_min, module_max, rule_min, rule_max):
 if (protocol == 'icmp'):
  if (module_min and (int(module_min) == (-1))):
   module_min = None
  if (module_max and (int(module_max) == (-1))):
   module_max = None
 if ((protocol in ['tcp', 'udp']) and (module_min is None) and (module_max is None)):
  if (rule_min and (int(rule_min) == 1) and rule_max and (int(rule_max) == 65535)):
   return True
 if module_min:
  module_min = int(module_min)
 if module_max:
  module_max = int(module_max)
 if rule_min:
  rule_min = int(rule_min)
 if rule_max:
  rule_max = int(rule_max)
 return ((module_min == rule_min) and (module_max == rule_max))

def _ports_match ( protocol , module_min , module_max , rule_min , rule_max ) : if ( protocol == 'icmp' ) : if ( module_min and ( int ( module_min ) == ( - 1 ) ) ) : module_min = None if ( module_max and ( int ( module_max ) == ( - 1 ) ) ) : module_max = None if ( ( protocol in [ 'tcp' , 'udp' ] ) and ( module_min is None ) and ( module_max is None ) ) : if ( rule_min and ( int ( rule_min ) == 1 ) and rule_max and ( int ( rule_max ) == 65535 ) ) : return True if module_min : module_min = int ( module_min ) if module_max : module_max = int ( module_max ) if rule_min : rule_min = int ( rule_min ) if rule_max : rule_max = int ( rule_max ) return ( ( module_min == rule_min ) and ( module_max == rule_max ) )
capture the complex port matching logic .