#NEWLINE# def register( self , plugin , name = None ) : #NEWLINE# #INDENT# ' Register a plugin and return its canonical name or None if the name\n        is blocked from registering.  Raise a ValueError if the plugin is already\n        registered. ' #NEWLINE# plugin_name = ( name or self . get_canonical_name ( plugin ) ) #NEWLINE# if ( ( plugin_name in self . _name2plugin ) or ( plugin in self . _plugin2hookcallers ) ) : #NEWLINE# #INDENT# if ( self . _name2plugin . get ( plugin_name , ( - 1 ) ) is None ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# raise ValueError ( ( 'Plugin already registered: %s=%s\n%s' % ( plugin_name , plugin , self . _name2plugin ) ) ) #NEWLINE# #UNINDENT# self . _name2plugin [ plugin_name ] = plugin #NEWLINE# self . _plugin2hookcallers [ plugin ] = hookcallers = [ ] #NEWLINE# for name in dir ( plugin ) : #NEWLINE# #INDENT# hookimpl_opts = self . parse_hookimpl_opts ( plugin , name ) #NEWLINE# if ( hookimpl_opts is not None ) : #NEWLINE# #INDENT# normalize_hookimpl_opts ( hookimpl_opts ) #NEWLINE# method = getattr ( plugin , name ) #NEWLINE# hookimpl = HookImpl ( plugin , plugin_name , method , hookimpl_opts ) #NEWLINE# hook = getattr ( self . hook , name , None ) #NEWLINE# if ( hook is None ) : #NEWLINE# #INDENT# hook = _HookCaller ( name , self . _hookexec ) #NEWLINE# setattr ( self . hook , name , hook ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if hook . has_spec ( ) : #NEWLINE# #INDENT# self . _verify_hook ( hook , hookimpl ) #NEWLINE# hook . _maybe_apply_history ( hookimpl ) #NEWLINE# #UNINDENT# #UNINDENT# hook . _add_hookimpl ( hookimpl ) #NEWLINE# hookcallers . append ( hook ) #NEWLINE# #UNINDENT# #UNINDENT# return plugin_name