code: def register(name, fn=None):
      
      def _hook_add(func):
          if name not in _hooks:
              logger.debug("Creating new hook %s" % name)
              _hooks[name] = []
  
          logger.debug('Registering hook %s for function %s' % (name, fn))
          _hooks[name].append(func)
  
      if fn is None:
          # Behave like a decorator
          def decorator(func):
              _hook_add(func)
              return func
          return decorator
      else:
          # Behave like a function, just register hook
          _hook_add(fn)
docs: Decorator to register a function as a hook
  
      Register hook for ``hook_name``. Can be used as a decorator::
          @register('hook_name')
          def my_hook(...):
              pass
  
      or as a function call::
          def my_hook(...):
              pass
          register('hook_name', my_hook)
  
      :param name: str Name of the hook/callback to register it as
      :param fn: function to register in the hook/callback
      :return: function Decorator if applied as a decorator