Esempio n. 1
0
    def customize(cls, **kwargs):
        """Duplicates cls and overwrites the values in ``cls.Attributes`` with
        ``**kwargs`` and returns the new class."""

        store_as = apply_pssm(kwargs.get('store_as', None), PSSM_VALUES)
        if store_as is not None:
            kwargs['store_as'] = store_as

        cls_name, cls_bases, cls_dict = cls._s_customize(cls, **kwargs)
        cls_dict['__module__'] = cls.__module__

        retval = type(cls_name, cls_bases, cls_dict)
        retval._type_info = TypeInfo(cls._type_info)
        retval.__type_name__ = cls.__type_name__
        retval.__namespace__ = cls.__namespace__
        retval.Attributes.parent_variant = cls

        child_attrs = kwargs.get('child_attrs', None)
        if child_attrs is not None:
            ti = retval._type_info
            for k, v in child_attrs.items():
                ti[k] = ti[k].customize(**v)

        tn = kwargs.get("type_name", None)
        if tn is not None:
            retval.__type_name__ = tn

        ns = kwargs.get("namespace", None)
        if ns is not None:
            retval.__namespace__ = ns

        if not cls is ComplexModel:
            cls._process_variants(retval)

        return retval
Esempio n. 2
0
    def customize(cls, **kwargs):
        """Duplicates cls and overwrites the values in ``cls.Attributes`` with
        ``**kwargs`` and returns the new class."""

        store_as = apply_pssm(kwargs.get('store_as', None))
        if store_as is not None:
            kwargs['store_as'] = store_as

        return super(AnyHtml, cls).customize(**kwargs)
Esempio n. 3
0
    def customize(cls, **kwargs):
        """Duplicates cls and overwrites the values in ``cls.Attributes`` with
        ``**kwargs`` and returns the new class."""

        store_as = apply_pssm(kwargs.get('store_as', None))
        if store_as is not None:
            kwargs['store_as'] = store_as

        return super(AnyHtml, cls).customize(**kwargs)
Esempio n. 4
0
    def customize(cls, **kwargs):
        """Duplicates cls and overwrites the values in ``cls.Attributes`` with
        ``**kwargs`` and returns the new class."""

        store_as = apply_pssm(kwargs.get('store_as', None),
                                {'json': json, 'xml': xml, 'msgpack': msgpack})
        if store_as is not None:
            kwargs['store_as'] = store_as

        return super(AnyDict, cls).customize(**kwargs)
Esempio n. 5
0
    def customize(cls, **kwargs):
        """Duplicates cls and overwrites the values in ``cls.Attributes`` with
        ``**kwargs`` and returns the new class."""

        store_as = apply_pssm(kwargs.get('store_as', None),
                                {'json': json, 'xml': xml, 'msgpack': msgpack})
        if store_as is not None:
            kwargs['store_as'] = store_as

        return super(AnyDict, cls).customize(**kwargs)
Esempio n. 6
0
    def customize(cls, **kwargs):
        """Duplicates cls and overwrites the values in ``cls.Attributes`` with
        ``**kwargs`` and returns the new class."""

        store_as = apply_pssm(kwargs.get('store_as', None), PSSM_VALUES)
        if store_as is not None:
            kwargs['store_as'] = store_as

        cls_name, cls_bases, cls_dict = cls._s_customize(cls, **kwargs)
        cls_dict['__module__'] = cls.__module__

        retval = type(cls_name, cls_bases, cls_dict)
        retval._type_info = TypeInfo(cls._type_info)
        retval.__type_name__ = cls.__type_name__
        retval.__namespace__ = cls.__namespace__
        retval.Attributes.parent_variant = cls

        dca = retval.Attributes._delayed_child_attrs
        if retval.Attributes._delayed_child_attrs is None:
            retval.Attributes._delayed_child_attrs = {}
        else:
            retval.Attributes._delayed_child_attrs = dict(dca.items())

        child_attrs = kwargs.get('child_attrs', None)
        if child_attrs is not None:
            ti = retval._type_info
            for k, v in child_attrs.items():
                if k in ti:
                    ti[k] = ti[k].customize(**v)
                else:
                    retval.Attributes._delayed_child_attrs[k] = v

        tn = kwargs.get("type_name", None)
        if tn is not None:
            retval.__type_name__ = tn

        ns = kwargs.get("namespace", None)
        if ns is not None:
            retval.__namespace__ = ns

        if not cls is ComplexModel:
            cls._process_variants(retval)

        # we could be smarter, but customize is supposed to be called only while
        # daemon initialization, so it's not really necessary.
        ComplexModelBase.get_subclasses.memo.clear()
        ComplexModelBase.get_flat_type_info.memo.clear()
        ComplexModelBase.get_simple_type_info.memo.clear()

        return retval
