[py3k] use six.add_metaclass
authorRémi Cardona <remi.cardona@logilab.fr>
Wed, 16 Sep 2015 13:57:21 +0200
changeset 10688 fa29f3628a1b
parent 10687 d394bfcd8c25
child 10689 49a62b8f6d43
[py3k] use six.add_metaclass
dataimport/deprecated.py
devtools/fill.py
repoapi.py
toolsutils.py
web/box.py
web/component.py
web/form.py
web/htmlwidgets.py
web/uihelper.py
web/views/__init__.py
web/views/boxes.py
web/views/plots.py
web/views/tableview.py
web/views/urlrewrite.py
web/views/workflow.py
--- a/dataimport/deprecated.py	Wed Sep 16 11:28:07 2015 +0200
+++ b/dataimport/deprecated.py	Wed Sep 16 13:57:21 2015 +0200
@@ -64,6 +64,8 @@
 import traceback
 from StringIO import StringIO
 
+from six import add_metaclass
+
 from logilab.common import attrdict, shellutils
 from logilab.common.date import strptime
 from logilab.common.deprecation import deprecated, class_deprecated
@@ -116,9 +118,9 @@
     return answer == 'Y'
 
 
+@add_metaclass(class_deprecated)
 class catch_error(object):
     """Helper for @contextmanager decorator."""
-    __metaclass__ = class_deprecated
     __deprecation_warning__ = '[3.21] deprecated'
 
     def __init__(self, ctl, key='unexpected error', msg=None):
@@ -257,6 +259,7 @@
             if k is not None and len(v) > 1]
 
 
+@add_metaclass(class_deprecated)
 class ObjectStore(object):
     """Store objects in memory for *faster* validation (development mode)
 
@@ -267,7 +270,6 @@
     >>> group = store.prepare_insert_entity('CWUser', name=u'unknown')
     >>> store.prepare_insert_relation(user, 'in_group', group)
     """
-    __metaclass__ = class_deprecated
     __deprecation_warning__ = '[3.21] use the new importer API'
 
     def __init__(self):
@@ -338,6 +340,7 @@
         self.prepare_insert_relation(eid_from, rtype, eid_to, **kwargs)
 
 
+@add_metaclass(class_deprecated)
 class CWImportController(object):
     """Controller of the data import process.
 
@@ -346,7 +349,6 @@
     >>> ctl.data = dict_of_data_tables
     >>> ctl.run()
     """
