selectors.py
changeset 4737 64143d458495
parent 4719 aaed3f813ef8
child 4833 41a78fb4107c
equal deleted inserted replaced
4622:790181bfd19c 4737:64143d458495
    41 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
    41 :license: GNU Lesser General Public License, v2.1 - http://www.gnu.org/licenses
    42 """
    42 """
    43 __docformat__ = "restructuredtext en"
    43 __docformat__ = "restructuredtext en"
    44 
    44 
    45 import logging
    45 import logging
    46 from warnings import warn, filterwarnings
    46 from warnings import warn
    47 
    47 
    48 from logilab.common.deprecation import class_renamed
    48 from logilab.common.deprecation import class_renamed
    49 from logilab.common.compat import all, any
    49 from logilab.common.compat import all, any
    50 from logilab.common.interface import implements as implements_iface
    50 from logilab.common.interface import implements as implements_iface
    51 
    51 
    52 from yams import BASE_TYPES
    52 from yams import BASE_TYPES
    53 
    53 
    54 from cubicweb import (Unauthorized, NoSelectableObject, NotAnEntity,
    54 from cubicweb import Unauthorized, NoSelectableObject, NotAnEntity, role
    55                       role, typed_eid)
       
    56 # even if not used, let yes here so it's importable through this module
    55 # even if not used, let yes here so it's importable through this module
    57 from cubicweb.appobject import Selector, objectify_selector, yes
    56 from cubicweb.appobject import Selector, objectify_selector, yes
    58 from cubicweb.vregistry import class_regid
    57 from cubicweb.vregistry import class_regid
    59 from cubicweb.cwconfig import CubicWebConfiguration
    58 from cubicweb.cwconfig import CubicWebConfiguration
    60 from cubicweb.schema import split_expression
    59 from cubicweb.schema import split_expression
   161                            ','.join(str(s) for s in self.expected_ifaces))
   160                            ','.join(str(s) for s in self.expected_ifaces))
   162 
   161 
   163     def score_interfaces(self, req, cls_or_inst, cls):
   162     def score_interfaces(self, req, cls_or_inst, cls):
   164         score = 0
   163         score = 0
   165         etypesreg = req.vreg['etypes']
   164         etypesreg = req.vreg['etypes']
   166         eschema = cls_or_inst.e_schema
       
   167         for iface in self.expected_ifaces:
   165         for iface in self.expected_ifaces:
   168             if isinstance(iface, basestring):
   166             if isinstance(iface, basestring):
   169                 # entity type
   167                 # entity type
   170                 try:
   168                 try:
   171                     iface = etypesreg.etype_class(iface)
   169                     iface = etypesreg.etype_class(iface)
   525     """
   523     """
   526     def score(self, cls, req, etype):
   524     def score(self, cls, req, etype):
   527         if etype in BASE_TYPES:
   525         if etype in BASE_TYPES:
   528             return 0
   526             return 0
   529         return 1
   527         return 1
       
   528 
       
   529     def score_class(self, eclass, req):
       
   530         return 1 # necessarily true if we're there
   530 
   531 
   531 
   532 
   532 class implements(ImplementsMixIn, EClassSelector):
   533 class implements(ImplementsMixIn, EClassSelector):
   533     """Return non-zero score for entity that are of the given type(s) or
   534     """Return non-zero score for entity that are of the given type(s) or
   534     implements at least one of the given interface(s). If multiple arguments are
   535     implements at least one of the given interface(s). If multiple arguments are