predicates.py
changeset 10612 84468b90e9c1
parent 10609 e2d8e81bfe68
child 10613 8d9fe02387e3
equal deleted inserted replaced
10611:f4dec0cca9a1 10612:84468b90e9c1
    22 
    22 
    23 import logging
    23 import logging
    24 from warnings import warn
    24 from warnings import warn
    25 from operator import eq
    25 from operator import eq
    26 
    26 
       
    27 from six import string_types
    27 from six.moves import range
    28 from six.moves import range
    28 
    29 
    29 from logilab.common.deprecation import deprecated
    30 from logilab.common.deprecation import deprecated
    30 from logilab.common.registry import Predicate, objectify_predicate, yes
    31 from logilab.common.registry import Predicate, objectify_predicate, yes
    31 
    32 
   611 
   612 
   612     def __init__(self, *expected_etypes, **kwargs):
   613     def __init__(self, *expected_etypes, **kwargs):
   613         super(is_instance, self).__init__(**kwargs)
   614         super(is_instance, self).__init__(**kwargs)
   614         self.expected_etypes = expected_etypes
   615         self.expected_etypes = expected_etypes
   615         for etype in self.expected_etypes:
   616         for etype in self.expected_etypes:
   616             assert isinstance(etype, basestring), etype
   617             assert isinstance(etype, string_types), etype
   617 
   618 
   618     def __str__(self):
   619     def __str__(self):
   619         return '%s(%s)' % (self.__class__.__name__,
   620         return '%s(%s)' % (self.__class__.__name__,
   620                            ','.join(str(s) for s in self.expected_etypes))
   621                            ','.join(str(s) for s in self.expected_etypes))
   621 
   622 
  1091 
  1092 
  1092     See :class:`cubicweb.entities.wfobjs.TrInfo` for more information.
  1093     See :class:`cubicweb.entities.wfobjs.TrInfo` for more information.
  1093     """
  1094     """
  1094     if from_state_name is not None:
  1095     if from_state_name is not None:
  1095         warn("on_fire_transition's from_state_name argument is unused", DeprecationWarning)
  1096         warn("on_fire_transition's from_state_name argument is unused", DeprecationWarning)
  1096     if isinstance(tr_names, basestring):
  1097     if isinstance(tr_names, string_types):
  1097         tr_names = set((tr_names,))
  1098         tr_names = set((tr_names,))
  1098     def match_etype_and_transition(trinfo):
  1099     def match_etype_and_transition(trinfo):
  1099         # take care trinfo.transition is None when calling change_state
  1100         # take care trinfo.transition is None when calling change_state
  1100         return (trinfo.transition and trinfo.transition.name in tr_names
  1101         return (trinfo.transition and trinfo.transition.name in tr_names
  1101                 # is_instance() first two arguments are 'cls' (unused, so giving
  1102                 # is_instance() first two arguments are 'cls' (unused, so giving
  1291         """
  1292         """
  1292         if kwargs and expected:
  1293         if kwargs and expected:
  1293             raise ValueError("match_form_params() can't be called with both "
  1294             raise ValueError("match_form_params() can't be called with both "
  1294                              "positional and named arguments")
  1295                              "positional and named arguments")
  1295         if expected:
  1296         if expected:
  1296             if len(expected) == 1 and not isinstance(expected[0], basestring):
  1297             if len(expected) == 1 and not isinstance(expected[0], string_types):
  1297                 raise ValueError("match_form_params() positional arguments "
  1298                 raise ValueError("match_form_params() positional arguments "
  1298                                  "must be strings")
  1299                                  "must be strings")
  1299             super(match_form_params, self).__init__(*expected)
  1300             super(match_form_params, self).__init__(*expected)
  1300         else:
  1301         else:
  1301             super(match_form_params, self).__init__(kwargs)
  1302             super(match_form_params, self).__init__(kwargs)