-    __metaclass__ = class_deprecated
     __deprecation_warning__ = '[3.21] use the new importer API'
 
     def __init__(self, store, askerror=0, catcherrors=None, tell=tell,
--- a/devtools/fill.py	Wed Sep 16 11:28:07 2015 +0200
+++ b/devtools/fill.py	Wed Sep 16 13:57:21 2015 +0200
@@ -27,6 +27,7 @@
 from datetime import datetime, date, time, timedelta
 from decimal import Decimal
 
+from six import add_metaclass
 from six.moves import range
 
 from logilab.common import attrdict
@@ -262,8 +263,10 @@
                 setattr(_ValueGenerator, attrname, attrvalue)
         return type.__new__(mcs, name, bases, classdict)
 
+
+@add_metaclass(autoextend)
 class ValueGenerator(_ValueGenerator):
-    __metaclass__ = autoextend
+    pass
 
 
 def _default_choice_func(etype, attrname):
--- a/repoapi.py	Wed Sep 16 11:28:07 2015 +0200
+++ b/repoapi.py	Wed Sep 16 13:57:21 2015 +0200
@@ -18,6 +18,9 @@
 """Official API to access the content of a repository
 """
 from warnings import warn
+
+from six import add_metaclass
+
 from logilab.common.deprecation import class_deprecated
 
 from cubicweb.utils import parse_repo_uri
@@ -63,6 +66,6 @@
     return connect(repo, anon_login, password=anon_password)
 
 
+@add_metaclass(class_deprecated)
 class ClientConnection(Connection):
-    __metaclass__ = class_deprecated
     __deprecation_warning__ = '[3.20] %(cls)s is deprecated, use Connection instead'
--- a/toolsutils.py	Wed Sep 16 11:28:07 2015 +0200
+++ b/toolsutils.py	Wed Sep 16 13:57:21 2015 +0200
@@ -38,6 +38,8 @@
     def symlink(*args):
         raise NotImplementedError
 
+from six import add_metaclass
+
 from logilab.common.clcommands import Command as BaseCommand
 from logilab.common.shellutils import ASK
 
@@ -210,12 +212,13 @@
         return cls
 
 
+@add_metaclass(metacmdhandler)
 class CommandHandler(object):
     """configuration specific helper for cubicweb-ctl commands"""
-    __metaclass__ = metacmdhandler
     def __init__(self, config):
         self.config = config
 
+
 class Command(BaseCommand):
     """base class for cubicweb-ctl commands"""
 
--- a/web/box.py	Wed Sep 16 11:28:07 2015 +0200
+++ b/web/box.py	Wed Sep 16 13:57:21 2015 +0200
@@ -20,6 +20,8 @@
 __docformat__ = "restructuredtext en"
 from cubicweb import _
 
+from six import add_metaclass
+
 from logilab.mtconverter import xml_escape
 from logilab.common.deprecation import class_deprecated, class_renamed
 
@@ -53,6 +55,7 @@
 
 # old box system, deprecated ###################################################
 
+@add_metaclass(class_deprecated)
 class BoxTemplate(View):
     """base template for boxes, usually a (contextual) list of possible
     actions. Various classes attributes may be used to control the box
@@ -66,7 +69,6 @@
 
         box.render(self.w)
     """
-    __metaclass__ = class_deprecated
     __deprecation_warning__ = '[3.10] *BoxTemplate classes are deprecated, use *CtxComponent instead (%(cls)s)'
 
     __registry__ = 'ctxcomponents'
--- a/web/component.py	Wed Sep 16 11:28:07 2015 +0200
+++ b/web/component.py	Wed Sep 16 13:57:21 2015 +0200
@@ -24,6 +24,8 @@
 
 from warnings import warn
 
+from six import add_metaclass
+
 from logilab.common.deprecation import class_deprecated, class_renamed, deprecated
 from logilab.mtconverter import xml_escape
 
@@ -677,6 +679,7 @@
 
 # old contextual components, deprecated ########################################
 
+@add_metaclass(class_deprecated)
 class EntityVComponent(Component):
     """abstract base class for additinal components displayed in content
     headers and footer according to:
@@ -687,7 +690,6 @@
     it should be configured using .accepts, .etype, .rtype, .target and
     .context class attributes
     """
-    __metaclass__ = class_deprecated
     __deprecation_warning__ = '[3.10] *VComponent classes are deprecated, use *CtxComponent instead (%(cls)s)'
 
     __registry__ = 'ctxcomponents'
--- a/web/form.py	Wed Sep 16 11:28:07 2015 +0200
+++ b/web/form.py	Wed Sep 16 13:57:21 2015 +0200
@@ -20,6 +20,8 @@
 
 from warnings import warn
 
+from six import add_metaclass
+
 from logilab.common.decorators import iclassmethod
 from logilab.common.deprecation import deprecated
 
@@ -74,8 +76,8 @@
     found
     """
 
+@add_metaclass(metafieldsform)
 class Form(AppObject):
-    __metaclass__ = metafieldsform
     __registry__ = 'forms'
 
     parent_form = None
--- a/web/htmlwidgets.py	Wed Sep 16 11:28:07 2015 +0200
+++ b/web/htmlwidgets.py	Wed Sep 16 13:57:21 2015 +0200
@@ -24,6 +24,7 @@
 import random
 from math import floor
 
+from six import add_metaclass
 from six.moves import range
 
 from logilab.mtconverter import xml_escape
@@ -117,9 +118,9 @@
         self.w(u'</div>')
 
 
+@add_metaclass(class_deprecated)
 class SideBoxWidget(BoxWidget):
     """default CubicWeb's sidebox widget"""
-    __metaclass__ = class_deprecated
     __deprecation_warning__ = '[3.10] class %(cls)s is deprecated'
 
     title_class = u'sideBoxTitle'
@@ -209,9 +210,9 @@
         self.w(u'</ul></div></div>')
 
 
+@add_metaclass(class_deprecated)
 class BoxField(HTMLWidget):
     """couples label / value meant to be displayed in a box"""
-    __metaclass__ = class_deprecated
     __deprecation_warning__ = '[3.10] class %(cls)s is deprecated'
     def __init__(self, label, value):
         self.label = label
@@ -222,18 +223,19 @@
                u'<span class="value">%s</span></div></li>'
                % (self.label, self.value))
 
