server/hook.py
changeset 4341 2d2aa2526c56
parent 4339 fe93b670343d
child 4490 d45cde54d464
equal deleted inserted replaced
4340:cc0fe6279181 4341:2d2aa2526c56
   139     in named arguments given to the selector
   139     in named arguments given to the selector
   140 
   140 
   141     :param *expected: parameters (eg `basestring`) which are expected to be
   141     :param *expected: parameters (eg `basestring`) which are expected to be
   142                       found in named arguments (kwargs)
   142                       found in named arguments (kwargs)
   143     """
   143     """
   144     def __init__(self, *expected):
   144     def __init__(self, *expected, **more):
   145         self.expected = expected
   145         self.expected = expected
   146         # if len(expected) == 1:
   146         self.frometypes = more.pop('frometypes', None)
   147         #     try:
   147         self.toetypes = more.pop('toetypes', None)
   148         #         iter(expected[0])
       
   149         #         self.expected = expected[0]
       
   150         #     except TypeError:
       
   151         #         pass
       
   152 
   148 
   153     @lltrace
   149     @lltrace
   154     def __call__(self, cls, req, *args, **kwargs):
   150     def __call__(self, cls, req, *args, **kwargs):
   155         return kwargs.get('rtype') in self.expected
   151         if kwargs.get('rtype') not in self.expected:
       
   152             return 0
       
   153         if self.frometypes is not None and \
       
   154                req.describe(kwargs['eidfrom'])[0] not in self.frometypes:
       
   155             return 0
       
   156         if self.toetypes is not None and \
       
   157                req.describe(kwargs['eidto'])[0] not in self.toetypes:
       
   158             return 0
       
   159         return 1
       
   160 
   156 
   161 
   157 class match_rtype_sets(match_search_state):
   162 class match_rtype_sets(match_search_state):
   158     """accept if parameters specified as initializer arguments are specified
   163     """accept if parameters specified as initializer arguments are specified
   159     in named arguments given to the selector
   164     in named arguments given to the selector
   160     """
   165     """