class decorator to create "_full_state" methods/properties on the class (so they
    are valid for all instances created from this class).

    Parameters
    ----------
    class_with_globalize_methods
6084
def add_full_state_methods(class_with_globalize_methods):
    
    assert hasattr(class_with_globalize_methods, 'active_set')
    assert hasattr(class_with_globalize_methods, 'nstates_full')

    for name, method in class_with_globalize_methods.__dict__.copy().items():
        if isinstance(method, property) and hasattr(method.fget, '_map_to_full_state_def_arg'):
            default_value = method.fget._map_to_full_state_def_arg
            axis = method.fget._map_to_full_state_along_axis
            new_getter = _wrap_to_full_state(name, default_value, axis)
            alias_to_full_state_inst = property(new_getter)
        elif hasattr(method, '_map_to_full_state_def_arg'):
            default_value = method._map_to_full_state_def_arg
            axis = method._map_to_full_state_along_axis
            alias_to_full_state_inst = _wrap_to_full_state(name, default_value, axis)
        else:
            continue

        name += "_full_state"
        setattr(class_with_globalize_methods, name, alias_to_full_state_inst)

    return class_with_globalize_methods
787270
function classFulfills(classDefinition, protocol) {
	assertArgumentNotNullOrUndefined(classDefinition, ERROR_MESSAGES.NULL, 'Class', 'classFulfills');
	assertArgumentNotNullOrUndefined(protocol, ERROR_MESSAGES.NULL, 'Protocol', 'classFulfills');

	return fulfills(classDefinition.prototype, protocol);
}
255134
def singleton(the_class):
    
    class_instances = {}

    def get_instance(*args, **kwargs):
        """
        Creating or just return the one and only class instance.

        The singleton depends on the parameters used in __init__
        @type args: list
        @param args: positional arguments of the constructor.
        @type kwargs: dict
        @param kwargs: named parameters of the constructor.
        @rtype: decorated class type
        @return: singleton instance of decorated class.
        """
        key = (the_class, args, str(kwargs))
        if key not in class_instances:
            class_instances[key] = the_class(*args, **kwargs)
        return class_instances[key]

    return get_instance
752969
def instantiate(self, cls=None):
        
        if cls is None:
            cls = self.cls
        if cls is None:
            raise TypeError("cls must a class")
        return cls.create(*self.args, **self.kwargs)
1122395
def add_properties(self, names, methods):
        
        cls = type(self)
        cls = type(cls.__name__, (cls,), dict(cls.__dict__))
        if isinstance(names, string_types):
            names = [names]
            methods = [methods]
        for name,method in zip(names, methods):
            setattr(cls, name, property(method))
        return self.view(type=cls)
1322695
def _fullqualname_method_py2(obj):
    

    if obj.__self__ is None:
        # unbound methods
        module = obj.im_class.__module__
        cls = obj.im_class.__name__
    else:
        # bound methods
        if inspect.isclass(obj.__self__):
            # methods decorated with @classmethod
            module = obj.__self__.__module__
            cls = obj.__self__.__name__
        else:
            module = obj.__self__.__class__.__module__
            cls = obj.__self__.__class__.__name__

    return module + '.' + cls + '.' + obj.__func__.__name__
1153949
def as_view(cls, **initkwargs):
        
        # sanitize keyword arguments
        for key in initkwargs:
            if key in cls.http_method_names:
                raise TypeError("You tried to pass in the %s method name as a "
                                "keyword argument to %s(). Don't do that."
                                % (key, cls.__name__))
            if not hasattr(cls, key):
                raise TypeError("%s() received an invalid keyword %r. as_view "
                                "only accepts arguments that are already "
                                "attributes of the class." % (
                                    cls.__name__, key))

        def view(request, *args, **kwargs):
            self = cls(**initkwargs)
            if hasattr(self, 'get') and not hasattr(self, 'head'):
                self.head = self.get
            self.request = request
            self.args = args
            self.kwargs = kwargs
            self.authed_view = initkwargs.get('authed_view')
            self.authed_view_kwargs = initkwargs.get('authed_view_kwargs')
            self.anonymous_view = initkwargs.get('anonymous_view')
            self.anonymous_view_kwargs = initkwargs.get(
                'anonymous_view_kwargs')
            return self.dispatch(request, *args, **kwargs)
        # take name and docstring from class
        update_wrapper(view, cls, updated=())
        # and possible attributes set by decorators
        # like csrf_exempt from dispatch
        update_wrapper(view, cls.dispatch, assigned=())
        return view
