def match_host(host, pattern):
 if (':' in host):
  (host, host_port) = host.rsplit(':', 1)
 else:
  host_port = None
 if (':' in pattern):
  (pattern, pattern_port) = pattern.rsplit(':', 1)
  if (pattern_port == '*'):
   pattern_port = None
 else:
  pattern_port = None
 if ((pattern_port is not None) and (host_port != pattern_port)):
  return False
 host = host.split('.')
 pattern = pattern.split('.')
 if (len(pattern) > len(host)):
  return False
 for (h, p) in zip(host, pattern):
  if ((h == p) or (p == '*')):
   continue
  else:
   return False
 return True

def match_host ( host , pattern ) : if ( ':' in host ) : ( host , host_port ) = host . rsplit ( ':' , 1 ) else : host_port = None if ( ':' in pattern ) : ( pattern , pattern_port ) = pattern . rsplit ( ':' , 1 ) if ( pattern_port == '*' ) : pattern_port = None else : pattern_port = None if ( ( pattern_port is not None ) and ( host_port != pattern_port ) ) : return False host = host . split ( '.' ) pattern = pattern . split ( '.' ) if ( len ( pattern ) > len ( host ) ) : return False for ( h , p ) in zip ( host , pattern ) : if ( ( h == p ) or ( p == '*' ) ) : continue else : return False return True
match host against pattern .