[Pli-devel] pli-devel/pli/net rpcsession2.py,1.4,1.5
Status: Pre-Alpha
Brought to you by:
alex_nanou
|
From: Alex A. N. <ale...@us...> - 2008-03-08 15:57:09
|
Update of /cvsroot/pli/pli-devel/pli/net In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv31469/pli/net Modified Files: rpcsession2.py Log Message: Index: rpcsession2.py =================================================================== RCS file: /cvsroot/pli/pli-devel/pli/net/rpcsession2.py,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** rpcsession2.py 6 Mar 2008 15:37:32 -0000 1.4 --- rpcsession2.py 8 Mar 2008 15:57:11 -0000 1.5 *************** *** 2,6 **** __version__ = '''0.3.00''' ! __sub_version__ = '''20080306165348''' __copyright__ = '''(c) Alex A. Naanou 2008''' --- 2,6 ---- __version__ = '''0.3.00''' ! __sub_version__ = '''20080308185500''' __copyright__ = '''(c) Alex A. Naanou 2008''' *************** *** 15,19 **** import pli.logictypes as logictypes ! from pli.logictypes import ANY --- 15,19 ---- import pli.logictypes as logictypes ! from pli.logictypes import ANY, isident *************** *** 266,274 **** second level dispatch. ! this gets the path (.__get_by_path__(..) method) for the session ! context and calls it. ''' # get the session context... session = self.__active_sessions__[SID][1] # make the call... return self.__get_by_path__(session, path)(*p, **n) --- 266,282 ---- second level dispatch. ! get the object and call it. ! ! this does the folowing: ! - get the session. ! - prepare the path if .__prepare_path__ is defined. ! - get the object via the .__get_by_path__ method. ! - call the object and return the result. ''' # get the session context... session = self.__active_sessions__[SID][1] + # prepare the path... + if hasattr(self, '__prepare_path__'): + path = self.__prepare_path__(session, path) # make the call... return self.__get_by_path__(session, path)(*p, **n) *************** *** 347,351 **** res = prefix+res return res ! ##!!! possible problem with an expired sid that does not get noticed... (need a more clever way to destingwith a sid) def __prepare_data__(self, path, *p, **n): ''' --- 355,360 ---- res = prefix+res return res ! ##!!! possible problem with an expired sid that does not get noticed... ! ##!!! (need a more clever way to destingwith a sid) def __prepare_data__(self, path, *p, **n): ''' *************** *** 386,400 **** def __get_by_path__(self, session, path): ''' ''' obj = session - if hasattr(self, '__prepare_path__'): - path = self.__prepare_path__(session, path) - ## ##!!! think of a better way to do this... - ## if self.__item_protocol_in_path__: - ## for name in path: - ## obj = getattr(obj, name, obj['name']) - ## else: - ## for name in path: - ## obj = getattr(obj, name) for name in path: obj = getattr(obj, name) --- 395,401 ---- def __get_by_path__(self, session, path): ''' + get an object by path using the attribute protocol. ''' obj = session for name in path: obj = getattr(obj, name) *************** *** 409,412 **** --- 410,453 ---- #----------------------------------------------------------------------- + #-------------------------------SessionManagerWithItemPathGetterMixin--- + class SessionManagerWithItemPathGetterMixin(object): + ''' + ''' + def __get_by_path__(self, session, path): + ''' + get an object by path. + + NOTE: this will use pure item access protocol. + ''' + obj = session + for name in path: + obj = obj[name] + return obj + + + #--------------------------SessionManagerWithItemNAttrPathGetterMixin--- + class SessionManagerWithItemNAttrPathGetterMixin(object): + ''' + ''' + def __get_by_path__(self, session, path): + ''' + get object by path using either the attribute or the item protocol. + + if a path element is not an identifier or is not accessible ad an attr + the use the attr protocol, else, use the item protocol. + + NOTE: in this approach attributes have greater priority and shadow + items with the same name/key. + ''' + obj = session + for name in path: + if isident(name): + obj = getattr(obj, name, obj[name]) + else: + obj = obj[name] + return obj + + + #-----------------------------SessionManagerWithBasicPathTestingMixin--- class SessionManagerWithBasicPathTestingMixin(object): ''' *************** *** 658,662 **** if self.__is_global_method__(path[-1]): return self.__call_global__(SID, path, *p, **n) ! return super(SessionManagerWithGlobalMethodsMixin, self)._dispatch(SID, path, *p, **n) def __is_global_method__(self, name): --- 699,703 ---- if self.__is_global_method__(path[-1]): return self.__call_global__(SID, path, *p, **n) ! super(SessionManagerWithGlobalMethodsMixin, self)._dispatch(SID, path, *p, **n) def __is_global_method__(self, name): *************** *** 739,743 **** def meth(self, *p, **n): print 'dfl.meth', p, n - return 123 def _meth(self): print 'dfl._meth' --- 780,783 ---- *************** *** 786,792 **** sm.logout('0') ! print sm.dispatch(['logout'], sid) ! print sm.dispatch(['meth'], 1, 2, m=6) # in this case the system can not reliably say that the argument is --- 826,832 ---- sm.logout('0') ! sm.dispatch(['logout'], sid) ! sm.dispatch(['meth'], 1, 2, m=6) # in this case the system can not reliably say that the argument is |