'Configure a handler from a dictionary.'

def configure_handler(self, config):

    formatter = config.pop('formatter', None)
    if formatter:
        try:
            formatter = self.config['formatters'][formatter]
        except StandardError as e:
            raise ValueError(('Unable    to    set    formatter    %r:    %s' % (formatter, e)))
    level = config.pop('level', None)
    filters = config.pop('filters', None)
    if ('()' in config):
        c = config.pop('()')
        if ((not hasattr(c, '__call__')) and hasattr(types, 'ClassType') and (type(c) != types.ClassType)):
            c = self.resolve(c)
        factory = c
    else:
        klass = self.resolve(config.pop('class'))
        if (issubclass(klass, logging.handlers.MemoryHandler) and ('target' in config)):
            try:
                config['target'] = self.config['handlers'][config['target']]
            except StandardError as e:
                raise ValueError(('Unable    to    set    target    handler    %r:    %s' % (config['target'], e)))
        elif (issubclass(klass, logging.handlers.SMTPHandler) and ('mailhost' in config)):
            config['mailhost'] = self.as_tuple(config['mailhost'])
        elif (issubclass(klass, logging.handlers.SysLogHandler) and ('address' in config)):
            config['address'] = self.as_tuple(config['address'])
        factory = klass
    kwargs = dict([(k, config[k]) for k in config if valid_ident(k)])
    try:
        result = factory(**kwargs)
    except TypeError as te:
        if ("'stream'" not in str(te)):
            raise
        kwargs['strm'] = kwargs.pop('stream')
        result = factory(**kwargs)
    if formatter:
        result.setFormatter(formatter)
    if (level is not None):
        result.setLevel(logging._checkLevel(level))
    if filters:
        self.add_filters(result, filters)
    return result
