Create a new class starting with the base and adding capabilities.
487254
def compose_capability(base, *classes):
    """"""
    if _debug: compose_capability._debug("compose_capability %r %r", base, classes)

    # make sure the base is a Collector
    if not issubclass(base, Collector):
        raise TypeError("base must be a subclass of Collector")

    # make sure you only add capabilities
    for cls in classes:
        if not issubclass(cls, Capability):
            raise TypeError("%s is not a Capability subclass" % (cls,))

    # start with everything the base has and add the new ones
    bases = (base,) + classes

    # build a new name
    name = base.__name__
    for cls in classes:
        name += '+' + cls.__name__

    # return a new type
    return type(name, bases, {})
1017486
def _create(cls, model_class, *args, **kwargs):
        """"""
        if cls._meta.django_get_or_create:
            return cls._get_or_create(model_class, *args, **kwargs)

        manager = cls._get_manager(model_class)
        return manager.create(*args, **kwargs)
639496
def with_env(cls, env):
        
        new_cls = type(cls.__name__, cls.__bases__, dict(cls.__dict__))
        new_cls._env = env
        return new_cls
544319
def create(self, **kwargs):
        """"""
        body = self.client.create(url=self.base_url,
                                  json=kwargs)
        return body
1252886
def create(self, **kwargs):
        
        if self.created:
            raise RuntimeError(
                '{} already created.'.format(self.__model_type__.__name__))

        kwargs = self.merge_kwargs(self._create_kwargs, kwargs)

        self._inner = self.helper.create(
            self.name, *self._create_args, **kwargs)
1316967
def new(self, name, *args, **kwargs):
        '''
        '''
        if name in self._instance_map:
            raise ValueError('Instance {0} is already initialized'
                             .format(name))

        instance = self._class_map[name](*args, **kwargs)
        self._instance_map[name] = instance
        return instance
1116474
def create(cls, selective: typing.Optional[base.Boolean] = None):
        
        return cls(selective=selective)
38755
def with_metaclass(meta, *bases):
    """"""

    class metaclass(meta):
        def __new__(cls, name, this_bases, d):
            return meta(name, bases, d)

    return type.__new__(metaclass, "temporary_class", (), {})
843900
def build_from_bases(bases, classdict, attr, attr_dict):
    """"""
    output = OrderedDict()
    output_keys = set()
    all_bases = []
    # Go through the bases from furthest to nearest ancestor
    for base in reversed(bases):
        # Only keep the items that are still defined on the bases
        if base is not object and isinstance(base, PropertyMetaclass):
            output_keys = output_keys.union(getattr(base, attr))
        # Collect all bases so we ensure overridden items are assigned
        # in the correct order
        for item in reversed(base.__mro__):
            if item is object or not isinstance(item, PropertyMetaclass):
                continue
            if item not in all_bases:
                all_bases.append(item)
    # Update the items in reverse MRO order; only keep those that are
    # defined on the bases
    for base in all_bases:
        for key, val in iteritems(getattr(base, attr)):
            if key in base.__dict__ and key in output_keys:
                output.update({key: val})
    # Remove all items that were overridden by this class; this is
    # potentially a superset of the items added back in the next step.
    for key in classdict:
        if key in output:
            output.pop(key)
    # Update the items with those defined on this class
    output.update(attr_dict)
    return output
149793
def add_class(self, ioclass):
        
        current_ioclasses = self.ioclasses
        if ioclass.name in current_ioclasses.name:
            return
        current_ioclasses.append(ioclass)
        self.modify(new_ioclasses=current_ioclasses)