1161668
private static Function<Service<HttpRequest, HttpResponse>,
            ? extends Service<HttpRequest, HttpResponse>> decorator(
            Method method, Class<?> clazz,
            Function<Service<HttpRequest, HttpResponse>,
                    ? extends Service<HttpRequest, HttpResponse>> initialDecorator) {

        final List<DecoratorAndOrder> decorators = collectDecorators(clazz, method);

        Function<Service<HttpRequest, HttpResponse>,
                ? extends Service<HttpRequest, HttpResponse>> decorator = initialDecorator;
        for (int i = decorators.size() - 1; i >= 0; i--) {
            final DecoratorAndOrder d = decorators.get(i);
            decorator = decorator.andThen(d.decorator());
        }
        return decorator;
    }
758523
def cachedmethod(cache, key=keys.hashkey, lock=None):
    
    def decorator(method):
        if lock is None:
            def wrapper(self, *args, **kwargs):
                c = cache(self)
                if c is None:
                    return method(self, *args, **kwargs)
                k = key(*args, **kwargs)
                try:
                    return c[k]
                except KeyError:
                    pass  # key not found
                v = method(self, *args, **kwargs)
                try:
                    c[k] = v
                except ValueError:
                    pass  # value too large
                return v
        else:
            def wrapper(self, *args, **kwargs):
                c = cache(self)
                if c is None:
                    return method(self, *args, **kwargs)
                k = key(*args, **kwargs)
                try:
                    with lock(self):
                        return c[k]
                except KeyError:
                    pass  # key not found
                v = method(self, *args, **kwargs)
                try:
                    with lock(self):
                        c[k] = v
                except ValueError:
                    pass  # value too large
                return v
        return _update_wrapper(wrapper, method)
    return decorator
558197
def global_state(self):
        
        self._generate_func_code()

        return dict(
            REGEX_PATTERNS=self._compile_regexps,
            re=re,
            JsonSchemaException=JsonSchemaException,
        )
785351
def _generate_standard_methods(cls):
        """"""
        for state in cls.context.states_enum:
            getter_name = 'is_{name}'.format(name=state.value)
            cls.context.new_methods[getter_name] = utils.generate_getter(state)

            setter_name = 'set_{name}'.format(name=state.value)
            cls.context.new_methods[setter_name] = utils.generate_setter(state)

            checker_name = 'can_be_{name}'.format(name=state.value)
            checker = utils.generate_checker(state)
            cls.context.new_methods[checker_name] = checker

        cls.context.new_methods['actual_state'] = utils.actual_state
        cls.context.new_methods['as_enum'] = utils.as_enum
        cls.context.new_methods['force_set'] = utils.force_set
652522
def ensure_state(default_getter, exc_class, default_msg=None):
    """"""
    def decorator(getter=default_getter, msg=default_msg):
        def ensure_decorator(f):
            @wraps(f)
            def inner(self, *args, **kwargs):
                if not getter(self):
                    raise exc_class(msg) if msg else exc_class()
                return f(self, *args, **kwargs)
            return inner
        return ensure_decorator
    return decorator
136205
def singleton(*args, **kwargs):
    '''
    
    '''

    def decorator(cls: type) -> Callable[[], object]:
        if issubclass(type(cls), _SingletonMetaClassBase):
            raise TypeError('cannot inherit from another singleton class.')

        box = _Box()
        factory = None
        lock = Lock()

        def metaclass_call(_):
            if box.value is None:
                with lock:
                    if box.value is None:
                        instance = cls(*args, **kwargs)
                        instance.__class__ = factory
                        box.value = (instance, ) # use tuple to handle `cls()` return `None`
            return box.value[0]

        def _is_init(*_):
            return box.value is not None

        SingletonMetaClass = type('SingletonMetaClass', (type(cls), _SingletonMetaClassBase), {
            '__slots__': (),
            '__call__': metaclass_call
        })

        factory = SingletonMetaClass(cls.__name__, (cls, ), {
            '__slots__': (),
            '_is_init': _is_init
        })
        return update_wrapper(factory, cls, updated=())

    return decorator
469899
function(cls,methods) {
    var keys = Object.keys(methods);
    var len = keys.length;
    for (var i = 0; i < len; i++) {
      var key = keys[i];
      cls.prototype[key] = lib.method.createMethod(methods[key]);
    }
    return cls;
  }
421261
def create(cls):
        
        if cls not in cls._instances:
            cls._instances[cls] = cls()

        return cls._instances[cls]
286400
def create_python_export(self):
        
        setattr(self, "C", ExportObject())

        for _class in self.get_classes():
            self._create_python_export_class(_class)
3341
def create_memoized_method
      name, method, freezer = @method_name, @original_method, @freezer
      @descendant.module_eval do
        define_method(name) do |&block|
          fail BlockNotAllowedError.new(self.class, name) if block
          memoized_method_cache.fetch(name) do
            freezer.call(method.bind(self).call)
          end
        end
      end
    end