[buildobjs] use six to declare metaclasses

Deals with the different syntaxes in python 2 and 3. Related to #267910.

authorJulien Cristau <julien.cristau@logilab.fr>
changesetbe56e667d39b
branchdefault
phasepublic
hiddenno
parent revision#3cab8d5497df [pkg] add dependency on six
child revision#5a242c279995 [diff] deal with py3k string types
files modified by this revision
buildobjs.py
# HG changeset patch
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1413450264 -7200
# Thu Oct 16 11:04:24 2014 +0200
# Node ID be56e667d39b2046f16ff9986c9d5e16ac815f40
# Parent 3cab8d5497dfa484ba50b512c3ae183a1685f0fc
[buildobjs] use six to declare metaclasses

Deals with the different syntaxes in python 2 and 3. Related to
#267910.

diff --git a/buildobjs.py b/buildobjs.py
@@ -20,10 +20,12 @@
1  __docformat__ = "restructuredtext en"
2 
3  from warnings import warn
4  from copy import copy
5 
6 +from six import add_metaclass
7 +
8  from logilab.common import attrdict
9  from logilab.common.decorators import iclassmethod
10 
11  from yams import (BASE_TYPES, MARKER, BadSchemaDefinition, KNOWN_METAATTRIBUTES,
12                    DEFAULT_RELPERMS, DEFAULT_ATTRPERMS, DEFAULT_COMPUTED_ATTRPERMS)
@@ -120,14 +122,13 @@
13  class autopackage(type):
14      def __new__(mcs, name, bases, classdict):
15          classdict['package'] = PACKAGE
16          return super(autopackage, mcs).__new__(mcs, name, bases, classdict)
17 
18 +@add_metaclass(autopackage)
19  class Definition(object):
20      """Abstract class for entity / relation definition classes."""
21 -    __metaclass__ = autopackage
22 -
23      meta = MARKER
24      description = MARKER
25      __permissions__ = MARKER
26 
27      def __init__(self, name=None):
@@ -392,10 +393,11 @@
28          ### sort relations by creation rank
29          defclass.__relations__ = sorted(rels, key=lambda r: r.creation_rank)
30          return defclass
31 
32 
33 +@add_metaclass(metadefinition)
34  class EntityType(Definition):
35      #::FIXME reader magic forbids to define a docstring...
36      #: an entity has attributes and can be linked to other entities by
37      #: relations. Both entity attributes and relationships are defined by
38      #: class attributes.
@@ -417,11 +419,10 @@
39      #:  .. automethod:: EntityType.insert_relation_after
40      #:  .. automethod:: EntityType.remove_relation
41      #:  .. automethod:: EntityType.get_relation
42      #:  .. automethod:: EntityType.get_relations
43 
44 -    __metaclass__ = metadefinition
45      __permissions__ = {
46          'read': ('managers', 'users', 'guests',),
47          'update': ('managers', 'owners',),
48          'delete': ('managers', 'owners'),
49          'add': ('managers', 'users',)