+
+@add_metaclass(class_deprecated)
 class BoxSeparator(HTMLWidget):
     """a menu separator"""
-    __metaclass__ = class_deprecated
     __deprecation_warning__ = '[3.10] class %(cls)s is deprecated'
 
     def _render(self):
         self.w(u'</ul><hr class="boxSeparator"/><ul>')
 
 
+@add_metaclass(class_deprecated)
 class BoxLink(HTMLWidget):
     """a link in a box"""
-    __metaclass__ = class_deprecated
     __deprecation_warning__ = '[3.10] class %(cls)s is deprecated'
     def __init__(self, href, label, _class='', title='', ident='', escape=False):
         self.href = href
@@ -254,9 +256,9 @@
             self.w(u'<li class="%s">%s</li>\n' % (self._class, link))
 
 
+@add_metaclass(class_deprecated)
 class BoxHtml(HTMLWidget):
     """a form in a box"""
-    __metaclass__ = class_deprecated
     __deprecation_warning__ = '[3.10] class %(cls)s is deprecated'
     def __init__(self, rawhtml):
         self.rawhtml = rawhtml
--- a/web/uihelper.py	Wed Sep 16 11:28:07 2015 +0200
+++ b/web/uihelper.py	Wed Sep 16 13:57:21 2015 +0200
@@ -45,6 +45,7 @@
 """
 __docformat__ = "restructuredtext en"
 
+from six import add_metaclass
 
 from logilab.common.deprecation import deprecated
 from cubicweb.web.views import uicfg
@@ -93,6 +94,7 @@
         super(meta_formconfig, cls).__init__(name, bases, classdict)
 
 
+@add_metaclass(meta_formconfig)
 class FormConfig:
     """helper base class to define uicfg rules on a given entity type.
 
@@ -162,7 +164,6 @@
       inlined = ('use_email',)
 
     """
-    __metaclass__ = meta_formconfig
     formtype = 'main'
     etype = None # must be defined in concrete subclasses
     hidden = ()
--- a/web/views/__init__.py	Wed Sep 16 11:28:07 2015 +0200
+++ b/web/views/__init__.py	Wed Sep 16 13:57:21 2015 +0200
@@ -23,6 +23,8 @@
 import sys
 import tempfile
 
+from six import add_metaclass
+
 from rql import nodes
 from logilab.mtconverter import xml_escape
 from logilab.common.deprecation import class_deprecated
@@ -127,8 +129,8 @@
 
 
 
+@add_metaclass(class_deprecated)
 class TmpFileViewMixin(object):
-    __metaclass__ = class_deprecated
     __deprecation_warning__ = '[3.18] %(cls)s is deprecated'
     binary = True
     content_type = 'application/octet-stream'
--- a/web/views/boxes.py	Wed Sep 16 11:28:07 2015 +0200
+++ b/web/views/boxes.py	Wed Sep 16 13:57:21 2015 +0200
@@ -30,6 +30,8 @@
 
 from warnings import warn
 
+from six import add_metaclass
+
 from logilab.mtconverter import xml_escape
 from logilab.common.deprecation import class_deprecated
 
@@ -231,9 +233,9 @@
 
  # helper classes ##############################################################
 
+@add_metaclass(class_deprecated)
 class SideBoxView(EntityView):
     """helper view class to display some entities in a sidebox"""
-    __metaclass__ = class_deprecated
     __deprecation_warning__ = '[3.10] SideBoxView is deprecated, use RsetBox instead (%(cls)s)'
 
     __regid__ = 'sidebox'
--- a/web/views/plots.py	Wed Sep 16 11:28:07 2015 +0200
+++ b/web/views/plots.py	Wed Sep 16 13:57:21 2015 +0200
@@ -20,6 +20,7 @@
 __docformat__ = "restructuredtext en"
 from cubicweb import _
 
+from six import add_metaclass
 from six.moves import range
 
 from logilab.common.date import datetime2ticks
@@ -85,9 +86,10 @@
     def _render(self, *args, **kwargs):
         raise NotImplementedError
 
+
+@add_metaclass(class_deprecated)
 class FlotPlotWidget(PlotWidget):
     """PlotRenderer widget using Flot"""
-    __metaclass__ = class_deprecated
     __deprecation_warning__ = '[3.14] cubicweb.web.views.plots module is deprecated, use the jqplot cube instead'
     onload = u"""
 var fig = jQuery('#%(figid)s');
