def port_usage(port):
 global PORT_USES
 if (PORT_USES is None):
  config = conf.Config()
  config_path = os.path.join(os.path.dirname(__file__), 'ports.cfg')
  try:
   config.load(config_path)
   port_uses = {}
   for (key, value) in config.get('port', {}).items():
    if key.isdigit():
     port_uses[int(key)] = value
    elif ('-' in key):
     (min_port, max_port) = key.split('-', 1)
     for port_entry in range(int(min_port), (int(max_port) + 1)):
      port_uses[port_entry] = value
    else:
     raise ValueError(("'%s' is an invalid key" % key))
   PORT_USES = port_uses
  except Exception as exc:
   log.warn(("BUG: stem failed to load its internal port descriptions from '%s': %s" % (config_path, exc)))
 if (not PORT_USES):
  return None
 if (isinstance(port, str) and port.isdigit()):
  port = int(port)
 return PORT_USES.get(port)

def port_usage ( port ) : global PORT_USES if ( PORT_USES is None ) : config = conf . Config ( ) config_path = os . path . join ( os . path . dirname ( __file__ ) , 'ports.cfg' ) try : config . load ( config_path ) port_uses = { } for ( key , value ) in config . get ( 'port' , { } ) . items ( ) : if key . isdigit ( ) : port_uses [ int ( key ) ] = value elif ( '-' in key ) : ( min_port , max_port ) = key . split ( '-' , 1 ) for port_entry in range ( int ( min_port ) , ( int ( max_port ) + 1 ) ) : port_uses [ port_entry ] = value else : raise ValueError ( ( "'%s' is an invalid key" % key ) ) PORT_USES = port_uses except Exception as exc : log . warn ( ( "BUG: stem failed to load its internal port descriptions from '%s': %s" % ( config_path , exc ) ) ) if ( not PORT_USES ) : return None if ( isinstance ( port , str ) and port . isdigit ( ) ) : port = int ( port ) return PORT_USES . get ( port )
provides the common use of a given port .