195554
public function build() {

        // Add some extra settings that related processors are going to need
        $this->add_setting(new backup_activity_generic_setting(backup::VAR_COURSEID, base_setting::IS_INTEGER, $this->get_courseid()));
        $this->add_setting(new backup_activity_generic_setting(backup::VAR_CONTEXTID, base_setting::IS_INTEGER, $this->contextid));

        // Create the course directory
        $this->add_step(new create_taskbasepath_directory('create_course_directory'));

        // Create the course.xml file with course & category information
        // annotating some bits, tags and module restrictions
        $this->add_step(new backup_course_structure_step('course_info', 'course.xml'));

        // Generate the enrolment file (conditionally, prevent it in any IMPORT/HUB operation)
        if ($this->plan->get_mode() != backup::MODE_IMPORT && $this->plan->get_mode() != backup::MODE_HUB) {
            $this->add_step(new backup_enrolments_structure_step('course_enrolments', 'enrolments.xml'));
        }

        // Annotate enrolment custom fields.
        $this->add_step(new backup_enrolments_execution_step('annotate_enrol_custom_fields'));

        // Annotate all the groups and groupings belonging to the course. This can be optional.
        if ($this->get_setting_value('groups')) {
            $this->add_step(new backup_annotate_course_groups_and_groupings('annotate_course_groups'));
        }

        // Annotate the groups used in already annotated groupings (note this may be
        // unnecessary now that we are annotating all the course groups and groupings in the
        // step above). This is here to support course->defaultgroupingid.
        // This may not be required to annotate if groups are not being backed up.
        if ($this->get_setting_value('groups')) {
            $this->add_step(new backup_annotate_groups_from_groupings('annotate_groups_from_groupings'));
        }

        // Annotate the question_categories belonging to the course context (conditionally).
        if ($this->get_setting_value('questionbank')) {
            $this->add_step(new backup_calculate_question_categories('course_question_categories'));
        }

        // Generate the roles file (optionally role assignments and always role overrides)
        $this->add_step(new backup_roles_structure_step('course_roles', 'roles.xml'));

        // Generate the filter file (conditionally)
        if ($this->get_setting_value('filters')) {
            $this->add_step(new backup_filters_structure_step('course_filters', 'filters.xml'));
        }

        // Generate the comments file (conditionally)
        if ($this->get_setting_value('comments')) {
            $this->add_step(new backup_comments_structure_step('course_comments', 'comments.xml'));
        }

        // Generate the calender events file (conditionally)
        if ($this->get_setting_value('calendarevents')) {
            $this->add_step(new backup_calendarevents_structure_step('course_calendar', 'calendar.xml'));
        }

        // Generate the logs file (conditionally)
        if ($this->get_setting_value('logs')) {
            // Legacy logs.
            $this->add_step(new backup_course_logs_structure_step('course_logs', 'logs.xml'));
            // New log stores.
            $this->add_step(new backup_course_logstores_structure_step('course_logstores', 'logstores.xml'));
        }

        // Generate the course competencies.
        $this->add_step(new backup_course_competencies_structure_step('course_competencies', 'competencies.xml'));

        // Annotate activity completion defaults.
        $this->add_step(new backup_completion_defaults_structure_step('course_completion_defaults', 'completiondefaults.xml'));

        // Generate the inforef file (must be after ALL steps gathering annotations of ANY type)
        $this->add_step(new backup_inforef_structure_step('course', 'inforef.xml'));

        // Migrate the already exported inforef entries to final ones
        $this->add_step(new move_inforef_annotations_to_final('migrate_inforef'));

        // At the end, mark it as built
        $this->built = true;
    }
137113
def setUpClass(cls):
        """"""
        self.obsmode=None
        self.spectrum=None
        self.bp=None
        self.sp=None
        self.obs=None
        self.setup2()
1069165
public static function newInstance($baseclass, $args = array(), &$module = null)
    {
        $modules = ModuleManager::getInstance()->getModules();
        foreach ($modules as $module) {
            if (in_array($baseclass, $module->getModels())) {
                $classes = array('\\' . $module->modelNamespace . '\\' . $baseclass, $baseclass);
                foreach ($classes as $class) {
                    if (class_exists($class)) {

                        return new $class($args);
                    }
                }
            }
        }
        $class = '\\GLFramework\\Model\\' . $baseclass;
        if (class_exists($class)) {
            return new $class($args);
        }
        return false;
    }
279436
def create_module(base_module, name)
      desired_class = camelize(name)
      possible_suffixes = [''] + %w{1 2 3 4 5 6 7 8 9 10}
      if suffix = possible_suffixes.find {|e|
        !base_module.const_defined?(desired_class+e) }
          base_module.const_set(desired_class+suffix, Module.new)
      end
    end
401850
def add_bases(cls, *bases):
    
    assert inspect.isclass(cls), "Expected class object"
    for mixin in bases:
        assert inspect.isclass(mixin), "Expected class object for bases"
    new_bases = (bases + cls.__bases__)
    cls.__bases__ = new_bases
209415
def add_to_class(self, cls, name):
        '''
        
        '''
        self.model_class = cls
        setattr(cls, name, PhoneNumberDescriptor(self))
        self._bound = True
644419
public static function bootIsAbility()
    {
        BaseTenantScope::register(static::class);

        static::creating(function ($ability) {
            Models::scope()->applyToModel($ability);

            if (is_null($ability->title)) {
                $ability->title = AbilityTitle::from($ability)->toString();
            }
        });
    }