appobject.py
author Sylvain Thénault <sylvain.thenault@logilab.fr>
Thu, 22 Sep 2011 16:12:23 +0200
changeset 7827 9bbf83f68bcc
parent 7387 d240cff2d8ba
child 7815 2a164a9cf81c
permissions -rw-r--r--
[entity] upgrade fetch_[unrelated_]order to benefit from changes introduced in 3.14 (closes #1942758) of rql generation parts of the ORM now based on rql syntax tree. This allows more powerful and flexible sort control by giving them the syntax tree instead of manipulating string. Also: * prefix new methods by 'cw_' * fix cases that currently crash in 3.14 due to the refactoring
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5315
diff changeset
     1
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5315
diff changeset
     2
# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5315
diff changeset
     3
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5315
diff changeset
     4
# This file is part of CubicWeb.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5315
diff changeset
     5
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5315
diff changeset
     6
# CubicWeb is free software: you can redistribute it and/or modify it under the
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5315
diff changeset
     7
# terms of the GNU Lesser General Public License as published by the Free
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5315
diff changeset
     8
# Software Foundation, either version 2.1 of the License, or (at your option)
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5315
diff changeset
     9
# any later version.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5315
diff changeset
    10
#
5424
8ecbcbff9777 replace logilab-common by CubicWeb in disclaimer
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5421
diff changeset
    11
# CubicWeb is distributed in the hope that it will be useful, but WITHOUT
5421
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5315
diff changeset
    12
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5315
diff changeset
    13
# FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5315
diff changeset
    14
# details.
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5315
diff changeset
    15
#
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5315
diff changeset
    16
# You should have received a copy of the GNU Lesser General Public License along
8167de96c523 proper licensing information (LGPL-2.1). Hope I get it right this time.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5315
diff changeset
    17
# with CubicWeb.  If not, see <http://www.gnu.org/licenses/>.
5147
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
    18
"""
5306
763319a51e72 [doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5147
diff changeset
    19
.. _appobject:
763319a51e72 [doc/book] some fixes for vregistry, selectors & appobjects
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5147
diff changeset
    20
5147
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
    21
The `AppObject` class
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
    22
---------------------
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    23
5147
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
    24
The AppObject class is the base class for all dynamically loaded objects
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
    25
(application objects) accessible through the vregistry.
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
    26
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
    27
We can find a certain number of attributes and methods defined in this class and
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
    28
common to all the application objects.
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
    29
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
    30
.. autoclass:: AppObject
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    31
"""
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    32
__docformat__ = "restructuredtext en"
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    33
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
    34
import types
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
    35
from logging import getLogger
3390
ae50bd4b1631 [appobject] detect old-style property_defs and emit a deprectaion warning
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2968
diff changeset
    36
from warnings import warn
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
    37
2613
5e19c2bb370e R [all] logilab.common 0.44 provides only deprecated
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2476
diff changeset
    38
from logilab.common.deprecation import deprecated
5093
8d073d2e089d [optimization] improve massive write performance by optimizing hooks selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5018
diff changeset
    39
from logilab.common.decorators import classproperty
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
    40
from logilab.common.logging_ext import set_log_methods
447
0e52d72104a6 pylint fixes
sylvain.thenault@logilab.fr
parents: 237
diff changeset
    41
5564
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    42
from cubicweb.cwconfig import CubicWebConfiguration
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    43
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    44
def class_regid(cls):
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    45
    """returns a unique identifier for an appobject class"""
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    46
    if 'id' in cls.__dict__:
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    47
        warn('[3.6] %s.%s: id is deprecated, use __regid__'
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    48
             % (cls.__module__, cls.__name__), DeprecationWarning)
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    49
        cls.__regid__ = cls.id
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    50
    if hasattr(cls, 'id') and not isinstance(cls.id, property):
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    51
        return cls.id
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    52
    return cls.__regid__
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    53
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    54
# helpers for debugging selectors
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    55
TRACED_OIDS = None
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    56
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    57
def _trace_selector(cls, selector, args, ret):
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    58
    # /!\ lltrace decorates pure function or __call__ method, this
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    59
    #     means argument order may be different
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    60
    if isinstance(cls, Selector):
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    61
        selname = str(cls)
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    62
        vobj = args[0]
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    63
    else:
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    64
        selname = selector.__name__
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    65
        vobj = cls
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    66
    if TRACED_OIDS == 'all' or class_regid(vobj) in TRACED_OIDS:
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    67
        #SELECTOR_LOGGER.warning('selector %s returned %s for %s', selname, ret, cls)
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    68
        print '%s -> %s for %s(%s)' % (selname, ret, vobj, vobj.__regid__)
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    69
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    70
def lltrace(selector):
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    71
    """use this decorator on your selectors so the becomes traceable with
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    72
    :class:`traced_selection`
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    73
    """
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    74
    # don't wrap selectors if not in development mode
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    75
    if CubicWebConfiguration.mode == 'system': # XXX config.debug
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    76
        return selector
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    77
    def traced(cls, *args, **kwargs):
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    78
        ret = selector(cls, *args, **kwargs)
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    79
        if TRACED_OIDS is not None:
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    80
            _trace_selector(cls, selector, args, ret)
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    81
        return ret
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    82
    traced.__name__ = selector.__name__
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    83
    traced.__doc__ = selector.__doc__
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    84
    return traced
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    85
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    86
class traced_selection(object):
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    87
    """
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    88
    Typical usage is :
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    89
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    90
    .. sourcecode:: python
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    91
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    92
        >>> from cubicweb.selectors import traced_selection
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    93
        >>> with traced_selection():
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    94
        ...     # some code in which you want to debug selectors
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    95
        ...     # for all objects
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    96
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    97
    Don't forget the 'from __future__ import with_statement' at the module top-level
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    98
    if you're using python prior to 2.6.
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
    99
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   100
    This will yield lines like this in the logs::
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   101
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   102
        selector one_line_rset returned 0 for <class 'cubicweb.web.views.basecomponents.WFHistoryVComponent'>
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   103
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   104
    You can also give to :class:`traced_selection` the identifiers of objects on
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   105
    which you want to debug selection ('oid1' and 'oid2' in the example above).
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   106
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   107
    .. sourcecode:: python
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   108
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   109
        >>> with traced_selection( ('regid1', 'regid2') ):
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   110
        ...     # some code in which you want to debug selectors
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   111
        ...     # for objects with __regid__ 'regid1' and 'regid2'
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   112
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   113
    A potentially usefull point to set up such a tracing function is
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   114
    the `cubicweb.vregistry.Registry.select` method body.
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   115
    """
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   116
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   117
    def __init__(self, traced='all'):
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   118
        self.traced = traced
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   119
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   120
    def __enter__(self):
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   121
        global TRACED_OIDS
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   122
        TRACED_OIDS = self.traced
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   123
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   124
    def __exit__(self, exctype, exc, traceback):
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   125
        global TRACED_OIDS
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   126
        TRACED_OIDS = None
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   127
        return traceback is None
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   128
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   129
# selector base classes and operations ########################################
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   130
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   131
def objectify_selector(selector_func):
5147
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   132
    """Most of the time, a simple score function is enough to build a selector.
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   133
    The :func:`objectify_selector` decorator turn it into a proper selector
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   134
    class::
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   135
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   136
        @objectify_selector
5315
2c23d2fd3b51 fix docstring
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5306
diff changeset
   137
        def one(cls, req, rset=None, **kwargs):
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   138
            return 1
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   139
5147
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   140
        class MyView(View):
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   141
            __select__ = View.__select__ & one()
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   142
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   143
    """
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   144
    return type(selector_func.__name__, (Selector,),
4458
6151849f41e0 copy back __doc__ for proper sphinx doc generation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   145
                {'__doc__': selector_func.__doc__,
6151849f41e0 copy back __doc__ for proper sphinx doc generation
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4252
diff changeset
   146
                 '__call__': lambda self, *a, **kw: selector_func(*a, **kw)})
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   147
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   148
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   149
def _instantiate_selector(selector):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   150
    """ensures `selector` is a `Selector` instance
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   151
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   152
    NOTE: This should only be used locally in build___select__()
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   153
    XXX: then, why not do it ??
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   154
    """
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   155
    if isinstance(selector, types.FunctionType):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   156
        return objectify_selector(selector)()
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   157
    if isinstance(selector, type) and issubclass(selector, Selector):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   158
        return selector()
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   159
    return selector
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   160
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   161
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   162
class Selector(object):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   163
    """base class for selector classes providing implementation
5147
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   164
    for operators ``&``, ``|`` and  ``~``
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   165
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   166
    This class is only here to give access to binary operators, the
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   167
    selector logic itself should be implemented in the __call__ method
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   168
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   169
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   170
    a selector is called to help choosing the correct object for a
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   171
    particular context by returning a score (`int`) telling how well
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   172
    the class given as first argument apply to the given context.
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   173
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   174
    0 score means that the class doesn't apply.
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   175
    """
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   176
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   177
    @property
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   178
    def func_name(self):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   179
        # backward compatibility
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   180
        return self.__class__.__name__
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   181
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   182
    def search_selector(self, selector):
7387
d240cff2d8ba [hooks selection optimization] prune hooks when multiple entities are concerned by a hm.call_hooks() (closes: #1672022)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7083
diff changeset
   183
        """search for the given selector, selector instance or tuple of
d240cff2d8ba [hooks selection optimization] prune hooks when multiple entities are concerned by a hm.call_hooks() (closes: #1672022)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7083
diff changeset
   184
        selectors in the selectors tree. Return None if not found.
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   185
        """
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   186
        if self is selector:
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   187
            return self
7387
d240cff2d8ba [hooks selection optimization] prune hooks when multiple entities are concerned by a hm.call_hooks() (closes: #1672022)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7083
diff changeset
   188
        if (isinstance(selector, type) or isinstance(selector, tuple)) and \
d240cff2d8ba [hooks selection optimization] prune hooks when multiple entities are concerned by a hm.call_hooks() (closes: #1672022)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7083
diff changeset
   189
               isinstance(self, selector):
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   190
            return self
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   191
        return None
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   192
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   193
    def __str__(self):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   194
        return self.__class__.__name__
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   195
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   196
    def __and__(self, other):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   197
        return AndSelector(self, other)
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   198
    def __rand__(self, other):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   199
        return AndSelector(other, self)
2833
9aa47a3c0dfe [selectors] explicity fail on inplace and/or
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2829
diff changeset
   200
    def __iand__(self, other):
5373
24a873060692 [selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5315
diff changeset
   201
        return AndSelector(self, other)
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   202
    def __or__(self, other):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   203
        return OrSelector(self, other)
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   204
    def __ror__(self, other):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   205
        return OrSelector(other, self)
2833
9aa47a3c0dfe [selectors] explicity fail on inplace and/or
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2829
diff changeset
   206
    def __ior__(self, other):
5373
24a873060692 [selector] allow inplace operator in selector computation
Julien Jehannet <julien.jehannet@logilab.fr>
parents: 5315
diff changeset
   207
        return OrSelector(self, other)
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   208
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   209
    def __invert__(self):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   210
        return NotSelector(self)
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   211
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   212
    # XXX (function | function) or (function & function) not managed yet
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   213
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   214
    def __call__(self, cls, *args, **kwargs):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   215
        return NotImplementedError("selector %s must implement its logic "
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   216
                                   "in its __call__ method" % self.__class__)
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   217
6870
658039c5eeac [selectors] minor: use similar __repr__ implementation for selector instances
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5901
diff changeset
   218
    def __repr__(self):
658039c5eeac [selectors] minor: use similar __repr__ implementation for selector instances
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5901
diff changeset
   219
        return u'<Selector %s at %x>' % (self.__class__.__name__, id(self))
658039c5eeac [selectors] minor: use similar __repr__ implementation for selector instances
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5901
diff changeset
   220
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   221
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   222
class MultiSelector(Selector):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   223
    """base class for compound selector classes"""
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   224
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   225
    def __init__(self, *selectors):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   226
        self.selectors = self.merge_selectors(selectors)
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   227
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   228
    def __str__(self):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   229
        return '%s(%s)' % (self.__class__.__name__,
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   230
                           ','.join(str(s) for s in self.selectors))
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   231
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   232
    @classmethod
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   233
    def merge_selectors(cls, selectors):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   234
        """deal with selector instanciation when necessary and merge
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   235
        multi-selectors if possible:
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   236
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   237
        AndSelector(AndSelector(sel1, sel2), AndSelector(sel3, sel4))
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   238
        ==> AndSelector(sel1, sel2, sel3, sel4)
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   239
        """
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   240
        merged_selectors = []
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   241
        for selector in selectors:
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   242
            try:
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   243
                selector = _instantiate_selector(selector)
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   244
            except:
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   245
                pass
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   246
            #assert isinstance(selector, Selector), selector
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   247
            if isinstance(selector, cls):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   248
                merged_selectors += selector.selectors
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   249
            else:
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   250
                merged_selectors.append(selector)
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   251
        return merged_selectors
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   252
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   253
    def search_selector(self, selector):
7387
d240cff2d8ba [hooks selection optimization] prune hooks when multiple entities are concerned by a hm.call_hooks() (closes: #1672022)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7083
diff changeset
   254
        """search for the given selector or selector instance (or tuple of
d240cff2d8ba [hooks selection optimization] prune hooks when multiple entities are concerned by a hm.call_hooks() (closes: #1672022)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7083
diff changeset
   255
        selectors) in the selectors tree. Return None if not found
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   256
        """
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   257
        for childselector in self.selectors:
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   258
            if childselector is selector:
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   259
                return childselector
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   260
            found = childselector.search_selector(selector)
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   261
            if found is not None:
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   262
                return found
7387
d240cff2d8ba [hooks selection optimization] prune hooks when multiple entities are concerned by a hm.call_hooks() (closes: #1672022)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7083
diff changeset
   263
        # if not found in children, maybe we are looking for self?
d240cff2d8ba [hooks selection optimization] prune hooks when multiple entities are concerned by a hm.call_hooks() (closes: #1672022)
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 7083
diff changeset
   264
        return super(MultiSelector, self).search_selector(selector)
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   265
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   266
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   267
class AndSelector(MultiSelector):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   268
    """and-chained selectors (formerly known as chainall)"""
5564
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   269
    @lltrace
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   270
    def __call__(self, cls, *args, **kwargs):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   271
        score = 0
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   272
        for selector in self.selectors:
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   273
            partscore = selector(cls, *args, **kwargs)
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   274
            if not partscore:
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   275
                return 0
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   276
            score += partscore
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   277
        return score
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   278
1524
1d7575f5deaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   279
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   280
class OrSelector(MultiSelector):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   281
    """or-chained selectors (formerly known as chainfirst)"""
5564
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   282
    @lltrace
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   283
    def __call__(self, cls, *args, **kwargs):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   284
        for selector in self.selectors:
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   285
            partscore = selector(cls, *args, **kwargs)
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   286
            if partscore:
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   287
                return partscore
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   288
        return 0
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   289
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   290
class NotSelector(Selector):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   291
    """negation selector"""
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   292
    def __init__(self, selector):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   293
        self.selector = selector
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   294
5564
d13830a2adfd [selectors] move lltrace decorator and traced_selection cm to appobject module so we can apply lltrace to And/Or/Not selectors, fixing #662565
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   295
    @lltrace
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   296
    def __call__(self, cls, *args, **kwargs):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   297
        score = self.selector(cls, *args, **kwargs)
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   298
        return int(not score)
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   299
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   300
    def __str__(self):
5899
11cecbaeb731 imported patch selstrfix.diff
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5426
diff changeset
   301
        return 'NOT(%s)' % self.selector
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   302
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   303
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   304
class yes(Selector):
4462
c57c8176b8c2 reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4459
diff changeset
   305
    """Return the score given as parameter, with a default score of 0.5 so any
c57c8176b8c2 reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4459
diff changeset
   306
    other selector take precedence.
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   307
4462
c57c8176b8c2 reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4459
diff changeset
   308
    Usually used for appobjects which can be selected whatever the context, or
c57c8176b8c2 reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4459
diff changeset
   309
    also sometimes to add arbitrary points to a score.
c57c8176b8c2 reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4459
diff changeset
   310
c57c8176b8c2 reorganize, cleanup and properly document base selectors. Kill the may_add_relation selector.
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4459
diff changeset
   311
    Take care, `yes(0)` could be named 'no'...
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   312
    """
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   313
    def __init__(self, score=0.5):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   314
        self.score = score
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   315
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   316
    def __call__(self, *args, **kwargs):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   317
        return self.score
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   318
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   319
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   320
# the base class for all appobjects ############################################
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   321
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   322
class AppObject(object):
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   323
    """This is the base class for CubicWeb application objects which are
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   324
    selected according to a context (usually at least a request and a result
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   325
    set).
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   326
5147
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   327
    The following attributes should be set on concret appobject classes:
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   328
5147
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   329
    :attr:`__registry__`
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   330
      name of the registry for this object (string like 'views',
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   331
      'templates'...)
5147
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   332
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   333
    :attr:`__regid__`
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   334
      object's identifier in the registry (string like 'main',
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   335
      'primary', 'folder_box')
5147
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   336
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   337
    :attr:`__select__`
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   338
      class'selector
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   339
5147
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   340
    Moreover, the `__abstract__` attribute may be set to True to indicate that a
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   341
    class is abstract and should not be registered.
1524
1d7575f5deaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   342
2825
87ac03aed941 doc update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2822
diff changeset
   343
    At selection time, the following attributes are set on the instance:
87ac03aed941 doc update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2822
diff changeset
   344
5147
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   345
    :attr:`_cw`
2825
87ac03aed941 doc update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2822
diff changeset
   346
      current request
5147
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   347
    :attr:`cw_extra_kwargs`
2825
87ac03aed941 doc update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2822
diff changeset
   348
      other received arguments
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   349
5147
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   350
    And also the following, only if `rset` is found in arguments (in which case
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   351
    rset/row/col will be removed from `cwextra_kwargs`):
2825
87ac03aed941 doc update
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2822
diff changeset
   352
5147
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   353
    :attr:`cw_rset`
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   354
      context result set or None
5147
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   355
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   356
    :attr:`cw_row`
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   357
      if a result set is set and the context is about a particular cell in the
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   358
      result set, and not the result set as a whole, specify the row number we
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   359
      are interested in, else None
5147
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   360
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   361
    :attr:`cw_col`
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   362
      if a result set is set and the context is about a particular cell in the
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   363
      result set, and not the result set as a whole, specify the col number we
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   364
      are interested in, else None
5147
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   365
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   366
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   367
    .. Note::
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   368
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   369
      * do not inherit directly from this class but from a more specific class
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   370
        such as `AnyEntity`, `EntityView`, `AnyRsetView`, `Action`...
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   371
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   372
      * to be recordable, a subclass has to define its registry (attribute
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   373
        `__registry__`) and its identifier (attribute `__regid__`). Usually
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   374
        you don't have to take care of the registry since it's set by the base
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   375
        class, only the identifier `id`
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   376
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   377
      * application objects are designed to be loaded by the vregistry and
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   378
        should be accessed through it, not by direct instantiation, besides
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   379
        to use it as base classe.
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   380
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   381
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   382
      * When we inherit from `AppObject` (even not directly), you *always* have
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   383
        to use **super()** to get the methods and attributes of the superclasses,
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   384
        and not use the class identifier.
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   385
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   386
        For example, instead of writting::
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   387
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   388
          class Truc(PrimaryView):
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   389
              def f(self, arg1):
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   390
                  PrimaryView.f(self, arg1)
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   391
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   392
        You must write::
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   393
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   394
          class Truc(PrimaryView):
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   395
              def f(self, arg1):
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   396
                  super(Truc, self).f(arg1)
70181998897f more / cleaner / in code documentation of vreg, selectors and appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5093
diff changeset
   397
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   398
    """
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   399
    __registry__ = None
3376
f5c69485381f [appobjects] use __regid__ instead of __id__, more explicit
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2968
diff changeset
   400
    __regid__ = None
805
6e99feeba28b set a default selector on base app objects class
sylvain.thenault@logilab.fr
parents: 802
diff changeset
   401
    __select__ = yes()
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   402
5093
8d073d2e089d [optimization] improve massive write performance by optimizing hooks selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5018
diff changeset
   403
    @classproperty
8d073d2e089d [optimization] improve massive write performance by optimizing hooks selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5018
diff changeset
   404
    def __registries__(cls):
8d073d2e089d [optimization] improve massive write performance by optimizing hooks selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5018
diff changeset
   405
        if cls.__registry__ is None:
8d073d2e089d [optimization] improve massive write performance by optimizing hooks selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5018
diff changeset
   406
            return ()
8d073d2e089d [optimization] improve massive write performance by optimizing hooks selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5018
diff changeset
   407
        return (cls.__registry__,)
8d073d2e089d [optimization] improve massive write performance by optimizing hooks selection
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 5018
diff changeset
   408
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   409
    @classmethod
2820
66b31686d92b rename registered to __registered__
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2819
diff changeset
   410
    def __registered__(cls, registry):
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   411
        """called by the registry when the appobject has been registered.
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   412
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   413
        It must return the object that will be actually registered (this may be
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   414
        the right hook to create an instance for example). By default the
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   415
        appobject is returned without any transformation.
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   416
        """
3678
29f74716fd70 add note
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3453
diff changeset
   417
        try: # XXX < 3.6 bw compat
3390
ae50bd4b1631 [appobject] detect old-style property_defs and emit a deprectaion warning
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2968
diff changeset
   418
            pdefs = cls.property_defs
ae50bd4b1631 [appobject] detect old-style property_defs and emit a deprectaion warning
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2968
diff changeset
   419
        except AttributeError:
ae50bd4b1631 [appobject] detect old-style property_defs and emit a deprectaion warning
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2968
diff changeset
   420
            pdefs = getattr(cls, 'cw_property_defs', {})
ae50bd4b1631 [appobject] detect old-style property_defs and emit a deprectaion warning
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2968
diff changeset
   421
        else:
5018
2f2d9bc6dca4 [appobject] add version number to deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4719
diff changeset
   422
            warn('[3.6] property_defs is deprecated, use cw_property_defs in %s'
3390
ae50bd4b1631 [appobject] detect old-style property_defs and emit a deprectaion warning
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 2968
diff changeset
   423
                 % cls, DeprecationWarning)
2802
2251b4aee54a should still call .items
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2799
diff changeset
   424
        for propid, pdef in pdefs.items():
2799
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2798
diff changeset
   425
            pdef = pdef.copy() # may be shared
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2798
diff changeset
   426
            pdef['default'] = getattr(cls, propid, pdef['default'])
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2798
diff changeset
   427
            pdef['sitewide'] = getattr(cls, 'site_wide', pdef.get('sitewide'))
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2798
diff changeset
   428
            registry.vreg.register_property(cls._cwpropkey(propid), **pdef)
4716
55b6a3262071 fix some pylint detected errors
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4568
diff changeset
   429
        assert callable(cls.__select__), cls
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   430
        return cls
1524
1d7575f5deaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   431
2822
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   432
    def __init__(self, req, **extra):
2656
a93ae0f6c0ad R [base classes] only AppObject remaning, no more AppRsetObject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2650
diff changeset
   433
        super(AppObject, self).__init__()
2847
c2ee28f4d4b1 use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2833
diff changeset
   434
        self._cw = req
2822
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   435
        try:
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   436
            self.cw_rset = extra.pop('rset')
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   437
            self.cw_row = extra.pop('row', None)
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   438
            self.cw_col = extra.pop('col', None)
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   439
        except KeyError:
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   440
            pass
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   441
        self.cw_extra_kwargs = extra
1524
1d7575f5deaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   442
2799
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2798
diff changeset
   443
    # persistent class properties ##############################################
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2798
diff changeset
   444
    #
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2798
diff changeset
   445
    # optional `cw_property_defs` dict on a class defines available persistent
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2798
diff changeset
   446
    # properties for this class:
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2798
diff changeset
   447
    #
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2798
diff changeset
   448
    # * key: id of the property (the actual CWProperty key is build using
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2798
diff changeset
   449
    #        <registry name>.<obj id>.<property id>
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2798
diff changeset
   450
    # * value: tuple (property type, vocabfunc, default value, property description)
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2798
diff changeset
   451
    #         possible types are those used by `logilab.common.configuration`
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   452
    #
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   453
    # notice that when it exists multiple objects with the same id (adaptation,
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   454
    # overriding) only the first encountered definition is considered, so those
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   455
    # objects can't try to have different default values for instance.
2799
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2798
diff changeset
   456
    #
2818
326375561412 propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2811
diff changeset
   457
    # you can then access to a property value using self.cw_propval, where self
326375561412 propagate some api changes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2811
diff changeset
   458
    # is an instance of class
1524
1d7575f5deaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   459
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   460
    @classmethod
2799
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2798
diff changeset
   461
    def _cwpropkey(cls, propid):
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2798
diff changeset
   462
        """return cw property key for the property of the given id for this
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2798
diff changeset
   463
        class
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   464
        """
3399
2b84f4adb6f8 use __regid__ instead of id on appobject classes
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3396
diff changeset
   465
        return '%s.%s.%s' % (cls.__registry__, cls.__regid__, propid)
1524
1d7575f5deaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   466
2799
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2798
diff changeset
   467
    def cw_propval(self, propid):
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2798
diff changeset
   468
        """return cw property value associated to key
1524
1d7575f5deaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   469
2799
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2798
diff changeset
   470
        <cls.__registry__>.<cls.id>.<propid>
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   471
        """
3418
7b49fa7e942d [api] use _cw, cw_row, cw_col, cw_rset etc.
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3399
diff changeset
   472
        return self._cw.property_value(self._cwpropkey(propid))
2799
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2798
diff changeset
   473
2792
135580d15d42 rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2789
diff changeset
   474
    # deprecated ###############################################################
135580d15d42 rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2789
diff changeset
   475
2811
e1f3b8e7f19a fix bw compat properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2804
diff changeset
   476
    @property
4013
f0d1038e5059 .id backward compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3678
diff changeset
   477
    @deprecated('[3.6] use self.__regid__')
f0d1038e5059 .id backward compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3678
diff changeset
   478
    def id(self):
f0d1038e5059 .id backward compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3678
diff changeset
   479
        return self.__regid__
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   480
4013
f0d1038e5059 .id backward compat
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 3678
diff changeset
   481
    @property
2968
0e3460341023 somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2888
diff changeset
   482
    @deprecated('[3.6] use self._cw.vreg')
2811
e1f3b8e7f19a fix bw compat properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2804
diff changeset
   483
    def vreg(self):
2847
c2ee28f4d4b1 use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2833
diff changeset
   484
        return self._cw.vreg
1524
1d7575f5deaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   485
2822
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   486
    @property
2968
0e3460341023 somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2888
diff changeset
   487
    @deprecated('[3.6] use self._cw.vreg.schema')
2822
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   488
    def schema(self):
2847
c2ee28f4d4b1 use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2833
diff changeset
   489
        return self._cw.vreg.schema
2792
135580d15d42 rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2789
diff changeset
   490
2811
e1f3b8e7f19a fix bw compat properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2804
diff changeset
   491
    @property
2968
0e3460341023 somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2888
diff changeset
   492
    @deprecated('[3.6] use self._cw.vreg.config')
2822
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   493
    def config(self):
2847
c2ee28f4d4b1 use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2833
diff changeset
   494
        return self._cw.vreg.config
1524
1d7575f5deaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   495
2822
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   496
    @property
2968
0e3460341023 somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2888
diff changeset
   497
    @deprecated('[3.6] use self._cw')
2822
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   498
    def req(self):
2847
c2ee28f4d4b1 use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2833
diff changeset
   499
        return self._cw
2822
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   500
2968
0e3460341023 somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2888
diff changeset
   501
    @deprecated('[3.6] use self.cw_rset')
2888
5492bafa4f17 add write support for rset to avoid some crash
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2886
diff changeset
   502
    def get_rset(self):
5492bafa4f17 add write support for rset to avoid some crash
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2886
diff changeset
   503
        return self.cw_rset
2968
0e3460341023 somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2888
diff changeset
   504
    @deprecated('[3.6] use self.cw_rset')
2888
5492bafa4f17 add write support for rset to avoid some crash
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2886
diff changeset
   505
    def set_rset(self, rset):
5492bafa4f17 add write support for rset to avoid some crash
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2886
diff changeset
   506
        self.cw_rset = rset
5492bafa4f17 add write support for rset to avoid some crash
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2886
diff changeset
   507
    rset = property(get_rset, set_rset)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   508
2811
e1f3b8e7f19a fix bw compat properties
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2804
diff changeset
   509
    @property
2968
0e3460341023 somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2888
diff changeset
   510
    @deprecated('[3.6] use self.cw_row')
2822
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   511
    def row(self):
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   512
        return self.cw_row
1524
1d7575f5deaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   513
2822
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   514
    @property
2968
0e3460341023 somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2888
diff changeset
   515
    @deprecated('[3.6] use self.cw_col')
2822
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   516
    def col(self):
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   517
        return self.cw_col
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   518
2822
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   519
    @property
2968
0e3460341023 somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2888
diff changeset
   520
    @deprecated('[3.6] use self.cw_extra_kwargs')
2822
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   521
    def extra_kwargs(self):
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   522
        return self.cw_extra_kwargs
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   523
2968
0e3460341023 somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2888
diff changeset
   524
    @deprecated('[3.6] use self._cw.view')
2822
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   525
    def view(self, *args, **kwargs):
2847
c2ee28f4d4b1 use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2833
diff changeset
   526
        return self._cw.view(*args, **kwargs)
2822
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   527
3453
e2572c9ca3ec [deprecation] better deprecation handling on self.varmaker
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3426
diff changeset
   528
    @property
2968
0e3460341023 somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2888
diff changeset
   529
    @deprecated('[3.6] use self._cw.varmaker')
3453
e2572c9ca3ec [deprecation] better deprecation handling on self.varmaker
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3426
diff changeset
   530
    def varmaker(self):
e2572c9ca3ec [deprecation] better deprecation handling on self.varmaker
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3426
diff changeset
   531
        return self._cw.varmaker
2796
14d2c69e12c4 move get_cache to base request
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2795
diff changeset
   532
2968
0e3460341023 somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2888
diff changeset
   533
    @deprecated('[3.6] use self._cw.get_cache')
2822
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   534
    def get_cache(self, cachename):
2847
c2ee28f4d4b1 use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2833
diff changeset
   535
        return self._cw.get_cache(cachename)
2822
f26578339214 deprecate appobject.vreg and rename appobject instance attributes using cw_ prefix
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2821
diff changeset
   536
2968
0e3460341023 somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2888
diff changeset
   537
    @deprecated('[3.6] use self._cw.build_url')
2798
9c650701cb17 stop using controller class attribute, allowing to deprecate appobject.build_url in favor of req.build_url
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2796
diff changeset
   538
    def build_url(self, *args, **kwargs):
2847
c2ee28f4d4b1 use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2833
diff changeset
   539
        return self._cw.build_url(*args, **kwargs)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   540
2968
0e3460341023 somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2888
diff changeset
   541
    @deprecated('[3.6] use self.cw_rset.limited_rql')
2792
135580d15d42 rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2789
diff changeset
   542
    def limited_rql(self):
3426
6ea4a2ff01c9 [api] use cw_*
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3419
diff changeset
   543
        return self.cw_rset.limited_rql()
2792
135580d15d42 rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2789
diff changeset
   544
3419
32cfd0844243 fix deprecation warnings in appobject: display the correct expected replacement
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   545
    @deprecated('[3.6] use self.cw_rset.complete_entity(row,col) instead')
2792
135580d15d42 rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2789
diff changeset
   546
    def complete_entity(self, row, col=0, skip_bytes=True):
3426
6ea4a2ff01c9 [api] use cw_*
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3419
diff changeset
   547
        return self.cw_rset.complete_entity(row, col, skip_bytes)
2792
135580d15d42 rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2789
diff changeset
   548
3419
32cfd0844243 fix deprecation warnings in appobject: display the correct expected replacement
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3418
diff changeset
   549
    @deprecated('[3.6] use self.cw_rset.get_entity(row,col) instead')
2792
135580d15d42 rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2789
diff changeset
   550
    def entity(self, row, col=0):
3426
6ea4a2ff01c9 [api] use cw_*
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents: 3419
diff changeset
   551
        return self.cw_rset.get_entity(row, col)
2792
135580d15d42 rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2789
diff changeset
   552
2968
0e3460341023 somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2888
diff changeset
   553
    @deprecated('[3.6] use self._cw.user_rql_callback')
2792
135580d15d42 rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2789
diff changeset
   554
    def user_rql_callback(self, args, msg=None):
2847
c2ee28f4d4b1 use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2833
diff changeset
   555
        return self._cw.user_rql_callback(args, msg)
2792
135580d15d42 rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2789
diff changeset
   556
2968
0e3460341023 somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2888
diff changeset
   557
    @deprecated('[3.6] use self._cw.user_callback')
2792
135580d15d42 rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2789
diff changeset
   558
    def user_callback(self, cb, args, msg=None, nonify=False):
2847
c2ee28f4d4b1 use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2833
diff changeset
   559
        return self._cw.user_callback(cb, args, msg, nonify)
2792
135580d15d42 rename and move cw.RequestSessionMixIn to cw.req.RequestSessionBase; move some appobjects methods where they actually belong to
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2789
diff changeset
   560
2968
0e3460341023 somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2888
diff changeset
   561
    @deprecated('[3.6] use self._cw.format_date')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   562
    def format_date(self, date, date_format=None, time=False):
2847
c2ee28f4d4b1 use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2833
diff changeset
   563
        return self._cw.format_date(date, date_format, time)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   564
4568
ed35dbe408ae fix typo in deprecation warning
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 4490
diff changeset
   565
    @deprecated('[3.6] use self._cw.format_time')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   566
    def format_time(self, time):
2847
c2ee28f4d4b1 use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2833
diff changeset
   567
        return self._cw.format_time(time)
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   568
2968
0e3460341023 somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2888
diff changeset
   569
    @deprecated('[3.6] use self._cw.format_float')
0
b97547f5f1fa Showtime !
Adrien Di Mascio <Adrien.DiMascio@logilab.fr>
parents:
diff changeset
   570
    def format_float(self, num):
2847
c2ee28f4d4b1 use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2833
diff changeset
   571
        return self._cw.format_float(num)
1524
1d7575f5deaf delete-trailing-whitespaces
sylvain.thenault@logilab.fr
parents: 1398
diff changeset
   572
2968
0e3460341023 somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2888
diff changeset
   573
    @deprecated('[3.6] use self._cw.parse_datetime')
1984
8d571df6012a move parse_datetime on appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   574
    def parse_datetime(self, value, etype='Datetime'):
2847
c2ee28f4d4b1 use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2833
diff changeset
   575
        return self._cw.parse_datetime(value, etype)
1984
8d571df6012a move parse_datetime on appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 1977
diff changeset
   576
2968
0e3460341023 somewhat painful backport of 3.5 branch, should mostly be ok
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2888
diff changeset
   577
    @deprecated('[3.6] use self.cw_propval')
2799
b703639614e7 refactor property handling to avoid name conflicts
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2798
diff changeset
   578
    def propval(self, propid):
2847
c2ee28f4d4b1 use ._cw instead of .cw_req
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2833
diff changeset
   579
        return self._cw.property_value(self._cwpropkey(propid))
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   580
7083
b8e35cde46e9 help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6870
diff changeset
   581
    # these are overridden by set_log_methods below
b8e35cde46e9 help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6870
diff changeset
   582
    # only defining here to prevent pylint from complaining
b8e35cde46e9 help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6870
diff changeset
   583
    info = warning = error = critical = exception = debug = lambda msg,*a,**kw: None
b8e35cde46e9 help pylint by explicitely defining some attributes
Alexandre Fayolle <alexandre.fayolle@logilab.fr>
parents: 6870
diff changeset
   584
2657
de974465d381 [appobject] kill VObject class, move base selector classes to appobject
Sylvain Thénault <sylvain.thenault@logilab.fr>
parents: 2656
diff changeset
   585
set_log_methods(AppObject, getLogger('cubicweb.appobject'))