Exemplo n.º 1
0
class ApiNodeMetaclass(type):
    parent_class = writeonce(
        None,
        writeonce_msg=
        u'Duplicate in API tree: %(instance)s already has parent %(old_value)s though %(value)s can not be set as new parent'
    )

    def __new__(cls, name, parents, dct):
        ret = super(ApiNodeMetaclass, cls).__new__(cls, name, parents, dct)
        # Initializing internal class attributes
        ret._serializers_preparations = None

        for node_name, node_class in ret.iter_children():
            node_class.parent_class = ret
            if not node_class.name:
                node_class.name = node_name.lower()
        ret.prepare_serializers()
        return ret

    @property
    def urls(cls):
        cls.get_root_class()  # check for loops
        return cls.get_urls()

    def __str__(cls):
        if not hasattr(cls, '_strval'):
            s = cls.__name__
            node = cls
            i = 0
            N = 10
            while node.parent_class is not None and i < N:
                s = node.parent_class.__name__ + '.' + s
                node = node.parent_class
                i += 1
            if i == N:
                s = ' ...%s' % s
            else:
                s = '.%s' % s

            cls._strval = '%s%s' % (node.__module__, s)
        return cls._strval
Exemplo n.º 2
0
 class A(object):
     x = writeonce()
Exemplo n.º 3
0
 class M(type):
     x = writeonce()
Exemplo n.º 4
0
 class A(object):
     x = writeonce(default)
Exemplo n.º 5
0
 class B(A):
     x = writeonce()  # explicit override - so it's ok
Exemplo n.º 6
0
    class A(object):
        x = writeonce(writeonce_msg='qwe-%(name)s-%(instance)s-%(value)s-%(old_value)s')

        def __str__(self):
            return 'a'