Esempio n. 7
0
    def customize(cls, **kwargs):
        """Duplicates cls and overwrites the values in ``cls.Attributes`` with
        ``**kwargs`` and returns the new class.

        Because each class is registered as a variant of the original (__orig__)
        class, using this function to generate classes dynamically on-the-fly
        could cause memory leaks. You have been warned.
        """

        store_as = apply_pssm(kwargs.get("store_as", None), PSSM_VALUES)
        if store_as is not None:
            kwargs["store_as"] = store_as

        cls_name, cls_bases, cls_dict = cls._s_customize(cls, **kwargs)
        cls_dict["__module__"] = cls.__module__
        if "__extends__" not in cls_dict:
            cls_dict["__extends__"] = cls.__extends__

        retval = type(cls_name, cls_bases, cls_dict)
        retval._type_info = TypeInfo(cls._type_info)
        retval.__type_name__ = cls.__type_name__
        retval.__namespace__ = cls.__namespace__
        retval.Attributes.parent_variant = cls

        dca = retval.Attributes._delayed_child_attrs
        if retval.Attributes._delayed_child_attrs is None:
            retval.Attributes._delayed_child_attrs = {}
        else:
            retval.Attributes._delayed_child_attrs = dict(dca.items())

        tn = kwargs.get("type_name", None)
        if tn is not None:
            retval.__type_name__ = tn

        ns = kwargs.get("namespace", None)
        if ns is not None:
            retval.__namespace__ = ns

        if cls is not ComplexModel:
            cls._process_variants(retval)

        _process_child_attrs(cls, retval, kwargs)

        # we could be smarter, but customize is supposed to be called only
        # during daemon initialization, so it's not really necessary.
        ComplexModelBase.get_subclasses.memo.clear()
        ComplexModelBase.get_flat_type_info.memo.clear()
        ComplexModelBase.get_simple_type_info.memo.clear()

        return retval
Esempio n. 8
0
    def customize(cls, **kwargs):
        """Duplicates cls and overwrites the values in ``cls.Attributes`` with
        ``**kwargs`` and returns the new class.

        Because each class is registered as a variant of the original (__orig__)
        class, using this function to generate classes dynamically on-the-fly
        could cause memory leaks. You have been warned.
        """

        store_as = apply_pssm(kwargs.get('store_as', None), PSSM_VALUES)
        if store_as is not None:
            kwargs['store_as'] = store_as

        cls_name, cls_bases, cls_dict = cls._s_customize(cls, **kwargs)
        cls_dict['__module__'] = cls.__module__
        if '__extends__' not in cls_dict:
            cls_dict['__extends__'] = cls.__extends__

        retval = type(cls_name, cls_bases, cls_dict)
        retval._type_info = TypeInfo(cls._type_info)
        retval.__type_name__ = cls.__type_name__
        retval.__namespace__ = cls.__namespace__
        retval.Attributes.parent_variant = cls

        dca = retval.Attributes._delayed_child_attrs
        if retval.Attributes._delayed_child_attrs is None:
            retval.Attributes._delayed_child_attrs = {}
        else:
            retval.Attributes._delayed_child_attrs = dict(dca.items())

        tn = kwargs.get("type_name", None)
        if tn is not None:
            retval.__type_name__ = tn

        ns = kwargs.get("namespace", None)
        if ns is not None:
            retval.__namespace__ = ns

        if cls is not ComplexModel:
            cls._process_variants(retval)

        _process_child_attrs(cls, retval, kwargs)

        # we could be smarter, but customize is supposed to be called only
        # during daemon initialization, so it's not really necessary.
        ComplexModelBase.get_subclasses.memo.clear()
        ComplexModelBase.get_flat_type_info.memo.clear()
        ComplexModelBase.get_simple_type_info.memo.clear()

        return retval
Esempio n. 9
0
    def customize(cls, **kwargs):
        """Duplicates cls and overwrites the values in ``cls.Attributes`` with
        ``**kwargs`` and returns the new class."""

        store_as = apply_pssm(kwargs.get('store_as', None), PSSM_VALUES)
        if store_as is not None:
            kwargs['store_as'] = store_as

        cls_name, cls_bases, cls_dict = cls._s_customize(cls, **kwargs)
        cls_dict['__module__'] = cls.__module__

        retval = type(cls_name, cls_bases, cls_dict)
        retval._type_info = TypeInfo(cls._type_info)
        retval.__type_name__ = cls.__type_name__
        retval.__namespace__ = cls.__namespace__
        retval.Attributes.parent_variant = cls

        dca = retval.Attributes._delayed_child_attrs
        if retval.Attributes._delayed_child_attrs is None:
            retval.Attributes._delayed_child_attrs = {}
        else:
            retval.Attributes._delayed_child_attrs = dict(dca.items())

        child_attrs = kwargs.get('child_attrs', None)
        if child_attrs is not None:
            ti = retval._type_info
            for k, v in child_attrs.items():
                if k in ti:
                    ti[k] = ti[k].customize(**v)
                else:
                    retval.Attributes._delayed_child_attrs[k] = v

        tn = kwargs.get("type_name", None)
        if tn is not None:
            retval.__type_name__ = tn

        ns = kwargs.get("namespace", None)
        if ns is not None:
            retval.__namespace__ = ns

        if not cls is ComplexModel:
            cls._process_variants(retval)

        # we could be smarter, but customize is supposed to be called only while
        # daemon initialization, so it's not really necessary.
        ComplexModelBase.get_subclasses.memo.clear()
        ComplexModelBase.get_flat_type_info.memo.clear()
        ComplexModelBase.get_simple_type_info.memo.clear()

        return retval