@@ -139,8 +141,8 @@
                                      'dateformat': '"%s"' % fmt})
 
 
+@add_metaclass(class_deprecated)
 class PlotView(baseviews.AnyRsetView):
-    __metaclass__ = class_deprecated
     __deprecation_warning__ = '[3.14] cubicweb.web.views.plots module is deprecated, use the jqplot cube instead'
     __regid__ = 'plot'
     title = _('generic plot')
--- a/web/views/tableview.py	Wed Sep 16 11:28:07 2015 +0200
+++ b/web/views/tableview.py	Wed Sep 16 13:57:21 2015 +0200
@@ -67,7 +67,7 @@
 from copy import copy
 from types import MethodType
 
-from six import string_types
+from six import string_types, add_metaclass
 from six.moves import range
 
 from logilab.mtconverter import xml_escape
@@ -921,13 +921,13 @@
 ################################################################################
 
 
+@add_metaclass(class_deprecated)
 class TableView(AnyRsetView):
     """The table view accepts any non-empty rset. It uses introspection on the
     result set to compute column names and the proper way to display the cells.
 
     It is however highly configurable and accepts a wealth of options.
     """
-    __metaclass__ = class_deprecated
     __deprecation_warning__ = '[3.14] %(cls)s is deprecated'
     __regid__ = 'table'
     title = _('table')
@@ -1187,8 +1187,8 @@
     title = _('editable-table')
 
 
+@add_metaclass(class_deprecated)
 class CellView(EntityView):
-    __metaclass__ = class_deprecated
     __deprecation_warning__ = '[3.14] %(cls)s is deprecated'
     __regid__ = 'cell'
     __select__ = nonempty_rset()
@@ -1274,6 +1274,7 @@
     finalview = 'editable-final'
 
 
+@add_metaclass(class_deprecated)
 class EntityAttributesTableView(EntityView):
     """This table displays entity attributes in a table and allow to set a
     specific method to help building cell content for each attribute as well as
@@ -1285,7 +1286,6 @@
     Table will render column header using the method header_for_COLNAME if
     defined otherwise COLNAME will be used.
     """
-    __metaclass__ = class_deprecated
     __deprecation_warning__ = '[3.14] %(cls)s is deprecated'
     __abstract__ = True
     columns = ()
--- a/web/views/urlrewrite.py	Wed Sep 16 11:28:07 2015 +0200
+++ b/web/views/urlrewrite.py	Wed Sep 16 13:57:21 2015 +0200
@@ -19,7 +19,7 @@
 
 import re
 
-from six import string_types
+from six import string_types, add_metaclass
 
 from cubicweb.uilib import domid
 from cubicweb.appobject import AppObject
@@ -53,6 +53,7 @@
         return super(metarewriter, mcs).__new__(mcs, name, bases, classdict)
 
 
+@add_metaclass(metarewriter)
 class URLRewriter(AppObject):
     """Base class for URL rewriters.
 
@@ -66,7 +67,6 @@
     should be tried first. The higher the priority is, the earlier the
     rewriter will be tried.
     """
-    __metaclass__ = metarewriter
     __registry__ = 'urlrewriting'
     __abstract__ = True
     priority = 1
--- a/web/views/workflow.py	Wed Sep 16 11:28:07 2015 +0200
+++ b/web/views/workflow.py	Wed Sep 16 13:57:21 2015 +0200
@@ -27,6 +27,8 @@
 import os
 from warnings import warn
 
+from six import add_metaclass
+
 from logilab.mtconverter import xml_escape
 from logilab.common.graph import escape
 from logilab.common.deprecation import class_deprecated
@@ -429,8 +431,8 @@
         return WorkflowDotPropsHandler(self._cw)
 
 
+@add_metaclass(class_deprecated)
 class TmpPngView(TmpFileViewMixin, EntityView):
-    __metaclass__ = class_deprecated
     __deprecation_warning__ = '[3.18] %(cls)s is deprecated'
     __regid__ = 'tmppng'
     __select__ = match_form_params('tmpfile')