Returns a Param Class Instance, by its kwarg or param name
186702
def _get(cls, kwarg_name):
        
        param_classes = cls._discover_params()
        try:
            param_class = param_classes[kwarg_name]
        except KeyError:
            raise ValueError('invalid param keyword {}'.format(kwarg_name))
        else:
            return param_class
577155
def from_params(cls, params):
        
        key_fn = lambda x: id(x[1].owner)
        streams = []
        for _, group in groupby(sorted(params.items(), key=key_fn), key_fn):
            group = list(group)
            inst = [p.owner for _, p in group][0]
            if not isinstance(inst, param.Parameterized):
                continue
            names = [p.name for _, p in group]
            rename = {p.name: n for n, p in group}
            streams.append(cls(inst, names, rename=rename))
        return streams
1057481
def _add_parameter(self_, param_name,param_obj):
        
        # CEBALERT: can't we just do
        # setattr(cls,param_name,param_obj)?  The metaclass's
        # __setattr__ is actually written to handle that.  (Would also
        # need to do something about the params() cache.  That cache
        # is a pain, but it definitely improved the startup time; it
        # would be worthwhile making sure no method except for one
        # "add_param()" method has to deal with it (plus any future
        # remove_param() method.)
        cls = self_.cls
        type.__setattr__(cls,param_name,param_obj)
        ParameterizedMetaclass._initialize_parameter(cls,param_name,param_obj)
        # delete cached params()
        try:
            delattr(cls,'_%s__params'%cls.__name__)
        except AttributeError:
            pass
1221115
def get_param_type(self, index):
        """'"""

        assert index in (0, 1)

        type_info = self.type.get_param_type(index)
        type_cls = get_return_class(type_info)
        instance = type_cls(None, type_info, [], self.backend)
        instance.setup()
        return instance
412934
def show_qparams(qtype, stream=sys.stdout):
    """"""
    for cls in all_subclasses(QueueAdapter):
        if cls.QTYPE == qtype: return stream.write(cls.QTEMPLATE)

    raise ValueError("Cannot find class associated to qtype %s" % qtype)
1051547
def instance(cls, *args, **kwgs):
        """"""
        if not hasattr(cls, "_instance"):
            cls._instance = cls(*args, **kwgs)
        return cls._instance
658799
def get_caller(*caller_class, **params):
    
    (frame, file, line, func, contextlist, index) = inspect.stack()[1]

    try: class_name = frame.f_locals["self"].__class__.__name__
    except: class_name = None

    if class_name:
        name = class_name + '.'
    elif caller_class != ():                                                                    # pragma: no cover
        name = inspect.getmodule(caller_class[0]).__name__ + '.'
    elif hasattr(inspect.getmodule(frame), '__name__'):
        name = inspect.getmodule(frame).__name__ + '.'
    else:                                                                                       # pragma: no cover
        name = ''

    if func == '__init__' and class_name:
        name = class_name + '()'
    elif name == '__main__.':                                                                   # pragma: no cover
        name = func + '()'
    else:
        name += func + '()'

    if 'persist_place' in params:
        get_caller._Persist_Place = params['persist_place']

    log = params.get('log', logging.getLogger())
    if get_caller._Persist_Place or params.get('place') or log.isEnabledFor(logging.DEBUG):
        name += ' [+{} {}]'.format(line, os.path.basename(file))
    return name
625004
def store_parameter(parameter):
    '''
    
    '''
    def decorator(fun):
        KeywordArgumentParser._parameter_dict[parameter] = fun
        return fun
    return decorator
505297
def get_kwargs(kwargs):
    
    return {
        key: value for key, value in six.iteritems(kwargs)
        if key != 'self'
    }
909090
def instance(*args, **kwargs):
        

        if not hasattr(Config, "_instance") or Config._instance is None:
            Config._instance = Config(*args, **kwargs)
        return Config._instance
