parameters: (cli, rsvd)
return_statement: return creators
docstring: Return module instance creators and port instance creators.
  
      A creator is, in effect, a class as if defined by:
          class Foo(Module):
              bess = bess
              choose_arg = _choose_arg
      (and similarly for a port creator but with Port as the base class).
      The choose_arg function is internal, meant for use in the __init__
      functions in the base classes; see class Module and class Port,
      defined elsewhere.
  
      The rsvd argument is a dictionary of reserved names (see below).
docstring_summary: Return module instance creators and port instance creators.
docstring_tokens: Return module instance creators and port instance creators .
function: def _get_bess_module_and_port_creators(cli, rsvd):
      """
      Return module instance creators and port instance creators.
  
      A creator is, in effect, a class as if defined by:
          class Foo(Module):
              bess = bess
              choose_arg = _choose_arg
      (and similarly for a port creator but with Port as the base class).
      The choose_arg function is internal, meant for use in the __init__
      functions in the base classes; see class Module and class Port,
      defined elsewhere.
  
      The rsvd argument is a dictionary of reserved names (see below).
      """
      creators = {}
  
      # TODO(torek) cache these for performance, rebuild when needed
  
      class_names = [str(i) for i in cli.bess.list_mclasses().names]
      driver_names = [str(i) for i in cli.bess.list_drivers().driver_names]
  
      # Duplicates, if they exist, represent a fault in what's been
      # loaded into BESS.  In particular, at least for the moment,
      # we cannot have the same name as both a module *and* a port,
      # nor may they use any of the reserved names.
      #
      # We can assume that the C++ code has already forbidden
      # using the same name twice as-module class or port-driver.
      # But the C++ code does not have the restriction on using
      # Foo() as *both* module *and* port-driver.
      counts = collections.Counter(rsvd.keys())
      counts.update(class_names)
      counts.update(driver_names)
      dups = [k for k in counts if counts[k] > 1]
  
      if dups:
          errors = []
          for name in dups:
              if name in rsvd:
                  why = 'reserved name {} is used as '.format(name)
              else:
                  why = 'name {} is used as '.format(name)
              if name in class_names:
                  if name in driver_names:
                      why += 'both a module class and a port driver'
                  else:
                      why += 'a module class'
              else:
                  why += 'a port driver'
              errors.append(why)
          errors = 'duplicate names found: {}'.format('; '.join(errors))
          raise cli.InternalError(errors)
  
      for name in class_names:
          creators[name] = type(str(name), (Module,),
                                {'bess': cli.bess, 'choose_arg': _choose_arg})
      for name in driver_names:
          creators[name] = type(str(name), (Port,),
                                {'bess': cli.bess, 'choose_arg': _choose_arg})
  
      return creators
function_tokens: def _get_bess_module_and_port_creators ( cli , rsvd ) : creators = { } # TODO(torek) cache these for performance, rebuild when needed class_names = [ str ( i ) for i in cli . bess . list_mclasses ( ) . names ] driver_names = [ str ( i ) for i in cli . bess . list_drivers ( ) . driver_names ] # Duplicates, if they exist, represent a fault in what's been # loaded into BESS.  In particular, at least for the moment, # we cannot have the same name as both a module *and* a port, # nor may they use any of the reserved names. # # We can assume that the C++ code has already forbidden # using the same name twice as-module class or port-driver. # But the C++ code does not have the restriction on using # Foo() as *both* module *and* port-driver. counts = collections . Counter ( rsvd . keys ( ) ) counts . update ( class_names ) counts . update ( driver_names ) dups = [ k for k in counts if counts [ k ] > 1 ] if dups : errors = [ ] for name in dups : if name in rsvd : why = 'reserved name {} is used as ' . format ( name ) else : why = 'name {} is used as ' . format ( name ) if name in class_names : if name in driver_names : why += 'both a module class and a port driver' else : why += 'a module class' else : why += 'a port driver' errors . append ( why ) errors = 'duplicate names found: {}' . format ( '; ' . join ( errors ) ) raise cli . InternalError ( errors ) for name in class_names : creators [ name ] = type ( str ( name ) , ( Module , ) , { 'bess' : cli . bess , 'choose_arg' : _choose_arg } ) for name in driver_names : creators [ name ] = type ( str ( name ) , ( Port , ) , { 'bess' : cli . bess , 'choose_arg' : _choose_arg } ) return creators