Get a handler (if present) from a namespace.

        Returns
        -------
        function or None
            The handler defined in the namespace.
197746
def _get_handler(self, namespace, remove_handler=False):
        
        if hasattr(namespace, '_func'):
            _func = namespace._func
            if remove_handler:
                del namespace._func
            return _func
225031
def handle(event):
        
        def dec(func):
            if not hasattr(func, '_handle_events'):
                func._handle_events = set()
            func._handle_events.add(event)
            return func

        return dec
12434
def get_response_handler(self):
        
        assert self.response_handler is not None, \
            'Please define a response_handler ' \
            ' for Endpoint: %s' % self.__class__.__name__

        return self.response_handler(self, **self.get_response_handler_params())
66643
def _get_op_handler(operation):
        
        try:
            mod_to_import, attr_path = operation.split('#')
            op = import_module(mod_to_import)
            for part in attr_path.split('.'):
                op = getattr(op, part)
            if isinstance(op, types.FunctionType):
                return op
            return six.get_method_function(op)
        except (ValueError, AttributeError):
            raise ValueError("The operation '{}' is invalid.".format(operation))
42190
def get_logger(name=None):
    
    logging.setLoggerClass(CustomLogger)

    logger = logging.getLogger(name)
    logger.setLevel(logging.DEBUG)

    logger.addHandler(_get_info_handler())
    logger.addHandler(_get_out_handler())
    logger.addHandler(_get_warn_handler())
    logger.addHandler(_get_error_handler())
    logger.addHandler(_get_critical_handler())
    logger.addHandler(_get_success_handler())
    logger.propagate = False

    return logger
51528
def get_handler(self, *args, **options):
        
        handler = super(Command, self).get_handler(*args, **options)
        insecure_serving = options.get('insecure_serving', False)
        if self.should_use_static_handler(options):
            return StaticFilesHandler(handler)
        return handler
550904
def _get_class_handlers(cls, signal_name, instance):
        
        handlers = cls._signal_handlers_sorted[signal_name]
        return [getattr(instance, hname) for hname in handlers]
1273601
def _get_handler(self, handler_class):
        """"""
        element = None
        for handler in self.handlers:
            if isinstance(handler, handler_class):
                element = handler
                break
        return element
572164
def register_namespace(self, namespace_handler):
        
        if not isinstance(namespace_handler, namespace.ClientNamespace):
            raise ValueError('Not a namespace instance')
        if self.is_asyncio_based() != namespace_handler.is_asyncio_based():
            raise ValueError('Not a valid namespace class for this client')
        namespace_handler._set_client(self)
        self.namespace_handlers[namespace_handler.namespace] = \
            namespace_handler
664974
function getHandler (method, trans, version) {
  return function (req, res, next) {
    res.setHeader('Allow', Object.values(allowedMethods).join(','));

    let service = req.params.__service;
    let id = req.params.__id;
    let action = req.params.__action;
    let path = '/' + service +
      (id? '/' + id : '') +
      (action? '/' + action : '');
    
    // guess whether id is an action?
    if (id && !action) {
      if (!(validator.isNumeric(id) || validator.isMongoId(id))) {
        action = id;
      }
    }
    service += (action? '.' + action : '');
    
    debug(`REST handler calling service \'${service}\'`);
    debug(` => cmd  \'${method}\'`);
    debug(` => path \'${path}\'`);
    debug(` => version \'${version}\'`);

    // The service success callback which sets res.data or calls next() with the error
    const callback = function (err, data) {
      debug(' => service response:', err, data);
      if (err) return next(err.cause || err);

      res.data = data;

      if (!data) {
        debug(`No content returned for '${req.url}'`);
        res.status(statusCodes.noContent);
      } else if (method === 'post') {
        res.status(statusCodes.created);
      }

      return next();
    };

    trans.act({
      topic: `poplar.${service}`,
      cmd: method,
      path: path,
      version: version,
      headers: req.headers || {},
      query: req.query || {},
      body: req.body || {}
    }, callback);
  };
}
105096
def method_or_name(namespace, x):
    '''
    
    '''
    if not isinstance(x, str):
        return x

    if hasattr(namespace, x):
        return getattr(namespace, x)

    attrs = [y for y in dir(namespace) if not y.startswith('_')]
    msg = '''"%s" is not available in %s.
These attributes are available: %s.''' % (x, namespace.__name__, attrs)
    raise AttributeError(msg)
487761
def get_handler(self, options):
        """"""
        # Import the CurrencyHandler and get an instance
        handler_module = import_module(sources[options[self._source_param]], self._package_name)
        return handler_module.CurrencyHandler(self.log)
120225
def getNamespace(self, prefix):
        
        namespace = None
        if prefix == 'xmlns':
            namespace = DOM.findDefaultNS(prefix, self.__node)
        else:
            try:
                namespace = DOM.findNamespaceURI(prefix, self.__node)
            except DOMException, ex:
                if prefix != 'xml':
                    raise SchemaError, '%s namespace not declared for %s'\
                        %(prefix, self.__node._get_tagName())
                namespace = XMLNS.XML
        return namespace
1191598
async def _trigger_event(self, event, namespace, *args):
        """"""
        # first see if we have an explicit handler for the event
        if namespace in self.handlers and event in self.handlers[namespace]:
            if asyncio.iscoroutinefunction(self.handlers[namespace][event]) \
                    is True:
                try:
                    ret = await self.handlers[namespace][event](*args)
                except asyncio.CancelledError:  # pragma: no cover
                    ret = None
            else:
                ret = self.handlers[namespace][event](*args)
            return ret

        # or else, forward the event to a namepsace handler if one exists
        elif namespace in self.namespace_handlers:
            return await self.namespace_handlers[namespace].trigger_event(
                event, *args)
384082
def get_logger(name):
    
    logger = logging.getLogger(name)
    logger.addHandler(logging.NullHandler())
    return logger
1142452
def __get_function_or_ex_function(self, func_name):
        
        # try function name as given
        try:
            return getattr(self.driver, func_name)
        except AttributeError:
            pass
        # try prefixing name with `ex_`
        try:
            return getattr(self.driver, 'ex_' + func_name)
        except AttributeError:
            pass
        # no such function
        raise AttributeError(
            "No function named `{0}` or `{1}` in class `{2}`"
            .format(func_name, 'ex_'+func_name, self.__class__.__name__))
1022734
def bind(cls, origin, handler, *, name=None):
        
        name = cls.__name__ if name is None else name
        attrs = {
            "_origin": origin, "_handler": handler,
            "__module__": "origin",  # Could do better?
        }
        return type(name, (cls,), attrs)