205135
def instance_of(klass, arg):
    """"""
    if not isinstance(arg, klass):
        raise com.IbisTypeError(
            'Given argument with type {} is not an instance of {}'.format(
                type(arg), klass
            )
        )
    return arg
1065016
def from_param(cls, param):
        
        if isinstance(param, cls):
            return param
        if isinstance(param, list):
            return cls(param)
        if param is None:
            return cls.from_environment()
        # otherwise, assume it's a string.
        return cls.from_string(param)
438151
def get_parameter(self, name):
        
        for parameter in self._parameters:
            if parameter.name == name:
                return parameter
81734
def get_create_func(base_class, nickname):
    
    if base_class not in _REGISTRY:
        _REGISTRY[base_class] = {}
    registry = _REGISTRY[base_class]

    def create(*args, **kwargs):
        """Create instance from config"""
        if len(args):
            name = args[0]
            args = args[1:]
        else:
            name = kwargs.pop(nickname)

        if isinstance(name, base_class):
            assert len(args) == 0 and len(kwargs) == 0, \
                "%s is already an instance. Additional arguments are invalid"%(nickname)
            return name

        if isinstance(name, dict):
            return create(**name)

        assert isinstance(name, string_types), "%s must be of string type"%nickname

        if name.startswith('['):
            assert not args and not kwargs
            name, kwargs = json.loads(name)
            return create(name, **kwargs)
        elif name.startswith('{'):
            assert not args and not kwargs
            kwargs = json.loads(name)
            return create(**kwargs)

        name = name.lower()
        assert name in registry, \
            "%s is not registered. Please register with %s.register first"%(
                str(name), nickname)
        return registry[name](*args, **kwargs)

    create.__doc__ = """Create a %s instance from config.

Parameters
----------
%s : str or %s instance
    class name of desired instance. If is a instance,
    it will be returned directly.
**kwargs : dict
    arguments to be passed to constructor"""%(nickname, nickname, base_class.__name__)

    return create
627117
def _instance(self, cls, *args, **kwargs):
        
        logger.debug(f'args: {args}, kwargs: {kwargs}')
        return cls(*args, **kwargs)
535715
def get(self, name, **kwargs):
        
        name = self._prefix + name
        if name not in self._params:
            self._params[name] = symbol.Variable(name, **kwargs)
        return self._params[name]
206388
def _preprocess_params(cls, kwargs):
        
        # kwargs.pop('csrf_token', None)
        for attr, val in kwargs.items():
            if cls.is_the_primary_key(attr) and cls._prevent_primary_key_initialization_:
                del kwargs[attr]
                continue
            if val == "":
                # Making an assumption that there is no good usecase
                # for setting an empty string. This will help prevent
                # cases where empty string is sent because of client
                # not clearing form fields to null
                kwargs[attr] = None
                continue
            if attr in class_mapper(cls).relationships and attr not in cls._no_overwrite_:
                rel = class_mapper(cls).relationships[attr]
                if rel.uselist:
                    if isinstance(val, list):
                        if all(isinstance(v, dict) for v in val):
                            rel_cls = cls.mapped_rel_class(attr)
                            kwargs[attr] = rel_cls.update_or_new_all(
                                list_of_kwargs=val, keys=[rel_cls.primary_key_name()])
                    elif isinstance(val, dict):
                        rel_cls = cls.mapped_rel_class(attr)
                        mapping_col = rel.collection_class().keyfunc.name
                        list_of_kwargs = [merge(v, {mapping_col: k}) for k, v in val.items()]
                        kwargs[attr] = {getattr(obj, mapping_col): obj for obj in rel_cls.update_or_new_all(
                            list_of_kwargs=list_of_kwargs, keys=[rel_cls.primary_key_name()])}
                elif isinstance(val, dict):
                    rel_cls = cls.mapped_rel_class(attr)
                    kwargs[attr] = rel_cls.update_or_new(
                        **merge(val, {'keys': [rel_cls.primary_key_name()]}))
        return kwargs