From ef9cd376c41e0992a3cbf7e4a2529d6338d68d7c Mon Sep 17 00:00:00 2001 From: pzread Date: Sun, 16 Jun 2013 03:00:34 +0800 Subject: Add web part. Add filter to imc.js --- src/py/imc/proxy.py | 66 +++++++++++++++++++++++------------------------------ 1 file changed, 28 insertions(+), 38 deletions(-) (limited to 'src/py/imc/proxy.py') diff --git a/src/py/imc/proxy.py b/src/py/imc/proxy.py index e21b171..6b95674 100755 --- a/src/py/imc/proxy.py +++ b/src/py/imc/proxy.py @@ -146,47 +146,11 @@ class Proxy: return None def register_call(self,path,func_name,func): - parts = path.split('/')[:-1] - child,name,filt = self._callpath_root - i = 0 - size = len(parts) - while i < size: - try: - child,name,filt = child[parts[i]] - i += 1 - - except KeyError: - while i < size: - part = parts[i] - node = ({},{},[]) - child[part] = node - child,name,filt = node - i += 1 - - break - + child,name,filt = self._walk_path(path,True) name[func_name] = func def register_filter(self,path,func): - parts = path.split('/')[:-1] - child,name,filt = self._callpath_root - i = 0 - size = len(parts) - while i < size: - try: - child,name,filt = child[parts[i]] - i += 1 - - except KeyError: - while i < size: - part = parts[i] - node = ({},{},[]) - child[part] = node - child,name,filt = node - i += 1 - - break - + child,name,filt = self._walk_path(path,True) filt.append(func) def call(self,dst,func_name,timeout,*args): @@ -265,6 +229,32 @@ class Proxy: with Auth.change_current_iden(self._idendesc,self._auth): self.call(info['src_link'] + 'imc/','reject_sendfile',65536,filekey) + def _walk_path(self,path,create = False): + parts = path.split('/')[:-1] + child,name,filt = self._callpath_root + i = 0 + size = len(parts) + while i < size: + try: + child,name,filt = child[parts[i]] + i += 1 + + except KeyError: + if create == False: + raise + + else: + while i < size: + part = parts[i] + node = ({},{},[]) + child[part] = node + child,name,filt = node + i += 1 + + break + + return (child,name,filt) + def _route_call(self,in_conn,caller_link,caller_retid,idendesc,dst,func_name,timeout,param): def __add_wait_caller(conn_link): callback = tornado.stack_context.wrap(lambda result : self._ret_call(caller_link,caller_retid,result)) -- cgit v1.2.3