Exemplo n.º 1
0
 def dispatch_hooks(self):
     #process DISPATCH hooks
     d = conf.settings.get('BINDS', {})
     for func, args in d.iteritems():
         if not args:
             continue
         is_wrong = False
         if isinstance(args, (tuple, list)):
             if len(args) != 2:
                 is_wrong = True
             if not isinstance(args[1], dict):
                 is_wrong = True
             if not is_wrong:
                 dispatch.bind(args[0], **args[1])(func)
         elif isinstance(args, (str, unicode)):
             dispatch.bind(args)(func)
         else:
             is_wrong = True
         if is_wrong:
             log.error('BINDS definition should be "function=topic" or "function=topic, {"args":value1,...}"')
             raise Exception, 'BINDS definition [%s=%r] is not right' % (func, args)
             
     d = conf.settings.get('EXPOSES', {})
     for name, args in d.iteritems():
         if not args:
             continue
         is_wrong = False
         if isinstance(args, (tuple, list)):
             if len(args) == 2:
                 url, method = args
                 kwargs = {'name':name}
             elif len(args) == 3:
                 url, method, kwargs = args
                 if not isinstance(kwargs, dict):
                     is_wrong = True
                 else:
                     kwargs['name'] = name
             else:
                 is_wrong = True
             if not is_wrong:
                 expose(url, **kwargs)(method)
         else:
             is_wrong = True
         if is_wrong:
             log.error('EXPOSES definition should be "name=url, endpoint" or "name=url, endpoint, {"args":value1,...}"')
             raise Exception, 'EXPOSES definition [%s=%r] is not right' % (name, args)
Exemplo n.º 2
0
 def install_binds(self):
     #process DISPATCH hooks
     #BINDS format
     #func = topic              #bind_name will be the same with function
     #bind_name = topic, func        
     #bind_name = topic, func, {args}
     d = settings.get('BINDS', {})
     for bind_name, args in d.iteritems():
         if not args:
             continue
         is_wrong = False
         if isinstance(args, (tuple, list)):
             if len(args) == 2:
                 dispatch.bind(args[0])(args[1])
             elif len(args) == 3:
                 if not isinstance(args[2], dict):
                     is_wrong = True
                 else:
                     dispatch.bind(args[0], **args[2])(args[1])
             else:
                 is_wrong = True
         elif isinstance(args, (str, unicode)):
             dispatch.bind(args)(bind_name)
         else:
             is_wrong = True
         if is_wrong:
             log.error('BINDS definition should be "function=topic" or "bind_name=topic, function" or "bind_name=topic, function, {"args":value1,...}"')
             raise UliwebError('BINDS definition [%s=%r] is not right' % (bind_name, args))
Exemplo n.º 3
0
 def install_binds(self):
     #process DISPATCH hooks
     #BINDS format
     #func = topic              #bind_name will be the same with function
     #bind_name = topic, func        
     #bind_name = topic, func, {args}
     d = settings.get('BINDS', {})
     for bind_name, args in d.items():
         if not args:
             continue
         is_wrong = False
         if isinstance(args, (tuple, list)):
             if len(args) == 2:
                 dispatch.bind(args[0])(args[1])
             elif len(args) == 3:
                 if not isinstance(args[2], dict):
                     is_wrong = True
                 else:
                     dispatch.bind(args[0], **args[2])(args[1])
             else:
                 is_wrong = True
         elif isinstance(args, (str, unicode)):
             dispatch.bind(args)(bind_name)
         else:
             is_wrong = True
         if is_wrong:
             log.error('BINDS definition should be "function=topic" or "bind_name=topic, function" or "bind_name=topic, function, {"args":value1,...}"')
             raise UliwebError('BINDS definition [%s=%r] is not right' % (bind_name, args))