958 return a score >= 0 |
958 return a score >= 0 |
959 """ |
959 """ |
960 def __init__(self, scorefunc, once_is_enough=False): |
960 def __init__(self, scorefunc, once_is_enough=False): |
961 super(score_entity, self).__init__(once_is_enough) |
961 super(score_entity, self).__init__(once_is_enough) |
962 self.score_entity = scorefunc |
962 self.score_entity = scorefunc |
963 |
|
964 |
|
965 def unbind_method(selector): |
|
966 def new_selector(registered): |
|
967 # get the unbound method |
|
968 if hasattr(registered, 'im_func'): |
|
969 registered = registered.im_func |
|
970 # don't rebind since it will be done automatically during |
|
971 # the assignment, inside the destination class body |
|
972 return selector(registered) |
|
973 new_selector.__name__ = selector.__name__ |
|
974 return new_selector |
|
975 |
|
976 |
|
977 def deprecate(registered, msg): |
|
978 # get the unbound method |
|
979 if hasattr(registered, 'im_func'): |
|
980 registered = registered.im_func |
|
981 def _deprecate(cls, vreg): |
|
982 warn(msg, DeprecationWarning) |
|
983 return registered(cls, vreg) |
|
984 return _deprecate |
|
985 |
|
986 @unbind_method |
|
987 def require_group_compat(registered): |
|
988 def plug_selector(cls, vreg): |
|
989 cls = registered(cls, vreg) |
|
990 if getattr(cls, 'require_groups', None): |
|
991 warn('use "match_user_groups(group1, group2)" instead of using require_groups', |
|
992 DeprecationWarning) |
|
993 cls.__select__ &= match_user_groups(cls.require_groups) |
|
994 return cls |
|
995 return plug_selector |
|
996 |
|
997 @unbind_method |
|
998 def accepts_compat(registered): |
|
999 def plug_selector(cls, vreg): |
|
1000 cls = registered(cls, vreg) |
|
1001 if getattr(cls, 'accepts', None): |
|
1002 warn('use "implements("EntityType", IFace)" instead of using accepts on %s' |
|
1003 % cls, |
|
1004 DeprecationWarning) |
|
1005 cls.__select__ &= implements(*cls.accepts) |
|
1006 return cls |
|
1007 return plug_selector |
|
1008 |
|
1009 @unbind_method |
|
1010 def accepts_etype_compat(registered): |
|
1011 def plug_selector(cls, vreg): |
|
1012 cls = registered(cls, vreg) |
|
1013 if getattr(cls, 'accepts', None): |
|
1014 warn('use "specified_etype_implements("EntityType", IFace)" instead of using accepts', |
|
1015 DeprecationWarning) |
|
1016 cls.__select__ &= specified_etype_implements(*cls.accepts) |
|
1017 return cls |
|
1018 return plug_selector |
|
1019 |
|
1020 @unbind_method |
|
1021 def condition_compat(registered): |
|
1022 def plug_selector(cls, vreg): |
|
1023 cls = registered(cls, vreg) |
|
1024 if getattr(cls, 'condition', None): |
|
1025 warn('use "use rql_condition(expression)" instead of using condition', |
|
1026 DeprecationWarning) |
|
1027 cls.__select__ &= rql_condition(cls.condition) |
|
1028 return cls |
|
1029 return plug_selector |
|
1030 |
|
1031 @unbind_method |
|
1032 def has_relation_compat(registered): |
|
1033 def plug_selector(cls, vreg): |
|
1034 cls = registered(cls, vreg) |
|
1035 if getattr(cls, 'etype', None): |
|
1036 warn('use relation_possible selector instead of using etype_rtype', |
|
1037 DeprecationWarning) |
|
1038 cls.__select__ &= relation_possible(cls.rtype, role(cls), |
|
1039 getattr(cls, 'etype', None), |
|
1040 action=getattr(cls, 'require_permission', 'read')) |
|
1041 return cls |
|
1042 return plug_selector |
|