Instantiate class or function
    :param obj_name: class or function name
    :return: instance of class or function
435008
def obj_for_name(obj_name):
    
    parts = obj_name.split('.')
    module = ".".join(parts[:-1])
    m = __import__( module )
    for comp in parts[1:]:
        m = getattr(m, comp)
    return m
938659
def instantiate_from_data(self, object_data):
        
        if isinstance(object_data, dict) and 'name' in object_data:
            name = object_data['name']
            module = importlib.import_module(name)
            return self.resolve_and_call(module.create, extra_env=object_data)
        if isinstance(object_data, dict) and 'factory' in object_data:
            factory = object_data['factory']
            module = importlib.import_module(factory)
            params = self.resolve_parameters(module.create, extra_env=object_data)
            return GenericFactory(module.create, params)
        elif isinstance(object_data, dict):
            return {k: self.instantiate_from_data(v) for k, v in object_data.items()}
        elif isinstance(object_data, list):
            return [self.instantiate_from_data(x) for x in object_data]
        elif isinstance(object_data, Variable):
            return object_data.resolve(self.parameters)
        else:
            return object_data
1018819
def _getattr(obj, name, default):
    
    value = getattr(obj, name, default)
    if value:
        return value
    else:
        return default
1135129
def import_object(name):
    
    parts = name.split('.')
    if len(parts) < 2:
        raise ValueError("Invalid name '%s'" % name)
    module_name = ".".join(parts[:-1])
    obj_name = parts[-1]
    module = importlib.import_module(module_name)
    return getattr(module, obj_name)
152770
def init_arg_names(obj):
    
    # doing something wildly hacky by pulling out the arguments to
    # __init__ or __new__ and hoping that they match fields defined on the
    # object
    try:
        init_code = obj.__init__.__func__.__code__
    except AttributeError:
        try:
            init_code = obj.__new__.__func__.__code__
        except AttributeError:
            # if object is a namedtuple then we can return its fields
            # as the required initial args
            if hasattr(obj, "_fields"):
                return obj._fields
            else:
                raise ValueError("Cannot determine args to %s.__init__" % (obj,))

    arg_names = init_code.co_varnames[:init_code.co_argcount]
    # drop self argument
    nonself_arg_names = arg_names[1:]
    return nonself_arg_names
1007564
def factory(cls, **kwargs):
    
    for name, obj in inspect.getmembers(sys.modules[__name__]):
        if inspect.isclass(obj) and issubclass(obj, UserAuthnMethod):
            try:
                if obj.__name__ == cls:
                    return obj(**kwargs)
            except AttributeError:
                pass
1023926
def _onInstanceAttribute(self, name, line, pos, absPosition, level):
        """"""
        # Instance attributes may appear in member functions only so we already
        # have a function on the stack of objects. To get the class object one
        # more step is required so we -1 here.
        attributes = self.objectsStack[level - 1].instanceAttributes
        for item in attributes:
            if item.name == name:
                return
        attributes.append(InstanceAttribute(name, line, pos, absPosition))
341179
def _instantiate(self, module, class_name,
                     args=None, kwargs=None, static=None):
        
        if args is None:
            args = []
        if kwargs is None:
            kwargs = {}
        if static is None:
            static = False

        _check_type('args', args, list)
        _check_type('kwargs', kwargs, dict)

        if static and class_name is None:
            return module

        if static and class_name is not None:
            return getattr(module, class_name)

        service_obj = getattr(module, class_name)

        # Replace scalars
        args = self._replace_scalars_in_args(args)
        kwargs = self._replace_scalars_in_kwargs(kwargs)

        # Replace service references
        args = self._replace_services_in_args(args)
        kwargs = self._replace_services_in_kwargs(kwargs)

        # Instantiate object
        return service_obj(*args, **kwargs)
610698
def getfunc(obj, name=''):
    ''''''
    if name:
        obj = getattr(obj, name)
    return getattr(obj, '__func__', obj)
439630
def patch_class(input_class):
    
    class Instantiator(object):
        @classmethod
        def _doubles__new__(self, *args, **kwargs):
            pass

    new_class = type(input_class.__name__, (input_class, Instantiator), {})

    return new_class
708921
def get_class_by_name!(name , super_class = :Object)
      c = get_class_by_name(name)
      return c if c
      create_class( name ,super_class)
    end
107583
def get_or_create(cls, name):
        
        obj = cls.query.filter_by(name=name).one_or_none()
        if obj:
            return obj
        try:
            with session.begin_nested():
                obj = cls(name=name)
                session.add(obj)
                session.flush()
            return obj
        except IntegrityError:
            log.debug('Collision when adding %s(name="%s"), returning existing object',
                      cls.__name__, name)
            return cls.query.filter_by(name=name).one()
364547
def instantiate_by_name_with_default(self, object_name, default_value=None):
        
        if object_name not in self.instances:
            if object_name not in self.environment:
                return default_value
            else:
                instance = self.instantiate_from_data(self.environment[object_name])

                self.instances[object_name] = instance
                return instance
        else:
            return self.instances[object_name]
928521
def factory(cls, class_name):
        
        class_name = str(class_name.lstrip('_'))
        types = ParseResource.__subclasses__()
        while types:
            t = types.pop()
            if t.__name__ == class_name:
                return t
            types.extend(t.__subclasses__())
        else:
            return type(class_name, (Object,), {})
315043
def get_object_from_dictionary_representation(dictionary, class_type):
        
        assert inspect.isclass(class_type), 'Cannot instantiate an object that is not a class'

        instance = class_type()

        CoyoteDb.update_object_from_dictionary_representation(dictionary, instance)

        return instance
897066
def from_main(cls, signature=''):
        
        instance = cls()

        def decorate(function):
            instance.main(signature)(function)
            return instance
        return decorate
655136
def new_instance(self, name):
        
        ist = lib.EnvCreateRawInstance(self._env, self._cls, name.encode())
        if ist == ffi.NULL:
            raise CLIPSError(self._env)

        return Instance(self._env, ist)